# Generated by Django 5.0 on 2026-02-21

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='TaskExecutionModel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('task_id', models.CharField(db_index=True, max_length=255, unique=True, verbose_name='任务ID')),
                ('task_name', models.CharField(db_index=True, max_length=255, verbose_name='任务名称')),
                ('status', models.CharField(choices=[('pending', '等待中'), ('started', '已开始'), ('success', '成功'), ('failure', '失败'), ('retry', '重试中'), ('revoked', '已撤销'), ('timeout', '超时')], db_index=True, max_length=20, verbose_name='状态')),
                ('args', models.JSONField(default=list, verbose_name='位置参数')),
                ('kwargs', models.JSONField(default=dict, verbose_name='关键字参数')),
                ('started_at', models.DateTimeField(db_index=True, null=True, verbose_name='开始时间')),
                ('finished_at', models.DateTimeField(null=True, verbose_name='完成时间')),
                ('result', models.TextField(null=True, verbose_name='执行结果')),
                ('exception', models.TextField(null=True, verbose_name='异常信息')),
                ('traceback', models.TextField(null=True, verbose_name='堆栈跟踪')),
                ('runtime_seconds', models.FloatField(null=True, verbose_name='运行时长(秒)')),
                ('retries', models.IntegerField(default=0, verbose_name='重试次数')),
                ('priority', models.CharField(choices=[('low', '低'), ('normal', '普通'), ('high', '高'), ('critical', '紧急')], default='normal', max_length=20, verbose_name='优先级')),
                ('queue', models.CharField(max_length=100, null=True, verbose_name='队列名称')),
                ('worker', models.CharField(max_length=100, null=True, verbose_name='Worker 名称')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
            ],
            options={
                'verbose_name': '任务执行记录',
                'verbose_name_plural': '任务执行记录',
                'ordering': ['-created_at'],
                'indexes': [
                    models.Index(fields=['task_name', 'created_at'], name='task_monit_task_name__id_idx'),
                    models.Index(fields=['status', 'created_at'], name='task_monit_status__id_idx'),
                ],
            },
        ),
        migrations.CreateModel(
            name='TaskAlertModel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('level', models.CharField(choices=[('info', '信息'), ('warning', '警告'), ('critical', '严重')], db_index=True, max_length=20, verbose_name='告警级别')),
                ('task_id', models.CharField(max_length=255, verbose_name='任务ID')),
                ('task_name', models.CharField(max_length=255, verbose_name='任务名称')),
                ('title', models.CharField(max_length=500, verbose_name='告警标题')),
                ('message', models.TextField(verbose_name='告警消息')),
                ('exception', models.TextField(null=True, verbose_name='异常信息')),
                ('traceback', models.TextField(null=True, verbose_name='堆栈跟踪')),
                ('is_sent', models.BooleanField(default=False, verbose_name='已发送')),
                ('sent_at', models.DateTimeField(null=True, verbose_name='发送时间')),
                ('send_error', models.TextField(null=True, verbose_name='发送错误')),
                ('metadata', models.JSONField(default=dict, verbose_name='元数据')),
                ('triggered_at', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='触发时间')),
            ],
            options={
                'verbose_name': '任务告警记录',
                'verbose_name_plural': '任务告警记录',
                'ordering': ['-triggered_at'],
                'indexes': [
                    models.Index(fields=['level', 'triggered_at'], name='task_monit_level__trig_idx'),
                    models.Index(fields=['task_name', 'triggered_at'], name='task_monit_tname__trig_idx'),
                ],
            },
        ),
    ]
