# Generated by Django 5.1.3 on 2024-11-20 20:32

import django.db.models.deletion
import scheduler.models.task
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("scheduler", "0018_alter_crontask_queue_alter_repeatabletask_queue_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="Task",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "name",
                    models.CharField(help_text="Name of the job", max_length=128, unique=True, verbose_name="name"),
                ),
                (
                    "task_type",
                    models.CharField(
                        choices=[
                            ("CronTaskType", "Cron Task"),
                            ("RepeatableTaskType", "Repeatable Task"),
                            ("OnceTaskType", "Run once"),
                        ],
                        default="OnceTaskType",
                        max_length=32,
                        verbose_name="Task type",
                    ),
                ),
                ("callable", models.CharField(max_length=2048, verbose_name="callable")),
                (
                    "enabled",
                    models.BooleanField(
                        default=True,
                        help_text="Should job be scheduled? This field is useful to keep past jobs that should no longer be scheduled",
                        verbose_name="enabled",
                    ),
                ),
                (
                    "queue",
                    models.CharField(
                        choices=scheduler.models.task.get_queue_choices,
                        help_text="Queue name",
                        max_length=255,
                        verbose_name="queue",
                    ),
                ),
                (
                    "job_id",
                    models.CharField(
                        blank=True,
                        editable=False,
                        help_text="Current job_id on queue",
                        max_length=128,
                        null=True,
                        verbose_name="job id",
                    ),
                ),
                (
                    "at_front",
                    models.BooleanField(
                        default=False,
                        help_text="When queuing the job, add it in the front of the queue",
                        verbose_name="At front",
                    ),
                ),
                (
                    "timeout",
                    models.IntegerField(
                        blank=True,
                        help_text="Timeout specifies the maximum runtime, in seconds, for the job before it'll be considered 'lost'. Blank uses the default timeout.",
                        null=True,
                        verbose_name="timeout",
                    ),
                ),
                (
                    "result_ttl",
                    models.IntegerField(
                        blank=True,
                        help_text="The TTL value (in seconds) of the job result.<br/>\n               -1: Result never expires, you should delete jobs manually. <br/>\n                0: Result gets deleted immediately. <br/>\n                >0: Result expires after n seconds.",
                        null=True,
                        verbose_name="result ttl",
                    ),
                ),
                (
                    "failed_runs",
                    models.PositiveIntegerField(
                        default=0, help_text="Number of times the task has failed", verbose_name="failed runs"
                    ),
                ),
                (
                    "successful_runs",
                    models.PositiveIntegerField(
                        default=0, help_text="Number of times the task has succeeded", verbose_name="successful runs"
                    ),
                ),
                (
                    "last_successful_run",
                    models.DateTimeField(
                        blank=True,
                        help_text="Last time the task has succeeded",
                        null=True,
                        verbose_name="last successful run",
                    ),
                ),
                (
                    "last_failed_run",
                    models.DateTimeField(
                        blank=True, help_text="Last time the task has failed", null=True, verbose_name="last failed run"
                    ),
                ),
                (
                    "interval",
                    models.PositiveIntegerField(
                        blank=True, help_text="Interval for repeatable task", null=True, verbose_name="interval"
                    ),
                ),
                (
                    "interval_unit",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("seconds", "seconds"),
                            ("minutes", "minutes"),
                            ("hours", "hours"),
                            ("days", "days"),
                            ("weeks", "weeks"),
                        ],
                        default="hours",
                        max_length=12,
                        null=True,
                        verbose_name="interval unit",
                    ),
                ),
                (
                    "repeat",
                    models.PositiveIntegerField(
                        blank=True,
                        help_text="Number of times to run the job. Leaving this blank means it will run forever.",
                        null=True,
                        verbose_name="repeat",
                    ),
                ),
                ("scheduled_time", models.DateTimeField(blank=True, null=True, verbose_name="scheduled time")),
                (
                    "cron_string",
                    models.CharField(
                        blank=True,
                        help_text='Define the schedule in a crontab like syntax.\n            Times are in UTC. Use <a href="https://crontab.guru/">crontab.guru</a> to create a cron string.',
                        max_length=64,
                        null=True,
                        verbose_name="cron string",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="crontask",
            name="new_task_id",
            field=models.ForeignKey(
                blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="scheduler.task"
            ),
        ),
        migrations.AddField(
            model_name="repeatabletask",
            name="new_task_id",
            field=models.ForeignKey(
                blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="scheduler.task"
            ),
        ),
        migrations.AddField(
            model_name="scheduledtask",
            name="new_task_id",
            field=models.ForeignKey(
                blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="scheduler.task"
            ),
        ),
    ]
