Skip to content

Commit 3b13471

Browse files
authored
Merge pull request #120 from wp-cli/copilot/add-cron-arguments-logging
2 parents c1d5c12 + e89c03c commit 3b13471

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

features/cron-event.feature

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,31 @@ Feature: Manage WP Cron events
130130
"""
131131
LOG A SHUTDOWN FROM ERROR
132132
"""
133+
134+
Scenario: Run cron event with arguments and debug output
135+
When I run `wp cron event schedule wp_cli_test_event_with_args now --0=123 --1=test-value`
136+
Then STDOUT should contain:
137+
"""
138+
Success: Scheduled event with hook 'wp_cli_test_event_with_args'
139+
"""
140+
141+
When I try `wp cron event run wp_cli_test_event_with_args --due-now --debug=cron`
142+
Then STDOUT should contain:
143+
"""
144+
Executed the cron event 'wp_cli_test_event_with_args'
145+
"""
146+
And STDERR should contain:
147+
"""
148+
Debug: Arguments: ["123","test-value"]
149+
"""
150+
151+
When I run `wp cron event schedule wp_cli_test_event_no_args now`
152+
And I try `wp cron event run wp_cli_test_event_no_args --due-now --debug=cron`
153+
Then STDOUT should contain:
154+
"""
155+
Executed the cron event 'wp_cli_test_event_no_args'
156+
"""
157+
And STDERR should not contain:
158+
"""
159+
Debug: Arguments:
160+
"""

src/Cron_Event_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ public function run( $args, $assoc_args ) {
248248
$total = round( microtime( true ) - $start, 3 );
249249
++$executed;
250250
WP_CLI::log( sprintf( "Executed the cron event '%s' in %ss.", $event->hook, $total ) );
251+
if ( ! empty( $event->args ) ) {
252+
WP_CLI::debug( sprintf( 'Arguments: %s', wp_json_encode( $event->args ) ), 'cron' );
253+
}
251254
}
252255

253256
$message = ( 1 === $executed ) ? 'Executed a total of %d cron event.' : 'Executed a total of %d cron events.';

0 commit comments

Comments
 (0)