Skip to content

[13.x] Add payload to InspectedJob#60326

Merged
taylorotwell merged 5 commits into
laravel:13.xfrom
jackbayliss:13.x-add-payload-to-inspectedjob
May 31, 2026
Merged

[13.x] Add payload to InspectedJob#60326
taylorotwell merged 5 commits into
laravel:13.xfrom
jackbayliss:13.x-add-payload-to-inspectedjob

Conversation

@jackbayliss
Copy link
Copy Markdown
Contributor

@jackbayliss jackbayliss commented May 30, 2026

If you use Queue::createPayloadUsing we may include additional payload information, but this isn't exposed via any of the queue inspection methods. (Thanks for pointing me at this method Taylor lol)

This PR adds payload to the InspectedJob so we can access it if we have any custom payload information.

 Queue::createPayloadUsing(function ($connection, $queue, $payload) {
      $job = $payload['data']['command'] ?? null;

      return is_object($job) && method_exists($job, 'context')
          ? ['context' => $job->context()]
          : [];
  });

  // when inspecting:
  Queue::reservedJobs()->first()->payload['context']; // ['tenant' => 'acme', ...]

I considered a static buildUsing callback on InspectedJob to allow swapping the class entirely, but felt like exposing the payload was simpler? Open to your opinion tho cause I wasnt sure what you'd prefer / maybe a better way?

I moved about the vars cause createdAt seemed odd not being last, I guess a slight b/c but dont think anyone is using it in that way

I figured you can already see the payload in the DB etc, so no harm seeing it via the inspection methods, and also useful for debugging

Test included

@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.

@jackbayliss jackbayliss marked this pull request as ready for review May 30, 2026 12:13
@ziadoz

This comment was marked as outdated.

@jackbayliss
Copy link
Copy Markdown
Contributor Author

jackbayliss commented May 30, 2026

@ziadoz Good question for all of the inspection methods tbh, but this follows how it is already, I'd imagine there's a good pr for that tho 😉 - will poke it when I get time

@ziadoz

This comment was marked as outdated.

@jackbayliss jackbayliss marked this pull request as draft May 30, 2026 21:39
@jackbayliss
Copy link
Copy Markdown
Contributor Author

jackbayliss commented May 30, 2026

@ziadoz Encryption only happens on the command ie job via iedata.command afaik, so it's not a concern for now as when using Queue::createPayloadUsing it gets put on the outer array, not on the data.command bit, so not encrypted.

It could be worth looking at separately, if you wanted to tap into the command via the inspect stuff but not sure if anyone would really want to tap into the command or at least I dont have a use case for it yet :D

@jackbayliss jackbayliss marked this pull request as ready for review May 30, 2026 23:03
@ziadoz

This comment was marked as outdated.

@taylorotwell taylorotwell merged commit 7b57397 into laravel:13.x May 31, 2026
52 checks passed
@jackbayliss jackbayliss deleted the 13.x-add-payload-to-inspectedjob branch May 31, 2026 22:10
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