Set up scheduled tasks in odoo15

concept

Mainly the ir.cron model, which has the following properties

  • ir_actions_server_id: server action
  • cron_name: task name
  • user_id: scheduler user, default is the current environment user
  • active: Default True
  • interval_number: frequency of task execution
  • interval_type: unit of task execution frequency, including: days, hours, minutes, weeks, months
  • numbercall: The number of times the loop runs, -1 means it continues to execute.
  • doall: indicates that the execution opportunity was missed during the server restart, whether to supplement the execution again
  • nextcall: next execution call time
  • lastcall: last execution time
  • priority: the priority of the job, 0 is high priority, 10 is low priority

application

Create a cron_res.xml file in the data folder of the module.
The code is as follows:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="res_ptn_demo" model="ir.cron">
        <field name="name">async model res</field>
        <field name="model_id" ref="model_my_res_ptn"/>
        <field name="state">code</field>
        <field name="code">model._async_model_res()</field>
        <field name='interval_number'>3</field>
        <field name='interval_type'>minutes</field>
        <field name="numbercall">-1</field>
    </record>
</odoo>

The above needs attention:

  • mode_id: Indicates the model where the task method is located, the value is model_model name
  • code: Specifies the task method name, the value is model.method name

After the above module is initialized, a record will be generated in the ir.cron of the database. As long as the program is not interrupted, the set tasks will be executed regularly.

Guess you like

Origin blog.csdn.net/weixin_44141284/article/details/132336233