Search 1.9 billion lines of Odoo code on GitHub

smile_wsqueue

Author: Smile
License: AGPL-3
Branch: 13.0
Repository: anhvu-sg/odoo_addons
Dependencies: smile_impex
Languages: HTML (478, 67.4%), PO File (66, 9.3%), Python (113, 15.9%), XML (6, 0.8%), and reStructuredText (46, 6.5%)
Other repositories: Smile-SA/odoo_addons, and anodino-dev/odoo_addons

<h1 class="title">WebService Queue</h1> <p><a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/Smile-SA/odoo_addons/tree/13.0/smile_web_impex"><img alt="Smile-SA/odoo_addons" src="https://img.shields.io/badge/github-Smile_SA%2Fodoo_addons-lightgray.png?logo=github" /></a></p> <p>This module adds helpers to implement a queue job.</p> <p>This adds the mechanism of keeping jobs inside a queue, and treat them one at a time periodically, with a restart policy in case of failures.</p> <p>You have to define your model with your own method, a cron to execute the jobs in queue, and define views to consult job history.</p> <p>This module could be greatly improved, feel free to make it better via pull requests.</p> <p><strong>Table of contents</strong></p> <div class="contents local topic" id="contents"> <ul class="simple"> <li><a class="reference internal" href="#usage" id="id1">Usage</a><ul> <li><a class="reference internal" href="#define-your-model" id="id2">Define your model</a></li> <li><a class="reference internal" href="#execution-of-queue" id="id3">Execution of queue</a></li> <li><a class="reference internal" href="#consult-jobs-enqueued" id="id4">Consult jobs enqueued</a></li> </ul> </li> <li><a class="reference internal" href="#bug-tracker" id="id5">Bug Tracker</a></li> <li><a class="reference internal" href="#credits" id="id6">Credits</a><ul> <li><a class="reference internal" href="#authors" id="id7">Authors</a></li> <li><a class="reference internal" href="#contributors" id="id8">Contributors</a></li> <li><a class="reference internal" href="#maintainers" id="id9">Maintainers</a></li> </ul> </li> </ul> </div> <a name="usage"></a> <h2><a class="toc-backref" href="#id1">Usage</a></h2> <a name="define-your-model"></a> <h3><a class="toc-backref" href="#id2">Define your model</a></h3> <p>You have to define a class inheriting from <cite>queue.job</cite>.</p> <pre> <code lang="python">class MyModuleJob(models.Model): _name = 'my_module.job' _inherit = 'queue.job' method = fields.Selection([ ('foo', 'Method doing foo'), ('bar', 'Method doing bar') ]) def foo(self): &quot;&quot;&quot;Execute the job `foo`. This could be a button method, a cron method, etc. &quot;&quot;&quot; pass def bar(self): &quot;&quot;&quot;Execute the job `bar`. This could be a button method, a cron method, etc. &quot;&quot;&quot; pass</code> </pre> <a name="execution-of-queue"></a> <h3><a class="toc-backref" href="#id3">Execution of queue</a></h3> <p>You have to define a cron to check queue periodically, eg. each 5 minutes:</p> <pre> <code lang="xml">&lt;record id=&quot;some_external_api_queue&quot; model=&quot;ir.model.export.template&quot;&gt; &lt;field name=&quot;name&quot;&gt;Some external API&lt;/field&gt; &lt;field name=&quot;model_id&quot; ref=&quot;my_module.model_my_module_job&quot; /&gt; &lt;field name=&quot;method&quot;&gt;execute_call&lt;/field&gt; &lt;field name=&quot;filter_type&quot;&gt;method&lt;/field&gt; &lt;field name=&quot;filter_method&quot;&gt;filter_jobs&lt;/field&gt; &lt;field name=&quot;unique&quot; eval=&quot;False&quot; /&gt; &lt;field name=&quot;new_thread&quot; eval=&quot;False&quot; /&gt; &lt;field name=&quot;one_at_a_time&quot; eval=&quot;True&quot; /&gt; &lt;/record&gt; &lt;record id=&quot;ir_cron_some_external_api_queue&quot; model=&quot;ir.cron&quot;&gt; &lt;field name=&quot;name&quot;&gt;Some external API - Manage queue&lt;/field&gt; &lt;field name=&quot;user_id&quot; ref=&quot;base.user_root&quot; /&gt; &lt;field name=&quot;interval_number&quot;&gt;5&lt;/field&gt; &lt;field name=&quot;interval_type&quot;&gt;minutes&lt;/field&gt; &lt;field name=&quot;numbercall&quot;&gt;-1&lt;/field&gt; &lt;field name=&quot;priority&quot;&gt;10&lt;/field&gt; &lt;field name=&quot;nextcall&quot; eval=&quot;time.strftime('%Y-%m-%d %H:00:00')&quot; /&gt; &lt;field name=&quot;model_id&quot; ref=&quot;my_module.model_my_module_job&quot; /&gt; &lt;field name=&quot;code&quot;&gt;model.execute_cron()&lt;/field&gt; &lt;field name=&quot;state&quot;&gt;code&lt;/field&gt; &lt;/record&gt; &lt;record id=&quot;some_external_api_queue&quot; model=&quot;ir.model.export.template&quot;&gt; &lt;field name=&quot;cron_id&quot; ref=&quot;ir_cron_some_external_api_queue&quot; /&gt; &lt;/record&gt;</code> </pre> <a name="consult-jobs-enqueued"></a> <h3><a class="toc-backref" href="#id4">Consult jobs enqueued</a></h3> <p>You have to define views and actions to see your jobs.</p> <p>Following code displays pending and error jobs by default:</p> <pre> <code lang="xml">&lt;record id=&quot;view_job_form&quot; model=&quot;ir.ui.view&quot;&gt; &lt;field name=&quot;name&quot;&gt;my_module.job.form&lt;/field&gt; &lt;field name=&quot;model&quot;&gt;my_module.job&lt;/field&gt; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt; &lt;form&gt; &lt;header&gt; &lt;field name=&quot;state&quot; widget=&quot;statusbar&quot;/&gt; &lt;/header&gt; &lt;sheet&gt; &lt;group col=&quot;1&quot;&gt; &lt;field name=&quot;method&quot;/&gt; &lt;/group&gt; &lt;group col=&quot;6&quot;&gt; &lt;field name=&quot;max_tries&quot;/&gt; &lt;field name=&quot;tries&quot;/&gt; &lt;field name=&quot;total_tries&quot;/&gt; &lt;/group&gt; &lt;group&gt; &lt;field name=&quot;status_code&quot;/&gt; &lt;field name=&quot;result&quot;/&gt; &lt;/group&gt; &lt;/sheet&gt; &lt;/form&gt; &lt;/field&gt; &lt;/record&gt; &lt;record id=&quot;view_job_tree&quot; model=&quot;ir.ui.view&quot;&gt; &lt;field name=&quot;name&quot;&gt;my_module.job.tree&lt;/field&gt; &lt;field name=&quot;model&quot;&gt;my_module.job&lt;/field&gt; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt; &lt;tree string=&quot;Jobs&quot; decoration-danger=&quot;state=='error'&quot; decoration-success=&quot;state=='done'&quot; decoration-muted=&quot;state=='canceled'&quot;&gt; &lt;field name=&quot;method&quot; /&gt; &lt;field name=&quot;state&quot; /&gt; &lt;field name=&quot;status_code&quot; /&gt; &lt;field name=&quot;create_date&quot; /&gt; &lt;field name=&quot;execute_date&quot; /&gt; &lt;field name=&quot;total_tries&quot; /&gt; &lt;/tree&gt; &lt;/field&gt; &lt;/record&gt; &lt;record id=&quot;view_job_search&quot; model=&quot;ir.ui.view&quot;&gt; &lt;field name=&quot;name&quot;&gt;my_module.job.search&lt;/field&gt; &lt;field name=&quot;model&quot;&gt;my_module.job&lt;/field&gt; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt; &lt;search&gt; &lt;field name=&quot;method&quot; /&gt; &lt;filter name=&quot;filter_canceled&quot; string=&quot;Canceled&quot; domain=&quot;[('state', '=', 'canceled')]&quot; /&gt; &lt;filter name=&quot;filter_done&quot; string=&quot;Done&quot; domain=&quot;[('state', '=', 'done')]&quot; /&gt; &lt;filter name=&quot;filter_error&quot; string=&quot;Error&quot; domain=&quot;[('state', '=', 'error')]&quot; /&gt; &lt;filter name=&quot;filter_pending&quot; string=&quot;Pending&quot; domain=&quot;[('state', '=', 'pending')]&quot; /&gt; &lt;filter name=&quot;groupby_state&quot; string=&quot;State&quot; context=&quot;{'group_by': 'state'}&quot; /&gt; &lt;filter name=&quot;groupby_status_code&quot; string=&quot;Status code&quot; context=&quot;{'group_by': 'status_code'}&quot; /&gt; &lt;/search&gt; &lt;/field&gt; &lt;/record&gt; &lt;record id=&quot;action_jobs_view&quot; model=&quot;ir.actions.act_window&quot;&gt; &lt;field name=&quot;name&quot;&gt;Some external API&lt;/field&gt; &lt;field name=&quot;type&quot;&gt;ir.actions.act_window&lt;/field&gt; &lt;field name=&quot;res_model&quot;&gt;my_mobule.job&lt;/field&gt; &lt;field name=&quot;view_mode&quot;&gt;tree,form&lt;/field&gt; &lt;field name=&quot;context&quot;&gt;{ 'search_default_filter_pending': 1, 'search_default_filter_error': 1 }&lt;/field&gt; &lt;/record&gt; &lt;menuitem id=&quot;menu_wsqueue_jobs_some_external_api&quot; action=&quot;action_jobs_view&quot; parent=&quot;smile_wsqueue.menu_wsqueue_jobs&quot; /&gt;</code> </pre> <a name="bug-tracker"></a> <h2><a class="toc-backref" href="#id5">Bug Tracker</a></h2> <p>Bugs are tracked on <a class="reference external" href="https://github.com/Smile-SA/odoo_addons/issues">GitHub Issues</a>. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed <a class="reference external" href="https://github.com/Smile-SA/odoo_addons/issues/new?body=module:%20smile_web_impex%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <p>Do not contact contributors directly about support or help with technical issues.</p> <a name="credits"></a> <h2><a class="toc-backref" href="#id6">Credits</a></h2> <a name="authors"></a> <h3><a class="toc-backref" href="#id7">Authors</a></h3> <ul class="simple"> <li>Smile SA</li> </ul> <a name="contributors"></a> <h3><a class="toc-backref" href="#id8">Contributors</a></h3> <ul class="simple"> <li>Paul JOANNON</li> <li>Isabelle RICHARD</li> </ul> <a name="maintainers"></a> <h3><a class="toc-backref" href="#id9">Maintainers</a></h3> <p>This module is maintained by the Smile SA.</p> <p>Since 1991 Smile has been a pioneer of technology and also the European expert in open source solutions.</p> <a class="reference external image-reference" href="http://smile.fr"><img alt="Smile SA" src="https://avatars0.githubusercontent.com/u/572339?s=200&amp;v=4" /></a> <p>This module is part of the <a class="reference external" href="https://github.com/Smile-SA/odoo_addons">odoo-addons</a> project on GitHub.</p> <p>You are welcome to contribute.</p>