Download the PHP package schoolpalm/queued-jobs without Composer
On this page you can find all versions of the php package schoolpalm/queued-jobs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download schoolpalm/queued-jobs
More information about schoolpalm/queued-jobs
Files in schoolpalm/queued-jobs
Package queued-jobs
Short Description A Laravel queue infrastructure package that preserves application execution context when dispatching queued jobs.
License MIT
Informations about the package queued-jobs
SchoolPalm Queued Jobs
A Laravel queue infrastructure package that preserves application execution context (tenant, school, user, module) when dispatching and processing queued jobs. Designed for multi-tenant and multi-school Laravel applications.
Why?
In multi-tenant or multi-school applications, queued jobs often need access to the same context (tenant, school, user, module) that was present when the job was originally dispatched. Without context propagation, each job would need to manually resolve this information, leading to duplicated code and potential inconsistencies.
This package provides a clean, extensible way to automatically capture and restore the application execution context when dispatching and processing queued jobs.
Installation
Publish Configuration
Run Migrations
Quick Start
1. Create a Context-Aware Job
Extend ContextAwareJob:
2. Register a Context Resolver
In your AppServiceProvider:
3. Register a Context Restorer
The restorer runs before each queued job executes, restoring the application state:
4. Dispatch Jobs
Using the Facade (with fluent context overrides)
Standard Laravel Dispatch
If the job is dispatched via GenerateReport::dispatch(), the context will NOT be attached automatically. Always use the QueuedJobs::job() facade to ensure context propagation.
Fluent API Reference
QueuedJobs::job(object $job): JobBuilder
Start building a job dispatch.
| Method | Description |
|---|---|
->withTenant(string\|int $id) |
Attach tenant context |
->withSchool(string\|int $id) |
Attach school context |
->withUser(string\|int $id) |
Attach user context |
->withModule(string $module) |
Attach module context |
->withMetadata(array $data) |
Attach arbitrary metadata |
->withContext(array\|QueueContext $ctx) |
Attach full context object or array |
->onConnection(?string $conn) |
Set queue connection |
->onQueue(?string $queue) |
Set queue name |
->delay($delay) |
Set job delay |
->tries(int $tries) |
Override max retry attempts |
->timeout(int $seconds) |
Override job timeout |
->backoff(int\|array $backoff) |
Override retry backoff |
->afterCommit(bool $value = true) |
Dispatch after DB commit |
->middleware(array $middleware) |
Add job-specific middleware |
->sync() |
Dispatch synchronously (immediate) |
->dispatch() |
Execute the dispatch |
->dispatchSync() |
Execute synchronously (immediate) |
->result() |
Get the created QueueJobResult (or null) |
->resultResource() |
Get a JobResultResource for the result (or null) |
->resultArray() |
Get the result as an API-friendly array (or null) |
QueuedJobs::resolveContextUsing(Closure $callback)
Register a callback that captures the current application context.
QueuedJobs::restoreContextUsing(Closure $callback)
Register a callback that restores application context before job execution.
QueuedJobs::context(array|QueueContext $context)
Set global or default context.
Job Result Tracking
The package includes optional job result tracking with a database-backed results table.
Creating a Result
For jobs extending ContextAwareJob, a result record is created automatically when
the job is dispatched through QueuedJobs::job(...)->dispatch(). The created record
uses the resolved queue context (school, user, module) and is exposed through the builder:
You can also create result records manually with JobResultManager:
Marking Completion / Failure
Querying Results
Context Serialization
Context is serialized with the job into the Laravel queue payload. The QueueContext value object is immutable and safely serializes/unserializes via PHP's native serialization. When the queue worker pops the job:
- Laravel unserializes the job (including the
queueContextarray) - The
RestoreJobContextmiddleware fires - The array context is converted back to a
QueueContextvalue object - Your registered
restoreContextUsingcallback is invoked - Your job's
handle()method runs with full context restored
Architecture
Configuration
| Option | Default | Description |
|---|---|---|
connection |
QUEUE_CONNECTION env |
Default queue connection |
queue |
QUEUE_NAME env |
Default queue name |
capture_context |
true |
Auto-capture context on dispatch |
auto_restore_context |
true |
Auto-restore context on job execution |
middleware |
[RestoreJobContext::class] |
Middleware applied to jobs |
tries |
3 |
Default job retry count |
timeout |
120 |
Default job timeout (seconds) |
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
All versions of queued-jobs with dependencies
illuminate/contracts Version ^12.0|^11.0
illuminate/support Version ^12.0
illuminate/queue Version ^12.0
illuminate/cache Version ^12.0|^11.0