#21072 closed enhancement (fixed)
CRON often returns ambiguous values
Reported by: | evansolomon | Owned by: | peterwilsoncc |
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Cron API | Keywords: | has-patch has-unit-tests has-dev-note |
Focuses: | Cc: |
Description
Many of the cron API functions return ambiguous values. For example, wp_cron()
returns null
(explicitly) when cron doesn't run, but it also returns null
(implicitly) every other time. This can make debugging harder.
Whenever possible, I think it's valuable to return meaningful values. The attached patch does that.
Attachments (5)
Change History (22)
#5
@
9 years ago
- Keywords needs-refresh removed
I've refreshed @evansolomon's patch.
(and boyscouted inline control structures in the touched functions).
#8
@
6 years ago
- Milestone changed from Future Release to 5.0
- Owner changed from swissspidy to peterwilsoncc
- Status changed from reviewing to accepted
This got dragged in to the patch for #32656 as return values are needed for that too.
I'll take into account @nacin's comment re return values as part of that.
#9
@
6 years ago
- Keywords has-unit-tests added
In 21072.diff:
wp_schedule_single_event()
,wp_schedule_event()
,wp_reschedule_event()
andwp_unschedule_event()
: boolean outcomewp_clear_scheduled_hook()
: false if fails to unschedule one or more events, zero if no events need to be unscheduled, or number of events unscheduled. If there are events to unschedule, partial success is possible.wp_unschedule_hook()
: false if it fails to unschedule events, zero if no events need to be unscheduled, or number of events unscheduled. If there are events to unschedule, partial success is not possible.spawn_cron()
false if no attempt to spawn, outcome ofwp_remote_post()
if an attempt is made (either an array or WP_Error)wp_cron()
: false if one or more events fail to spawn, zero if no events require spawning, integer indicating number of events spawned if all successful_set_cron_array()
: boolean outcome ofupdate_option()
.
Tests updated to include return values.
#10
@
6 years ago
Working on this on a Github PR
#11
@
6 years ago
- Keywords commit added
21072.3.diff is a tidy up of earlier patches:
- Fixes some CS errors
- Ensures
_set_cron_array
is only called when need when unscheduling
I've got a 👌 from Pento on the Github PR so labeling commit for next time I've got vvv runnning.
#13
@
6 years ago
- Milestone changed from 5.0 to 5.1
- Resolution fixed deleted
- Status changed from closed to reopened
Milestone changed to the 5.1 branch, inline docs will need to be updated.
#17
@
4 years ago
- Keywords has-dev-note added; needs-dev-note removed
This was detailed in the following dev note: https://make.wordpress.org/core/2019/01/23/cron-api-changes-in-wordpress-5-1/
I think this is good. While there are technically return value changes, I'm not too concerned about the back compat.
wp_clear_scheduled_hook() probably just needs to return true (it got cleared) or false, versus an array. It's also possible we change how that function works in the future, #25773 gave us some trouble.
The wp_remote_post() call is non-blocking, so spawn_cron() should probably not have a return value, right? Thus wp_cron() shouldn't have a return value either. I know that was the original bug report — what about
true
? Is that sufficient?