django-celery-beat
django-celery-beat copied to clipboard
Suggestion of improve PeriodicTask.kwargs
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
are you willing to contribute this improvement with appropriate regression test?