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

[16.0][IMP] queue_job: Add error handler when job fails #734

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from

Conversation

trisdoan
Copy link

@trisdoan trisdoan commented Jan 9, 2025

No description provided.

@OCA-git-bot
Copy link
Contributor

Hi @guewen,
some modules you are maintaining are being modified, check this out!

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
with patch.object(type(job), "perform", side_effect=IOError,), patch(
with patch.object(type(job), "perform", side_effect=IOError), patch(

Comment on lines +906 to +908
action_kwargs = self.job_config.error_handler_kwargs
action_kwargs["job"] = self
action_kwargs["job"] = self
Copy link
Contributor

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:

Suggested change
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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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:

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.

3 participants