-
-
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, |
@@ -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") |
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") |
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") |
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( |
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} |
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: |
No description provided.