-
-
Notifications
You must be signed in to change notification settings - Fork 471
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
[16.0][IMP] queue_job: Add error handler when job fails #734
base: 16.0
Are you sure you want to change the base?
Conversation
Hi @guewen, |
queue_job/models/queue_job.py
Outdated
@@ -506,3 +509,31 @@ def _test_job(self, failure_rate=0): | |||
_logger.info("Running test job.") | |||
if random.random() <= failure_rate: | |||
raise JobError("Job failed") | |||
|
|||
def _call_webhook(self, **kwargs): | |||
only_if_max_retries_reached = kwargs.get("only_if_max_retries_reached", False) |
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.
only_if_max_retries_reached = kwargs.get("only_if_max_retries_reached", False) | |
only_if_max_retries_reached = kwargs.get("only_if_max_retries_reached") |
queue_job/models/queue_job.py
Outdated
if only_if_max_retries_reached and (job and job.retry < job.max_retries): | ||
return | ||
|
||
webhook_url = kwargs.get("webhook_url", None) |
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.
webhook_url = kwargs.get("webhook_url", None) | |
webhook_url = kwargs.get("webhook_url") |
queue_job/models/queue_job.py
Outdated
webhook_url = kwargs.get("webhook_url", None) | ||
if not webhook_url: | ||
return | ||
payload = kwargs.get("payload", None) |
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.
payload = kwargs.get("payload", None) | |
payload = kwargs.get("payload") |
test_queue_job/tests/test_job.py
Outdated
model = self.env["test.queue.job"] | ||
job = model.with_delay(priority=1, max_retries=1).testing_method() | ||
trap.assert_jobs_count(1) | ||
with patch.object(type(job), "perform", side_effect=IOError,), patch( |
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.
with patch.object(type(job), "perform", side_effect=IOError,), patch( | |
with patch.object(type(job), "perform", side_effect=IOError), patch( |
queue_job/job.py
Outdated
action_kwargs = self.job_config.error_handler_kwargs | ||
action_kwargs["job"] = self | ||
action_kwargs["job"] = self |
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.
Duplicate line.
Can also be written as:
action_kwargs = self.job_config.error_handler_kwargs | |
action_kwargs["job"] = self | |
action_kwargs["job"] = self | |
action_kwargs = {**self.job_config.error_handler_kwargs, "job": self} |
queue_job/models/queue_job.py
Outdated
def _call_webhook(self, **kwargs): | ||
only_if_max_retries_reached = kwargs.get("only_if_max_retries_reached", False) | ||
job = kwargs.get("job") | ||
if only_if_max_retries_reached and (job and job.retry < job.max_retries): |
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.
if only_if_max_retries_reached and (job and job.retry < job.max_retries): | |
if only_if_max_retries_reached and job and job.retry < job.max_retries: |
6e3a7d9
to
c035a4c
Compare
try: | ||
controller._try_perform_job(self.env, job) | ||
with patch( | ||
"odoo.addons.test_queue_job.models.test_models.QueueJob" | ||
".testing_error_handler" | ||
) as patched: | ||
patched.assert_called_once() | ||
except Exception: | ||
_logger.info("Job fails") |
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.
It seems that lines 361-365 are not executed. Test has to be improved here, I believe.
Extract of the log on CI:
2025-01-14 05:40:08,895 275 INFO odoo odoo.addons.test_queue_job.tests.test_job: Starting TestJobsOnTestingMethod.test_failed_job_perform ...
2025-01-14 05:40:08,903 275 INFO odoo odoo.addons.queue_job.job: Job 648616de-b28e-4d33-8c3f-5be7ac760cac fails due to , execute <bound method QueueJob.testing_error_handler of queue.job()>
2025-01-14 05:40:08,903 275 INFO odoo odoo.addons.test_queue_job.tests.test_job: Job fails
No description provided.