Skip to content

feat: queue async actions through Laravel and configure them from config/hooks.php - #427

Merged
ogorzalka merged 2 commits into
developfrom
feat/async-queue-driver
Oct 7, 2026
Merged

ogorzalka merged 2 commits into
developfrom
feat/async-queue-driver

Conversation

@ogorzalka

Copy link
Copy Markdown
Member

Async Actions, phase 3 step 1 (design doc "Pollora — Async Actions: implementation document"): the framework side of ->async(). #[Async] comes in the next PR.

Changes

  • pollora/hook ^1.4 (1.4.1 locked in CI): defaults, parameter injection, final failure thrown to the queue.
  • config/hooks.php, merged, publishable with --tag=pollora-hooks: async.default (HOOKS_ASYNC_DRIVER, default auto), tries, backoff, as_user, queue.connection / queue.queue. Note: backoff sits at the top of async and not under queue as in the design doc, because it applies to every driver.
  • QueueDriver: available only when the connection's driver is neither sync (would run in the request) nor null (would drop the job). It dispatches RunAsyncAction on the configured connection, on the action's queue or the configured one, with the delay.
  • RunAsyncAction job:
    • #[Tries(1)]: retries are new jobs, queued by the package after the backoff;
    • Async::receive(..., throwOnFinalFailure: true): the last failure lands in failed_jobs, logged once by the queue;
    • wp_cache_flush_runtime() before each handler, because a worker lives across jobs and WordPress's in-memory cache would hand stale posts. Not wp_cache_flush(), which would also empty a shared Redis;
    • displayName(): pollora/async {hook} {handler}, for Horizon and failed_jobs.
  • EloquentModelReference: a saved model travels as class, key and connection, and is reloaded at execution (SerializesModels); a deleted one drops the handler, as for WordPress objects.
  • AsyncServiceProvider, registered after HookServiceProvider:
    • Async::setAutoDrivers(['queue', 'action-scheduler', 'wp-cron']);
    • default driver from the configuration (auto leaves the constant and the filter of pollora/hook in charge);
    • setDefaults() from the configuration;
    • setDebug(app.debug);
    • useClosureKey(app.key);
    • incidents to the PSR logger (error when they carry an exception, warning otherwise);
    • reference(EloquentModelReference);
    • injectParametersUsing() from the container.

Tests

  • 33 new tests (tests/Feature/Hook/Async): driver availability per connection, dispatched job, job run, final failure, cache flush, display name, model reference (SQLite), and every provider setting.
  • Full suite: 1,855 passed (in DDEV, for pdo_sqlite).
  • The four new classes are at 100 % line coverage and 100 % type coverage. Note: composer test:unit passes --min=100 without --coverage, so that threshold is not enforced, and the whole src/ sits at 46 %.
  • Rector, Pint and PHPStan pass.

@ogorzalka
ogorzalka merged commit b4c6d8c into develop Oct 7, 2026
11 checks passed
@ogorzalka
ogorzalka deleted the feat/async-queue-driver branch October 7, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant