Skip to content

Commit 893489c

Browse files
committed
fixup! [IMP] queue_job: run specific hook method after max_retries
1 parent 39cf2df commit 893489c

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

queue_job/README.rst

+27
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,33 @@ Based on this configuration, we can tell that:
397397
* retries 10 to 15 postponed 30 seconds later
398398
* all subsequent retries postponed 5 minutes later
399399

400+
**Job function: reach max retryable times**
401+
402+
When a job has reached the maximum number of retries and still fails,
403+
the job's status will be set to `Failed`.
404+
You can define a specific method to handle this event.
405+
The method should be named `{method_name}_on_max_retries_reached`.
406+
407+
Here's an example:
408+
409+
.. code-block:: python
410+
411+
from odoo import models, fields, api
412+
413+
class MyModel(models.Model):
414+
_name = 'my.model'
415+
416+
def button_done(self):
417+
self.env['my.model'].with_delay().my_method('a', k=2)
418+
419+
def my_method_on_max_retries_reached(self):
420+
# This method is called when the job reaches the maximum retries and fails
421+
# Add your custom logic here
422+
423+
In this example, `my_method_on_max_retries_reached`` is the method
424+
that will be called when the job my_method fails after reaching the maximum retries.
425+
You can add your custom logic inside this method to handle the event.
426+
400427
**Job Context**
401428

402429
The context of the recordset of the job, or any recordset passed in arguments of

queue_job/readme/USAGE.rst

+27
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,33 @@ Based on this configuration, we can tell that:
242242
* retries 10 to 15 postponed 30 seconds later
243243
* all subsequent retries postponed 5 minutes later
244244

245+
**Job function: reach max retryable times**
246+
247+
When a job has reached the maximum number of retries and still fails,
248+
the job's status will be set to `Failed`.
249+
You can define a specific method to handle this event.
250+
The method should be named `{method_name}_on_max_retries_reached`.
251+
252+
Here's an example:
253+
254+
.. code-block:: python
255+
256+
from odoo import models, fields, api
257+
258+
class MyModel(models.Model):
259+
_name = 'my.model'
260+
261+
def button_done(self):
262+
self.env['my.model'].with_delay().my_method('a', k=2)
263+
264+
def my_method_on_max_retries_reached(self):
265+
# This method is called when the job reaches the maximum retries and fails
266+
# Add your custom logic here
267+
268+
In this example, `my_method_on_max_retries_reached`` is the method
269+
that will be called when the job my_method fails after reaching the maximum retries.
270+
You can add your custom logic inside this method to handle the event.
271+
245272
**Job Context**
246273

247274
The context of the recordset of the job, or any recordset passed in arguments of

queue_job/static/description/index.html

+29-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger ([email protected])
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -715,6 +716,28 @@ <h3><a class="toc-backref" href="#toc-entry-7">Configure default options for job
715716
<li>retries 10 to 15 postponed 30 seconds later</li>
716717
<li>all subsequent retries postponed 5 minutes later</li>
717718
</ul>
719+
<p><strong>Job function: reach max retryable times</strong></p>
720+
<p>When a job has reached the maximum number of retries and still fails,
721+
the job’s status will be set to <cite>Failed</cite>.
722+
You can define a specific method to handle this event.
723+
The method should be named <cite>{method_name}_on_max_retries_reached</cite>.</p>
724+
<p>Here’s an example:</p>
725+
<pre class="code python literal-block">
726+
<span class="kn">from</span> <span class="nn">odoo</span> <span class="kn">import</span> <span class="n">models</span><span class="p">,</span> <span class="n">fields</span><span class="p">,</span> <span class="n">api</span><span class="w">
727+
728+
</span><span class="k">class</span> <span class="nc">MyModel</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><span class="w">
729+
</span> <span class="n">_name</span> <span class="o">=</span> <span class="s1">'my.model'</span><span class="w">
730+
731+
</span> <span class="k">def</span> <span class="nf">button_done</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><span class="w">
732+
</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s1">'my.model'</span><span class="p">]</span><span class="o">.</span><span class="n">with_delay</span><span class="p">()</span><span class="o">.</span><span class="n">my_method</span><span class="p">(</span><span class="s1">'a'</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span><span class="w">
733+
734+
</span> <span class="k">def</span> <span class="nf">my_method_on_max_retries_reached</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><span class="w">
735+
</span> <span class="c1"># This method is called when the job reaches the maximum retries and fails</span><span class="w">
736+
</span> <span class="c1"># Add your custom logic here</span>
737+
</pre>
738+
<p>In this example, <cite>my_method_on_max_retries_reached`</cite> is the method
739+
that will be called when the job my_method fails after reaching the maximum retries.
740+
You can add your custom logic inside this method to handle the event.</p>
718741
<p><strong>Job Context</strong></p>
719742
<p>The context of the recordset of the job, or any recordset passed in arguments of
720743
a job, is transferred to the job according to an allow-list.</p>
@@ -958,7 +981,9 @@ <h2><a class="toc-backref" href="#toc-entry-17">Contributors</a></h2>
958981
<div class="section" id="maintainers">
959982
<h2><a class="toc-backref" href="#toc-entry-18">Maintainers</a></h2>
960983
<p>This module is maintained by the OCA.</p>
961-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
984+
<a class="reference external image-reference" href="https://odoo-community.org">
985+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
986+
</a>
962987
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
963988
mission is to support the collaborative development of Odoo features and
964989
promote its widespread use.</p>

0 commit comments

Comments
 (0)