Repository navigation
v1.3.0
Changed
- The default driver is now
auto: Action Scheduler when a plugin bundling it is active and initialised, WP-Cron otherwise, resolved on each dispatch. A site with WooCommerce therefore queues through Action Scheduler after upgrading; payloads already queued through WP-Cron still run. SetPOLLORA_ASYNC_DRIVERtowp-cronto keep the previous behaviour. - The WP-Cron recovery task also leaves alone a stored payload whose Action Scheduler action is still pending.
- The type of
capture()andwhen()callbacks is documented ascallable, so closures with typed parameters pass static analysis.
Added
capture()on an asynchronous registration: a callback run at trigger time, in the original request, with the hook arguments; the array it returns is read back at execution throughAsyncContext::get(). Captured values travel like arguments. A handler class's publiccapture()method is used whencapture()is not called.when(): queue only when the callback, given the hook arguments, returnstrue. It runs before the capture, and an exception it throws goes through, as it would synchronously.tries(): a handler that throws is queued again, through the driver that queued it, until it has used its attempts; each failed attempt is reported, the last one is fired aspollora/async/failed.backoff()sets the seconds before each retry (default 10, 60, then 300; the last value repeats). A handler that no longer exists is not retried.asUser(): run as the user who fired the hook, then remove that user. Without it the handler runs without a current user.onQueue(): queue name, used as the Action Scheduler group and the Laravel queue; WP-Cron ignores it.unique(): merge identical triggers (same hook, same handler, same arguments) while the first one has not started running. The lock is an option that is not autoloaded, taken atomically withadd_option(), released when the first attempt starts, and expiring afterunique(for: …)seconds (one day by default) if never released; the daily maintenance task deletes expired locks. A lock that cannot be stored is a queuing failure, never a silent merge.action-schedulerdriver, offered when a plugin bundling Action Scheduler is active and its data store is initialised (never a dependency). The payload travels whole as the action argument, the queue name becomes the group (polloraby default), and history is visible in Tools › Scheduled Actions. A payload too long for Action Scheduler's arguments (8,000 characters as JSON) is kept in an option that is not autoloaded and the action carries only its identifier.Async::setAutoDrivers(): the driversautotries, in order.Async::fake()for tests: records queued handlers instead of queuing them, whatever the driver, withAsync::assertDispatched()(by class, descriptor orclosure, with an optional callback receiving the payload and the delay),assertDispatchedTimes(),assertNotDispatched()andassertNothingDispatched(). Arguments are still normalized, so one that cannot travel fails here too;runDispatched()runs the recorded handlers. Assertions go through PHPUnit when it is installed.- Closures as asynchronous handlers, when
laravel/serializable-closureis installed (suggested, not required). The closure is serialized with it and signed with an HMAC-SHA256 whose key derives fromwp_salt('auth'), or is set withAsync::useClosureKey(); the signature is checked before anything is unserialized, and an altered payload or a changed key fails with an explicit report. The closure is checked at registration but signed when its hook first fires, sincewp_salt()is pluggable and not loaded while plugins load. A closure made from a named function or method (strlen(...),$object->method(...)) travels by that name. - Payloads record the driver that queued them, the queue,
asUser, the backoff and the unique lock. These fields are optional, so payloads queued by 1.2.0 still run.
Full Changelog: v1.2.0...v1.3.0