django-celery-beat icon indicating copy to clipboard operation
django-celery-beat copied to clipboard

Suggestion of improve PeriodicTask.kwargs

Open Korolev-Oleg opened this issue 1 year ago • 1 comments

Summary:

  • Celery Version: 5.2.7
  • Celery-Beat Version: 2.4.0

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

Korolev-Oleg avatar Mar 03 '23 16:03 Korolev-Oleg

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

auvipy avatar Mar 04 '23 05:03 auvipy