-
Notifications
You must be signed in to change notification settings - Fork 39
Support autoreload of db_worker
#105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You would have to rewrite the |
This is indeed expected behaviour, although not "intended" necessarily. Only Django's 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? |
db_worker
I mainly use Python with Django, which led to my proposal for adding this to the documentation. Given that autoreload is not default Python behavior, I agree that my suggestion doesn't make sense.
Thinking about this, Django
I guess these problems are similar to the ones stated in the issue #46. |
A feature such as this needs to have a big caveat: only to be used in development. The reuslting overhead would be large in a production env (ie. do you really need to install another dependency such as pywatchman in prod) and the utility of having an autoreload functionality would not provide much value imo.
If we assume this only used for local development, we can consider the stakes low. In that case I would suggest a pessimistic approach: the task is terminated along with the worker, and a noack of the task results in a reprocessing of the task when the worker spins up again. |
Hooking into Django's existing reload system used for I agree making this development only (or at least |
Maybe just a command line option is enough to fix this issue? |
For development, I don't see a reason why this needs to be opt-in functionality. Might as well make it the default. |
Are you suggesting that when |
It'd need some thought, as to how currently-running tasks are handled. I suspect the solution is to reload after the current task (so it's a graceful reload). |
Here's an example command to make this work while there's no implementation: import shlex
import subprocess
from django.core.management.base import BaseCommand
from django.utils import autoreload
def restart_worker():
db_worker_cmd = "python manage.py db_worker"
cmd = f'pkill -f "{db_worker_cmd}"'
subprocess.call(shlex.split(cmd))
subprocess.call(shlex.split(f"{db_worker_cmd}"))
class Command(BaseCommand):
def handle(self, *args, **options):
print("Starting db worker with autoreload...")
autoreload.run_with_reloader(restart_worker) |
I am running this command to start "runserver" (dev server) and the "db_worker" in parallel:
This command also gives me free auto-reload for both, the dev server and the db_worker. |
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'srunserver
restarting on code changes. Could be a good idea to document this in the README?The text was updated successfully, but these errors were encountered: