cron-command icon indicating copy to clipboard operation
cron-command copied to clipboard

wp cron event run --due-now doesn't respect doing_cron transient

Open janw-me opened this issue 7 years ago • 2 comments

I use wp cron event run --due-now as my production cron. Every 5 minutes. But it's a heavy cron. Sometimes it takes more then 5 minutes. When that happens some events get executed twice. Mostly sending emails.

I would suggest a --no-doubles flag or something like that to prevent the cron from doing hooks twice.

When the flag is set, wp-cli should check for the doing_cron transient like core does. And set it if it's starting. Like core does.

Relevant core code

Why is it doing things twice

At the start of a cron all tasks are gathered with _get_cron_array, events get deleted once the start. And the remaing cron array is still executed. And still in the DB list So after 5 minutes the new cron get also does a _get_cron_array and will get all events that the first cron also is still handling (and deleting as it goes).

janw-me avatar Jun 20 '18 12:06 janw-me

👍 Seems reasonable.

danielbachhuber avatar Aug 20 '18 15:08 danielbachhuber

I think this should even be the default behavior. I wouldn't consider this a breaking change, I'd classify this as a bug: We're diverting from expected Core behavior.

schlessera avatar Aug 22 '18 08:08 schlessera