File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -252,8 +252,9 @@ Feature: Manage WP Cron events
252252 Success: Scheduled event with hook 'wp_cli_test_event_lock'
253253 """
254254
255- # Simulate an in-progress cron run by setting the doing_cron transient to now.
256- When I run `wp eval 'set_transient( "doing_cron", sprintf( "%.22F", microtime( true ) ) );' `
255+ # Simulate an in-progress WP-CLI cron run by setting the doing_cron transient
256+ # with the 'wpcli_' prefix that WP-CLI uses.
257+ When I run `wp eval 'set_transient( "doing_cron", "wpcli_" . sprintf( "%.22F", microtime( true ) ) );' `
257258
258259 And I try `wp cron event run --due-now`
259260 Then STDERR should contain:
Original file line number Diff line number Diff line change @@ -249,11 +249,19 @@ public function run( $args, $assoc_args ) {
249249 if ( $ due_now ) {
250250 $ lock_timeout = defined ( 'WP_CRON_LOCK_TIMEOUT ' ) ? WP_CRON_LOCK_TIMEOUT : 60 ;
251251 $ doing_cron_transient = get_transient ( 'doing_cron ' );
252- if ( is_string ( $ doing_cron_transient ) && (float ) $ doing_cron_transient > microtime ( true ) - $ lock_timeout ) {
252+ // Only treat the lock as belonging to another WP-CLI run when WP-CLI
253+ // itself set it (value starts with 'wpcli_'). WordPress's spawn_cron()
254+ // always stores a plain numeric microtime string, so we must not block
255+ // ourselves on a transient that was set by spawn_cron during bootstrap.
256+ if (
257+ is_string ( $ doing_cron_transient ) &&
258+ 0 === strncmp ( $ doing_cron_transient , 'wpcli_ ' , 6 ) &&
259+ (float ) substr ( $ doing_cron_transient , 6 ) > microtime ( true ) - $ lock_timeout
260+ ) {
253261 WP_CLI ::warning ( 'A cron event run is already in progress; skipping. ' );
254262 return ;
255263 }
256- set_transient ( 'doing_cron ' , sprintf ( '%.22F ' , microtime ( true ) ) );
264+ set_transient ( 'doing_cron ' , ' wpcli_ ' . sprintf ( '%.22F ' , microtime ( true ) ) );
257265 }
258266
259267 $ events = self ::get_selected_cron_events ( $ args , $ assoc_args );
You can’t perform that action at this time.
0 commit comments