Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[13.x] Allow Jobs to include context#60243

Draft
jackbayliss wants to merge 5 commits into
laravel:13.xfrom
jackbayliss:13.x-allow-jobs-to-include-context
Draft

[13.x] Allow Jobs to include context#60243
jackbayliss wants to merge 5 commits into
laravel:13.xfrom
jackbayliss:13.x-allow-jobs-to-include-context

Conversation

@jackbayliss
Copy link
Copy Markdown
Contributor

@jackbayliss jackbayliss commented May 22, 2026

When you use any of the Queue inspect methods ie reservedJobs etc sometimes... you just want a bit more.. CONTEXT

A lot of Jobs you'll just have a generic wrapper, such as a PodcastJob, it would be very helpful to be able to just get a bit of context when things like deployments are happening which are useful for observability ie so we know more context about that exact job thats holding deployments etc.

This adds a HasContext interface, that you implement and return an array of what you need in the context() method take below as an example....:

class AgentJob implements ShouldQueue, HasContext
{
    public function context(): array
    {
        return [
            'provider' => $this->provider,
            'model'    => $this->model,
        ];
    }
}

This means you can just do...

 Queue::reservedJobs()->first()->context

And instantly, we have more details so I can easily see "Hmm.. this agent is always slow around deployments" etc etc..

The context is saved to the job payload, so it shouldn't be a book, just nice details you need... no idea

Used an interface cause I can't think of a nicer non b/c way unless you're happy to just method_exists it...

I went with context, as it felt right, but open to renaming it.

@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

Comment on lines +22 to +23
public readonly array $context = [],
public readonly ?Carbon $createdAt = null,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It pained me to not see createdAt last, so just went with it..

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