celery / django-celery-beat

Celery Periodic Tasks backed by the Django ORM
Other
1.69k stars 429 forks source link

Suggestion of improve PeriodicTask.kwargs #633

Open Korolev-Oleg opened 1 year ago

Korolev-Oleg commented 1 year ago

Summary:

Currently, if you try to create PeriodicTask with the argument kwargas: dict its converts into a simple string and the task becomes inactive

pt = PeriodicTask.objects.create(
    name=task_name,
    task="api.v1.tasks.tasks.update_planned_task",
    crontab=crontab_schedule,
    kwargs={"planned_task_id": planned_task.id},
)
print(pt.kwargs) # "{'planned_task_id': 39}"

In order for everything to work, you need to convert kwargs dict into json using json.dumps This process can be transferred inside the model PeriodicTask in save method

self.kwargs = json.dumps(self.kwargs)

In this case, we use the variable kwargs in the usual way by passing a dictionary to it and not a string

auvipy commented 1 year ago

are you willing to contribute this improvement with appropriate regression test?