# Generated by Django 5.1.4 on 2025-01-02 06:28

from __future__ import annotations

import django.core.validators
import django.utils.timezone
from django.db import migrations
from django.db import models

import django_qstash.discovery.models
import django_qstash.schedules.validators


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="TaskSchedule",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "schedule_id",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="The schedule ID stored in QStash",
                        max_length=255,
                        null=True,
                        unique=True,
                        verbose_name="Schedule ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Short Description For This Task Schedule",
                        max_length=200,
                        verbose_name="Name",
                    ),
                ),
                ("task", django_qstash.discovery.models.TaskField(max_length=255)),
                (
                    "task_name",
                    models.CharField(
                        blank=True,
                        help_text="Original Python location of task",
                        max_length=255,
                    ),
                ),
                (
                    "args",
                    models.JSONField(
                        blank=True,
                        default=list,
                        help_text='JSON encoded positional arguments (Example: ["arg1", "arg2"])',
                        verbose_name="Positional Arguments",
                    ),
                ),
                (
                    "kwargs",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text='JSON encoded keyword arguments (Example: {"argument": "value"})',
                        verbose_name="Keyword Arguments",
                    ),
                ),
                (
                    "cron",
                    models.CharField(
                        default="*/5 * * * *",
                        help_text="Cron expression for scheduling the task",
                        max_length=255,
                        verbose_name="Cron Expression",
                    ),
                ),
                (
                    "retries",
                    models.IntegerField(
                        default=3,
                        help_text="Number of times to retry the task if it fails",
                        validators=[django.core.validators.MaxValueValidator(5)],
                        verbose_name="Retries",
                    ),
                ),
                (
                    "timeout",
                    models.CharField(
                        default="60s",
                        help_text="Duration string for task timeout (e.g., '1s', '5m', '2h'). See Max HTTP Connection Timeout on QStash pricing page for allowed values for your Upstash account.",
                        max_length=10,
                        validators=[
                            django_qstash.schedules.validators.validate_duration_string
                        ],
                        verbose_name="Timeout",
                    ),
                ),
                ("is_active", models.BooleanField(default=True)),
                (
                    "active_at",
                    models.DateTimeField(
                        blank=True, default=django.utils.timezone.now, null=True
                    ),
                ),
                ("is_paused", models.BooleanField(default=False)),
                ("paused_at", models.DateTimeField(blank=True, null=True)),
                ("is_resumed", models.BooleanField(default=False)),
                ("resumed_at", models.DateTimeField(blank=True, null=True)),
            ],
        ),
    ]
