Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2266 Vistas

Good day All,


tl;dr - How do I reference the property Next Execution Date​in my Scheduled Action's python code?

I have a scheduled action that runs every day. However, there are days when all scheduled actions just kind of stopped running. Although that can be fixed easily with a server restart, the thing is once it stops, it would skip the previous days on when it should have run. Since we have a property called Next Execution Date​, along with Repeat Missed​ set to true, I figure if I can just reference that in the python code, then the issue regarding previous days would be fixed.


Regards,
Ariel



Avatar
Descartar
Mejor respuesta

Hi,

You can handle missed executions within the same function, ensuring your scheduled action correctly references the "Next Execution Date" and handles any missed runs.

cron_record = self.env['ir.cron'].search([('name', '=', 'your_cron_job_name')], limit=1)

if cron_record:

next_execution_date = cron_record.nextcall

current_date = fields.Datetime.now()


# Check if there are missed executions

while next_execution_date

# your custom code

# Adjust based on the frequency of your scheduled action

next_execution_date += timedelta(days=1)

# Update the nextcall field to the next scheduled date

cron_record.write({'nextcall': next_execution_date})


Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
feb 24
2032
0
ago 24
492
2
ene 24
1026
1
may 23
1291
3
jul 23
1869