RealOrangeOne / django-tasks

A reference implementation and backport of background workers and tasks in Django
https://pypi.org/project/django-tasks/
BSD 3-Clause "New" or "Revised" License
286 stars 22 forks source link

Support autoreload of `db_worker` #105

Open daniboygg opened 2 weeks ago

daniboygg commented 2 weeks ago

I was testing this package and created a Django admin action to trigger the enqueue of a task. After getting everything working, I changed the code to modify the task result. However, after queuing the task, I still got the old result.

My guess is that when running the db_worker, you need to restart the command if you change the code. Is this expected behavior? I was surprised because I'm used to Django's runserver restarting on code changes. Could be a good idea to document this in the README?

hooverdc commented 2 weeks ago

You would have to rewrite the db_worker command to use Django's autoreload. It's not default Python behavior.

RealOrangeOne commented 2 weeks ago

This is indeed expected behaviour, although not "intended" necessarily. Only Django's runserver command reloads when the code does. Other long-running management commands don't.

I agree it'd be a nice feature to have, but the behaviour could be quite complex. For example, what happens if a task is running?