Skip to content

Standardize application job definitions - #1289

Merged
dati18 merged 2 commits into
mainfrom
ollie-use-job-base-class
Oct 14, 2026
Merged

dati18 merged 2 commits into
mainfrom
ollie-use-job-base-class

Conversation

@outdooracorn

@outdooracorn outdooracorn commented Oct 6, 2026 •

Copy link
Copy Markdown
Member
  • Use Illuminate\Foundation\Queue\Queueable in App\Jobs\Job so every application job receives the same dispatching, queue interaction, queue configuration, and model serialization behavior from a single source.
  • Convert relevant Jobs to inherit from this shared abstract base class.
  • Remove interfaces and traits that are not-used or already specified by the the abstract base class.
  • Add an architecture test to check that all queueable jobs extend App\Jobs\Job.

Having consistent job behaviour will make it easier to reason about the codebase and ensure shared configuration is applied centrally.

Bug: T440286

@outdooracorn outdooracorn self-assigned this Oct 6, 2026
@outdooracorn
outdooracorn force-pushed the ollie-use-job-base-class branch from f67a007 to 025181a Compare October 6, 2026 12:01
@outdooracorn
outdooracorn added this pull request to stack #1291 October 6, 2026 21:49
@deer-wmde

Copy link
Copy Markdown
Contributor

Oh this is marvelous refactoring, thank you Ollie!

One thing I'm not sure about is how the Job Classes that now would extend the base Job class behave with regards to how the queue workers are started (60s vs 90s timeout, also not quite sure with the retries): https://github.com/wbstack/api/blob/main/start.sh#L24
But I'm not expecting that to cause much trouble - lets try it!

@outdooracorn

Copy link
Copy Markdown
Member Author

One thing I'm not sure about is how the Job Classes that now would extend the base Job class behave with regards to how the queue workers are started (60s vs 90s timeout, also not quite sure with the retries): https://github.com/wbstack/api/blob/main/start.sh#L24
But I'm not expecting that to cause much trouble - lets try it!

Yes, that's a great thing to point out! While working on this I also noticed that the timeout and retry_after settings of our jobs, queue connections, and queue workers need improving. You'll see in the next PR in the stack(#1290) that I've started to try and document how these settings work, so that we can decide how we want to address this misalignment and hopefully prevent us from misconfiguring this in the future.

Also, the jobs need to be dispatched onto an asynchronous queue for any of the timeout or retry_after settings to have an effect. That means those settings are not enforced in any of these cases:

  • The job is dispatched via:
    • dispatch_sync($job)
    • ExampleJob::dispatchSync()
    • (new ExampleJob())->handle()
  • the sync queue connection is the configured default (e.g. in queue.php)
  • the sync queue connection is specified when dispatching the job, e.g. ExampleJob::dispatch()->onConnection('sync');

I think we have quite a few uses of the (new ExampleJob())->handle() pattern in this codebase which we should go through and decide if they should be dispatched with ExampleJob::dispatchSync() or ExampleJob::dispatch() instead. Alternatively, some of our jobs maybe be better converted to a Laravel command instead.

@outdooracorn

outdooracorn commented Oct 9, 2026 •

Copy link
Copy Markdown
Member Author

Your comment prompted me look at this some more. The tl;dr is that I think it's all okay for these jobs to now extend the Job abstract base class with a timeout of 60s.

I think that the timeout you linked to only applies to the artisan queue worker that is run when HORIZON_ENABLED is not set to 1. I don't think we currently run this artisan queue worker anywhere. Production, staging, and local k8s environments have horizon enabled (wbaas-deploy code search); the local docker compose setup doesn't configure an api container with CONTAINER_ROLE="queue" and instead uses the sync queue connection as defined in the .env.example file.

When Laravel Horizon is enabled, the configured timeout is 3600s (1h) - our api chart doesn't currently allow us to override the timeout with the HORIZON_TIMEOUT env var (wbstack/charts code search), so I think we can assume 3600s is the timeout of the queue worker(s).

So, going from the Horizon timeout of 3600s to 60s in quite the change. There are three application jobs in this PR that now extend this Job base class where they didn't previously:

While I think we need to rework these job and queue worker timeouts (and the queue connection retry_after), I don't think the timeout change in this PR will be an issue.

Remove the no-longer-used `DispatchesJobs` trait from `QueueSearchIndexBatches`.

The `$this->dispatch()` statement that was making use of this trait was removed in 00c5872 as part of the Laravel 10 upgrade.

Bug: T440286
* Use `Illuminate\Foundation\Queue\Queueable` in `App\Jobs\Job` so every application job receives the same dispatching, queue interaction, queue configuration, and model serialization behavior from a single source.
* Convert relevant Jobs to inherit from this shared base.
* Add an architecture test to check that all queueable jobs extend `App\Jobs\Job`.

Bug: T440286
@dati18
dati18 force-pushed the ollie-use-job-base-class branch from 025181a to 4cac2be Compare October 14, 2026 13:11
@dati18
dati18 merged commit 51b38c7 into main Oct 14, 2026
4 checks passed
@dati18
dati18 deleted the ollie-use-job-base-class branch October 14, 2026 13:20
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.

3 participants