Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
1731 Zobrazení

Hello,

Is there a mechanism how to run a code on Odoo startup, but when all the models are loaded and DB is ready?

The aim is to auto run some background tasks and services when the Odoo starts/restarts (just like bots etc.).


Thank you!

Avatar
Zrušit
Nejlepší odpověď

Hi,


Yes, there is a way to run code after Odoo has fully loaded, including all models and a ready database. If you want to kick off background tasks or services (like bots, listeners, etc.) right after startup, here's are steps:

Use post_init_hook or pre_init_hook (for one-time setup tasks)


These hooks can be defined in your __manifest__.py, but they're mostly intended for module installation or upgrade—not for every startup.


Easiest workaround: Use a scheduled action (cron)


Create a scheduled action that runs every minute (or just once, if you set number_of_calls = 1). It’s reliable and DB-aware.


Example:


xml

<record id="ir_cron_startup_task" model="ir.cron">

    <field name="name">Startup Task</field>

    <field name="model_id" ref="your_module.model_your_model"/>

    <field name="state">code</field>

    <field name="code">model.your_startup_method()</field>

    <field name="interval_number">1</field>

    <field name="interval_type">minutes</field>

    <field name="numbercall">-1</field>

    <field name="active">True</field>

</record>


If you only want it to run once, set numbercall to 1.


Hope it helps

Avatar
Zrušit
Nejlepší odpověď

Hello


I have the same question. The only idea I had so far is to launch a cron with a 1 minute interval.


BR

Nico

Avatar
Zrušit

Please tell in more details

Related Posts Odpovědi Zobrazení Aktivita
3
srp 25
2613
1
kvě 25
2646
1
dub 25
3637
1
dub 25
4492
1
dub 25
1962