-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Allow heartbeats to be sent in tests #6632
Conversation
I'm writing a Prometheus exporter at https://github.com/danihodovic/celery-exporter. In order to test the worker events: worker-heartbeat, worker-online, worker-offline I need to be able to enable heartbeats for the testing worker.
This pull request fixes 1 alert when merging b6376da into 948bb79 - view on LGTM.com fixed alerts:
|
@@ -119,7 +119,7 @@ def _start_worker_thread(app, | |||
logfile=logfile, | |||
# not allowed to override TestWorkController.on_consumer_ready | |||
ready_callback=None, | |||
without_heartbeat=True, | |||
without_heartbeat=kwargs.pop("without_heartbeat", True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't going to break the existing API write? shouldn't this overridable feature mentioned in the docs? and can we provide some sort of unit tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is True, so this should be backwards compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add documentation for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, probably next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution means you'll need to overwrite the celery_worker
/celery_session_worker
fixtures to override the value of without_heartbeat
.
This isn't the most comfortable API.
We should change https://github.com/celery/celery/blob/master/celery/contrib/pytest.py#L145 instead to return {"without_heartbeat": True}
and ensure it is passed onwards.
The question is if this breaks existing behavior for users that don't use the pytest fixture? By default the value is False - celery/celery/worker/consumer/heart.py Line 22 in 7288147
WorkController behavior would silently change and heartsbeats would be enabled.
No, you can override |
In that case we still need to check if
I meant the solution proposed in this PR, not the solution I'm proposing. |
Hmm... I'm confused because that's what this PR does https://github.com/celery/celery/pull/6632/files#diff-fee53e249a978fd480b1cade781b4e997b18492ab090d76d0377786d99128b92R122
|
Gottcha 🤦 |
No worries, happy we cleared it up. I'll be adding some docs later this week. |
This pull request introduces 1 alert and fixes 1 when merging 412d576 into 1eade4c - view on LGTM.com new alerts:
fixed alerts:
|
thanks! |
* Allow heartbeats to be sent in tests I'm writing a Prometheus exporter at https://github.com/danihodovic/celery-exporter. In order to test the worker events: worker-heartbeat, worker-online, worker-offline I need to be able to enable heartbeats for the testing worker. * Add docs on heartbeats in tests
I'm writing a Prometheus exporter at
https://github.com/danihodovic/celery-exporter.
In order to test the worker events: worker-heartbeat, worker-online,
worker-offline I need to be able to enable heartbeats for the testing
worker.
The change allows for overriding the default value of heartbeat = False.