Skip to content
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

Restart a consumer after a certain number of tasks #261

Closed
mindojo-victor opened this issue Oct 8, 2017 · 11 comments
Closed

Restart a consumer after a certain number of tasks #261

mindojo-victor opened this issue Oct 8, 2017 · 11 comments

Comments

@mindojo-victor
Copy link
Contributor

Is it easy to implement something like http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-worker_max_tasks_per_child ?

Or if there was a mechanism to restart the consumer manually ( #251 ) it should be easy to count tasks by myself and decide whether I need to restart the consumer because of leaking memory.

@coleifer
Copy link
Owner

coleifer commented Oct 8, 2017

Right now there is not, but I don't see why we should implement a restart signal at the very least. SIGHUP for instance?

@mindojo-victor
Copy link
Contributor Author

mindojo-victor commented Oct 8, 2017 via email

@coleifer
Copy link
Owner

coleifer commented Oct 9, 2017

I'm suggesting using SIGHUP to trigger a restart. I'm not too sure how to restart processes with Python from within the process itself... is it sufficient to restart the workers or should the whole consumer process get restarted, for example? Would I use the os.exec family to start the new process?

@coleifer
Copy link
Owner

coleifer commented Oct 9, 2017

Looks like I want https://docs.python.org/3/library/os.html#os.execl

@coleifer
Copy link
Owner

coleifer commented Oct 9, 2017

Wanna try out 1ffb3dd ?

@mindojo-victor
Copy link
Contributor Author

If I understood correctly, if the master process receives SIGHUP, it restart itself with all the workers. If a worker receives SIGHUP, only it restarts. I am interested in the second case, because other workers could be ok.

@mindojo-victor
Copy link
Contributor Author

Wanna try out 1ffb3dd ?

Will try this later. Thank you!

@coleifer
Copy link
Owner

coleifer commented Oct 9, 2017

I did not implement this on a worker-by-worker basis. It applies to the consumer as a whole.

@coleifer
Copy link
Owner

coleifer commented Oct 9, 2017

If you're running the worker health checker, it should be possible to just kill the worker process using the standard SIGTERM and huey consumer will automatically restart a new worker to take it's place?

@mindojo-victor
Copy link
Contributor Author

This should work. If health checker always running?

@mindojo-victor
Copy link
Contributor Author

Looks like it is. This means that all I need is there in place already. I can count number of tasks and raise KeyboardInterrupt when I think the worker should restart. It will die and the consumer will raise another worker in its place?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants