From e56df3a9ffe16b5d38af266687c6dcbe82914f85 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 08:52:03 -0600 Subject: [PATCH 1/9] first go at adding a verbose flag The idea here is to show what event just started, to help identify long-running events (with bad code we sometimes have crons running for literally hours and it can be tricky to identify the exact event causing the problem). --- src/Cron_Event_Command.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index e3e74720..1afbfba9 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -224,6 +224,9 @@ public function schedule( $args, $assoc_args ) { * * [--all] * : Run all hooks. + * + * [--verbose] + * : List event both before and after execution. * * ## EXAMPLES * @@ -242,7 +245,11 @@ public function run( $args, $assoc_args ) { } $executed = 0; + $verbose = Utils\get_flag_value( $assoc_args, 'verbose' ); foreach ( $events as $event ) { + if ( $verbose ) { + WP_CLI::log( sprintf( "Beginning execution of cron event '%s'.", $event->hook ) ); + } $start = microtime( true ); $result = self::run_event( $event ); $total = round( microtime( true ) - $start, 3 ); From cacec6fd7e0e9e17b721d15dd95eaca6e8f84d17 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 09:05:39 -0600 Subject: [PATCH 2/9] phpcs fixes v1 --- src/Cron_Event_Command.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index 1afbfba9..c2b8378d 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -224,9 +224,9 @@ public function schedule( $args, $assoc_args ) { * * [--all] * : Run all hooks. - * - * [--verbose] - * : List event both before and after execution. + * + * [--verbose] + * : List event both before and after execution. * * ## EXAMPLES * @@ -245,11 +245,11 @@ public function run( $args, $assoc_args ) { } $executed = 0; - $verbose = Utils\get_flag_value( $assoc_args, 'verbose' ); + $verbose = Utils\get_flag_value( $assoc_args, 'verbose' ); foreach ( $events as $event ) { - if ( $verbose ) { - WP_CLI::log( sprintf( "Beginning execution of cron event '%s'.", $event->hook ) ); - } + if ( $verbose ) { + WP_CLI::log( sprintf( "Beginning execution of cron event '%s'.", $event->hook ) ); + } $start = microtime( true ); $result = self::run_event( $event ); $total = round( microtime( true ) - $start, 3 ); From dbb923a360aef4173e9ced894308556bf8af6cb3 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 09:12:01 -0600 Subject: [PATCH 3/9] add verbose flag test --- features/cron-event.feature | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/features/cron-event.feature b/features/cron-event.feature index 2512d887..b24e2236 100644 --- a/features/cron-event.feature +++ b/features/cron-event.feature @@ -158,3 +158,18 @@ Feature: Manage WP Cron events """ Debug: Arguments: """ + + Scenario: Confirm that cron event run with verbose flag lists both before and after + When I run `wp cron event run wp_cli_test_event_1 --due-now --verbose` + Then STDOUT should contain: + """ + Beginning execution of cron event 'wp_cli_test_event_1' + """ + And STDOUT should contain: + """ + Executed the cron event 'wp_cli_test_event_1' + """ + And STDOUT should contain: + """ + Executed a total of 1 cron event + """ From 69bfb40d8e0cb651fc861e092487e61db8b486f4 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 09:36:32 -0600 Subject: [PATCH 4/9] simplify the test output I need to probably actually create and schedule an event explicitly? --- features/cron-event.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/cron-event.feature b/features/cron-event.feature index b24e2236..6feaa789 100644 --- a/features/cron-event.feature +++ b/features/cron-event.feature @@ -163,13 +163,13 @@ Feature: Manage WP Cron events When I run `wp cron event run wp_cli_test_event_1 --due-now --verbose` Then STDOUT should contain: """ - Beginning execution of cron event 'wp_cli_test_event_1' + Beginning execution of cron event """ And STDOUT should contain: """ - Executed the cron event 'wp_cli_test_event_1' + Executed the cron event """ And STDOUT should contain: """ - Executed a total of 1 cron event + Executed a total of """ From 0925c7bf9f2e88cefd4a64d62be38fc0115dd0c3 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 09:39:49 -0600 Subject: [PATCH 5/9] fix command line :V --- features/cron-event.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/cron-event.feature b/features/cron-event.feature index 6feaa789..fb7a3a68 100644 --- a/features/cron-event.feature +++ b/features/cron-event.feature @@ -160,7 +160,7 @@ Feature: Manage WP Cron events """ Scenario: Confirm that cron event run with verbose flag lists both before and after - When I run `wp cron event run wp_cli_test_event_1 --due-now --verbose` + When I run `wp cron event run --due-now --verbose` Then STDOUT should contain: """ Beginning execution of cron event From ebf084c97fe9d1bf62a4c4b49a526e5ba936d5c7 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 11:00:57 -0600 Subject: [PATCH 6/9] refactor to use the pre-existing debug switch --- features/cron-event.feature | 6 +++--- src/Cron_Event_Command.php | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/features/cron-event.feature b/features/cron-event.feature index fb7a3a68..22cbe945 100644 --- a/features/cron-event.feature +++ b/features/cron-event.feature @@ -159,9 +159,9 @@ Feature: Manage WP Cron events Debug: Arguments: """ - Scenario: Confirm that cron event run with verbose flag lists both before and after - When I run `wp cron event run --due-now --verbose` - Then STDOUT should contain: + Scenario: Confirm that cron event run in debug mode shows the start of events + When I run `wp cron event run --due-now --debug=cron` + Then STDERR should contain: """ Beginning execution of cron event """ diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index c2b8378d..b8d2e206 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -225,9 +225,6 @@ public function schedule( $args, $assoc_args ) { * [--all] * : Run all hooks. * - * [--verbose] - * : List event both before and after execution. - * * ## EXAMPLES * * # Run all cron events due right now @@ -247,9 +244,7 @@ public function run( $args, $assoc_args ) { $executed = 0; $verbose = Utils\get_flag_value( $assoc_args, 'verbose' ); foreach ( $events as $event ) { - if ( $verbose ) { - WP_CLI::log( sprintf( "Beginning execution of cron event '%s'.", $event->hook ) ); - } + WP_CLI::debug( sprintf( "Beginning execution of cron event '%s'.", $event->hook ), 'cron' ); $start = microtime( true ); $result = self::run_event( $event ); $total = round( microtime( true ) - $start, 3 ); From 4183a8546e86cd3460a927917842fc89ea40b8b2 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 11:13:59 -0600 Subject: [PATCH 7/9] update behat tests --- features/cron-event.feature | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/features/cron-event.feature b/features/cron-event.feature index 22cbe945..7aa280ea 100644 --- a/features/cron-event.feature +++ b/features/cron-event.feature @@ -160,16 +160,16 @@ Feature: Manage WP Cron events """ Scenario: Confirm that cron event run in debug mode shows the start of events - When I run `wp cron event run --due-now --debug=cron` - Then STDERR should contain: + When I run `wp cron event run wp_version_check --debug=cron` + Then STDOUT should contain: """ - Beginning execution of cron event + Executed the cron event 'wp_version_check' """ And STDOUT should contain: """ - Executed the cron event + Executed a total of 1 cron event """ - And STDOUT should contain: + And STDERR should contain: """ - Executed a total of + Debug: Beginning execution of cron event 'wp_version_check' """ From 8e5ff64a31958f6e5973c2c7d754dbbe348031fa Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 11:15:00 -0600 Subject: [PATCH 8/9] remove no-longer-needed flag --- src/Cron_Event_Command.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index b8d2e206..ca3202a4 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -242,7 +242,6 @@ public function run( $args, $assoc_args ) { } $executed = 0; - $verbose = Utils\get_flag_value( $assoc_args, 'verbose' ); foreach ( $events as $event ) { WP_CLI::debug( sprintf( "Beginning execution of cron event '%s'.", $event->hook ), 'cron' ); $start = microtime( true ); From 1a2e9fc4cf84ab532d36b6d9110bf55465e44e13 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 12 Feb 2026 11:41:42 -0600 Subject: [PATCH 9/9] switch task types in behat --- features/cron-event.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/cron-event.feature b/features/cron-event.feature index 7aa280ea..06644e02 100644 --- a/features/cron-event.feature +++ b/features/cron-event.feature @@ -160,7 +160,7 @@ Feature: Manage WP Cron events """ Scenario: Confirm that cron event run in debug mode shows the start of events - When I run `wp cron event run wp_version_check --debug=cron` + When I try `wp cron event run wp_version_check --debug=cron` Then STDOUT should contain: """ Executed the cron event 'wp_version_check'