From e96970f8fd62303eb38a7b02dea22ab8f16c0ae6 Mon Sep 17 00:00:00 2001 From: Quoc Duong Date: Wed, 7 Aug 2024 11:54:17 +0700 Subject: [PATCH] fixup! [IMP] queue_job: run specific hook method after max_retries --- queue_job/README.rst | 27 ++++++++++++++++++++ queue_job/readme/USAGE.rst | 27 ++++++++++++++++++++ queue_job/static/description/index.html | 33 ++++++++++++++++++++++--- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/queue_job/README.rst b/queue_job/README.rst index 439fc6ffc..23c2510a9 100644 --- a/queue_job/README.rst +++ b/queue_job/README.rst @@ -397,6 +397,33 @@ Based on this configuration, we can tell that: * retries 10 to 15 postponed 30 seconds later * all subsequent retries postponed 5 minutes later +**Job function: reach max retryable times** + +When a job has reached the maximum number of retries and still fails, +the job's status will be set to ``Failed``. +You can define a specific method to handle this event. +The method should be named ``{method_name}_on_max_retries_reached``. + +Here's an example: + +.. code-block:: python + + from odoo import models, fields, api + + class MyModel(models.Model): + _name = 'my.model' + + def button_done(self): + self.env['my.model'].with_delay().my_method('a', k=2) + + def my_method_on_max_retries_reached(self): + # This method is called when the job reaches the maximum retries and fails + # Add your custom logic here + +In this example, ``my_method_on_max_retries_reached`` is the method +that will be called when the job my_method fails after reaching the maximum retries. +You can add your custom logic inside this method to handle the event. + **Job Context** The context of the recordset of the job, or any recordset passed in arguments of diff --git a/queue_job/readme/USAGE.rst b/queue_job/readme/USAGE.rst index 0ac17f7b1..0a2cf3576 100644 --- a/queue_job/readme/USAGE.rst +++ b/queue_job/readme/USAGE.rst @@ -242,6 +242,33 @@ Based on this configuration, we can tell that: * retries 10 to 15 postponed 30 seconds later * all subsequent retries postponed 5 minutes later +**Job function: reach max retryable times** + +When a job has reached the maximum number of retries and still fails, +the job's status will be set to ``Failed``. +You can define a specific method to handle this event. +The method should be named ``{method_name}_on_max_retries_reached``. + +Here's an example: + +.. code-block:: python + + from odoo import models, fields, api + + class MyModel(models.Model): + _name = 'my.model' + + def button_done(self): + self.env['my.model'].with_delay().my_method('a', k=2) + + def my_method_on_max_retries_reached(self): + # This method is called when the job reaches the maximum retries and fails + # Add your custom logic here + +In this example, ``my_method_on_max_retries_reached`` is the method +that will be called when the job my_method fails after reaching the maximum retries. +You can add your custom logic inside this method to handle the event. + **Job Context** The context of the recordset of the job, or any recordset passed in arguments of diff --git a/queue_job/static/description/index.html b/queue_job/static/description/index.html index 20ec9c0e0..e766bc03d 100644 --- a/queue_job/static/description/index.html +++ b/queue_job/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -715,6 +716,28 @@

Configure default options for job
  • retries 10 to 15 postponed 30 seconds later
  • all subsequent retries postponed 5 minutes later
  • +

    Job function: reach max retryable times

    +

    When a job has reached the maximum number of retries and still fails, +the job’s status will be set to Failed. +You can define a specific method to handle this event. +The method should be named {method_name}_on_max_retries_reached.

    +

    Here’s an example:

    +
    +from odoo import models, fields, api
    +
    +class MyModel(models.Model):
    +    _name = 'my.model'
    +
    +    def button_done(self):
    +        self.env['my.model'].with_delay().my_method('a', k=2)
    +
    +    def my_method_on_max_retries_reached(self):
    +        # This method is called when the job reaches the maximum retries and fails
    +        # Add your custom logic here
    +
    +

    In this example, my_method_on_max_retries_reached is the method +that will be called when the job my_method fails after reaching the maximum retries. +You can add your custom logic inside this method to handle the event.

    Job Context

    The context of the recordset of the job, or any recordset passed in arguments of a job, is transferred to the job according to an allow-list.

    @@ -958,7 +981,9 @@

    Contributors

    Maintainers

    This module is maintained by the OCA.

    -Odoo Community Association + +Odoo Community Association +

    OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.