[wp-trac] [WordPress Trac] #51747: wp_schedule_event fails if cron job is unfortunately running.
WordPress Trac
noreply at wordpress.org
Tue Nov 10 13:38:27 UTC 2020
#51747: wp_schedule_event fails if cron job is unfortunately running.
------------------------------+-----------------------------
Reporter: Takahashi_Fumiki | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Cron API | Version: trunk
Severity: normal | Keywords: needs-patch
Focuses: performance |
------------------------------+-----------------------------
Some feature(e.g. scheduled posts) requires `cron` parameter to be stored
in `wp_options` as single array.
But if wp cron job is running, this array may be overridden.
Writing in an easier format...
{{{
//wp-cron.php recognize cron jobs like below.
[
'a',
'b',
'c',
'z'
]
//
foreach( $jobs as $job ) {
// Oh, c should be done.
// Reschedule or unschedule events.
wp_reschedule_event( $job->event_name, $job->args );
// Execute.
$job->exec();
}
// Result corn jobs.
[
'a',
'b',
'z',
]
}}}
If someone tries scheduling a new event simultaneously, it fails.
{{{
// Si
// in wp-admin/edit.php or /wp-json/wp/v2/posts
// with wp_insert_post or something,
// expected cron jobs.
[
'a',
'b',
'c',
'please_publish_my_new_post',
'z,'
]
}}}
In this case, the actual result will be...
{{{
[
'a',
'b',
'z'
]
}}}
Thus, the `please_publish_my_new_post` hook never happens, and the post
will be marked as `Missed schedule`.
== How to reproduce
I made a plugin to reproduce this. https://github.com/kuno1/nabeatsu-of-
the-world
[[Image(https://raw.githubusercontent.com/kuno1/nabeatsu-of-the-
world/main/screenshot.png)]]
This plugin will:
- Register WP-Cron job runs every minute. The job sometimes take very long
time(40 sec) for execution.
- On front end, schedule new post in every 10 seconds.
- You will get 360 scheduled posts in 1 hour and each of them should be
published in 5 minutes from their creation.
- But some of them are "Missed schedule"
== Solution
- Scheduling and execution should be split. Scheduling matters.
I'm working on a new patch.
== Note
- In some ticket( e.g. #49520, #15148 ), changing cron storage approach.
- This frequently occurs in large sites which hold by many writers and
posted many articles.
- Some core jobs(e.g. removing old transients, empty trash) may also
increase the probability.
- Site with many customers with recurring payment(e.g. ) also have high
probability.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51747>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list