Repository navigation
feat: index every driver's events in the cron option, migrate between drivers - #2
Merged
Merged
Conversation
The 'cron' option holds each event with the driver that keeps it, so wp_next_scheduled(), Site Health, WP Crontrol and Query Monitor see events Action Scheduler runs. WP-Cron no longer runs what another driver keeps, a direct write to the option reaches the driver, and Action Scheduler's own reports keep the index current. A migrator moves events between drivers, in both directions, with a dry run.
…Press loads wp cron event list gains type and driver and their filters, and running an event another driver keeps leaves its schedule alone. wp pollora schedule migrate moves events between drivers, with --dry-run. An application that starts before WordPress chooses the driver at once and the engine hooks into WordPress as soon as it can.
…dexed event wp cron event run reschedules the event, then unschedules its old time. For an event another driver keeps, that pair now leaves it scheduled. Documents the index and the migration.
…resh read The index mirrors a driver's events, so an action deleted from Tools › Scheduled Actions left an entry that wp_next_scheduled() believed and that kept a recurring event from ever being scheduled again: the engine now asks the driver that keeps an event, and drops the entry when the driver has none. A deleted action also reconciles the index when the request ends. An index write reads the option from the database first, so a long request does not undo what others scheduled since. With WP-Cron as the driver, the guard and the watchers are installed at init, and only when another driver still keeps events.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 3 of the pollora/schedule delivery plan (package side). Stacked on #1: the base is
feat/action-scheduler-driver; retarget tomainbefore deleting that branch.What it does
cronoption indexes every event with the driver that keeps it (driverkey; no key = WP-Cron's own).wp_next_scheduled(), Site Health, WP Crontrol and Query Monitor read it with no query.pre_get_scheduled_eventis no longer filtered.pre_get_ready_cron_jobs); a direct write to the option that removes or moves one reaches its driver (pre_update_option_cron).Contracts\ReportsChanges, optional, soScheduleDriveris unchanged and the package stays in 0.1.x.Migratormoves pending events between drivers in both directions, target first then source, interval from the entry,--dry-run, safe to rerun.ScheduleEngine::reindex()rebuilds the index from a driver.wp cron event listextended (type,driver, filters),wp pollora schedule migrate.Schedule::boot(): the framework starts before WordPress, so wiring waits foradd_filter().Found while testing live
wp cron event runreschedules then unschedules the old time. On a marked recurring event that cancelled the Action Scheduler action. The interceptor now remembers the pair and treats the second step as "stays". Without this, the index would have exposed Action Scheduler events to a command that destroys them.Tests
88 Pest tests, PHPStan level 5 clean. Also run on pollora-test with WooCommerce's Action Scheduler: events scheduled through
wp_schedule_event()are indexed and listed with their driver;wp cron event runkeeps a recurring event and consumes a single one; a due Action Scheduler event is not inwp_get_ready_cron_jobs(); a direct write removing an entry cancels the action; a 23-event round trip WP-Cron → Action Scheduler → WP-Cron leaves thecronoption byte-identical and a second run moves nothing.Not covered live: Site Health's late-event check (it reads the same array, so it depends on the index being current).
Added after a review of the first push
wp_next_scheduled()believed, so a recurring#[Schedule]was never created again.ScheduleEngine::next()now asks the driver that keeps a marked event and drops the entry when it has none (a driver that is not ready is trusted). A deleted action also reconciles the index once, when the request ends. WordPress's ownwp_next_scheduled()still reads the entry until the engine or a deletion hook has run: that is the price of reading the option with no query.wp_cache_delete('alloptions'|'cron', 'options')), so a long request (Action Scheduler's queue runner) does not write back its start-of-request copy over what others scheduled meanwhile. Run live with two processes (one sleeping 12 s over a stale copy): both entries survive. Core's own writes keep their own race.init, only when the index holds an entry another driver keeps. This departs from nothing in the study: with WP-Cron and no leftover, no filter is posted.Schedule::knows().Tests: 94 Pest, PHPStan clean;
TestsandCoding Standardsre-run on the branch byworkflow_dispatch(the workflows only trigger on PRs tomain): green.