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

Feat: Max requests flag to exit after N requests #405

Closed
wants to merge 9 commits into from

Conversation

alamorre
Copy link

@alamorre alamorre commented Feb 6, 2022

This is my first Open Source PR, but here is the --max-requests setting to periodically restart workers.

There are no tests, I'm happy to add them if this feature interests the Daphne maintainers.

Please let me know your thoughts!

Refs #403

Comment on lines +202 to +210
# Count completed requests and check against Max
self.server._complete_requests_counted += 1
if self.server._complete_requests_counted > self.server.max_requests:
logger.info('Max requests completed. Shutting down daphne...')
os.system("ps aux | grep 'daphne'")
bash_command = "kill $(ps aux | grep 'daphne' | awk '{print $2}')"
os.system(bash_command)
sys.exit(0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. OK, so... the expectation would be that we restart after X requests, not just shut down right?

@carltongibson
Copy link
Member

I'm going to close this as per my comment on the issue:

The PR in #405 adds a shutdown, but it doesn't reload.

For that we'd need something like Django autoreloader's restart_with_reloader():

https://github.com/django/django/blob/747b417a220b0412ed806001a383959449aac6da/django/utils/autoreload.py#L270-L276

If someone wanted to take that on, it would be worth a look.

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

Successfully merging this pull request may close these issues.

2 participants