Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Nov 20, 2024
1 parent d24742b commit 2da0bdf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions scheduler/admin/old_task_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class TaskAdmin(admin.ModelAdmin):
"function_string",
"is_scheduled",
"queue",
"new_task_id",
)
list_display_links = ("name",)
readonly_fields = ("job_id",)
Expand Down
3 changes: 2 additions & 1 deletion scheduler/management/commands/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def create_task_from_dict(task_dict: Dict[str, Any], update):
if not settings.USE_TZ and not timezone.is_naive(target):
target = timezone.make_naive(target)
kwargs["scheduled_time"] = target
model_fields = set(map(lambda field: field.attname, Task._meta.get_fields()))
model_fields = filter(lambda field:hasattr(field,'attname'),Task._meta.get_fields())
model_fields = set(map(lambda field: field.attname, model_fields))
keys_to_ignore = list(filter(lambda _k: _k not in model_fields, kwargs.keys()))
for k in keys_to_ignore:
del kwargs[k]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 5.1.3 on 2024-11-19 23:36
# 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

Expand Down Expand Up @@ -161,4 +162,25 @@ class Migration(migrations.Migration):
),
],
),
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"
),
),
]
14 changes: 10 additions & 4 deletions scheduler/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from .args import TaskKwarg, TaskArg, BaseTaskArg # noqa: F401
from .queue import Queue # noqa: F401
from .scheduled_task import BaseTask, ScheduledTask, RepeatableTask, CronTask # noqa: F401
from .task import Task # noqa: F401
from .args import TaskKwarg, TaskArg
from .scheduled_task import BaseTask, ScheduledTask, RepeatableTask, CronTask
from .queue import Queue
from .task import Task

__all__ = [
"TaskKwarg", "TaskArg",
"ScheduledTask", "RepeatableTask", "CronTask",
"Queue", "Task",
]
1 change: 1 addition & 0 deletions scheduler/models/scheduled_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class BaseTask(models.Model):
>0: Result expires after n seconds."""
),
)
new_task_id = models.ForeignKey('Task', on_delete=models.CASCADE, blank=True, null=True)

def callable_func(self):
"""Translate callable string to callable"""
Expand Down

0 comments on commit 2da0bdf

Please sign in to comment.