Automattic / Cron-Control

A fresh take on running WordPress's cron system, allowing parallel processing

Home Page:https://wordpress.org/plugins/wp-cron-control/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Events Store: improve handling of DB errors when race condition creates duplicates

ethitter opened this issue · comments

In rare cases, duplicate recurring events are created, and when the second event runs, its record will fail to update due to the unique constraints on the table. When Events_Store::create_or_update_job() triggers a "Duplicate entry 'X' for key 'ts_action_instance_status'" error, the store should better-recover from this state. It generally involves deleting duplicate events, or purging the entire queue, depending on size and the importance of the queue's contents.

REPLACE INTO or ON DUPLICATE UPDATE might help here (or simply OOL with versioning)

That duplicate entry is as result of this logic: https://github.com/Automattic/Cron-Control/blob/master/includes/class-events.php#L491. Easy to replicate with something that has a 12hour interval and is listed twice.

Need to decide if it's valid to have two recurring events with same action/instance, b/c if the interval is large enough they will clash a lot so this logic needs adjusting.

Or, the plugin makes an executive decision and disallows duplicates like this. Instead prompting users to utilize the instance args if they need "duplicates". I like this option a lot, as it also allows cron control to "cleanup" after other race conditions have caused accidental duplicates.

Tracking in #234