Skip to Content
Menu
This question has been flagged
1 Reply
2653 Views

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
2
Feb 24
2879
1
Jul 25
820
2
Jan 24
1385
1
May 23
1599
3
Jul 23
2282