-
Notifications
You must be signed in to change notification settings - Fork 7
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
[PP-2130] celery backend config #2282
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2282 +/- ##
=======================================
Coverage 91.12% 91.12%
=======================================
Files 363 363
Lines 41340 41342 +2
Branches 8848 8848
=======================================
+ Hits 37670 37672 +2
Misses 2408 2408
Partials 1262 1262 ☔ View full report in Codecov by Sentry. |
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.
A few things to take a look at here
src/palace/manager/celery/task.py
Outdated
@@ -29,6 +29,10 @@ def my_task(task: Task) -> None: | |||
... | |||
``` | |||
|
|||
NB: It the task does not return a result, you must either call .get() or .ignore_result() on the result or |
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.
Typo in the comment:
NB:
ItIf the task does not return a result ...
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.
I have a question about this as well, can we just configure results to be ignored by default instead of adding this parameter to the decorator everywhere, or would this have adverse consequences?
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 - this is the way to go - I ran into issues trying to set it up that way. I think that problem was that I was using the key for overriding it (which you pointed out below).
@@ -80,7 +80,8 @@ def mock_task( | |||
|
|||
def configure_app( | |||
self, | |||
broker_url: str = "redis://testtesttest:1234/1", | |||
broker_url: str = "redis://testtesttest:1234/0", |
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.
Why update the broker_url
here?
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.
I thought it more consisten to have the database component of the test broker url mirror the production pattern. /0 is used for the broker url in production.
@@ -80,7 +80,8 @@ def mock_task( | |||
|
|||
def configure_app( | |||
self, | |||
broker_url: str = "redis://testtesttest:1234/1", | |||
broker_url: str = "redis://testtesttest:1234/0", | |||
result_backend: str = "redis://testtesttest:1234/0", |
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.
Shouldn't result_backend
and broker_url
have different URLs?
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 they probably should - but they don't have to.
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.
I will fix that.
return partial( | ||
CeleryConfiguration, | ||
broker_url="redis://test.com:6379/0", | ||
result_backend="redis://test.com:6379/0", |
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.
Shouldn't these be different URLs?
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 they should.
tests/fixtures/celery.py
Outdated
@@ -39,7 +40,11 @@ def celery_pydantic_config() -> CeleryConfiguration: | |||
|
|||
The config returned will then be used to configure the `celery_app` fixture. | |||
""" | |||
return CeleryConfiguration.model_construct(broker_url="memory://") | |||
temp_dir = tempfile.mkdtemp(prefix="celery_test_backend") |
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.
Since this is never cleaned up, doesn't this leak temp files on every run?
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 - that's a good point.
tests/fixtures/celery.py
Outdated
temp_dir = tempfile.mkdtemp(prefix="celery_test_backend") | ||
|
||
return CeleryConfiguration.model_construct( | ||
broker_url="memory://", result_backend=f"file://{temp_dir}" |
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 official Celery docs suggest using cache+memory://
as a backend in tests. Did you try that? It might be preferable to a temp file.
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.
I didn't see that. That would be much better - I'll fix.
tests/fixtures/redis.py
Outdated
{ | ||
"redis": { | ||
"url": self.config.url, | ||
"backend": self.config.url, |
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.
Why does a backend
key need to get set here? It doesn't seem like redis needs 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.
I'm not sure why I put that in there. I'll see if I can take it out.
README.md
Outdated
|
||
- `PALACE_CELERY_BROKER_URL`: The URL of the broker to use for Celery. (**required**). | ||
- for example: | ||
```sh | ||
export PALACE_CELERY_BROKER_URL="redis://localhost:6379/0"` | ||
|
||
``` | ||
- `PALACE_CELERY_RESULT_BACKEND`: The url of the result backend to use for Celery. (**required**). |
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.
Minor: Looks like there are two spaces between the and result.
- `PALACE_CELERY_RESULT_BACKEND`: The url of the result backend to use for Celery. (**required**). | |
- `PALACE_CELERY_RESULT_BACKEND`: The url of the result backend to use for Celery. (**required**). |
@@ -40,6 +40,6 @@ def run(self) -> None: | |||
collection.delete() | |||
|
|||
|
|||
@shared_task(queue=QueueNames.high, bind=True) | |||
@shared_task(queue=QueueNames.high, bind=True, task_ignore_results=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.
I don't see task_ignore_results
anywhere in the Celery documentation. Is that the parameter that we need to be passing here? From the docs it looks like ignore_result
is what we want https://docs.celeryq.dev/en/stable/reference/celery.app.task.html#celery.app.task.Task.ignore_result
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.
Ah: that explains a lot. I'm going to try setting task_ignore_result=True in the config and remove all of what should have been ignore_result. Hopefully that will give us the default behavior we want with the backend enabled.
06362d6
to
5efd3a4
Compare
Ach - this is super frustrating: With the default value set for task_ignore_result (ie False) the tests are passing. But if I try to set the
However if I set |
That is annoying. You could take a look at that testing repo I pointed to in one of the comments. There might be some insight there. It's always a bit of work to get new components like this setup and testable. |
Description
This PR enables the result backend in celery. It should cause no change to the behavior of the system.
Motivation and Context
https://ebce-lyrasis.atlassian.net/browse/PP-2130
How Has This Been Tested?
I tested this update with my celery based axis 360 importer and reaper tasks which will follow after this one is merged.
Checklist