Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Pass event instance to event listeners tag() method #1361

Merged
merged 5 commits into from
Dec 29, 2023

Conversation

mateusjatenee
Copy link
Contributor

A common problem I have is that it's hard to deal with tags on queued event listeners.
On a regular job, you have the payload available on the constructor, so you can use that as usual, e.g:

public function tags()
{
    return ['user_id' => $this->userId];
}

On an event listener, the event instance is passed to the handle method, so when Horizon calls ->tags(), we can't access any context.
This PR aims to improve that by storing the event that's being handled when building tags, and passing that event instance to the tags method, so we can do something like this:

<?php

class MyEventListener implements ShouldQueue
{
  public function handle(MyEvent $event)
  {}
  
  public function tags(MyEvent $event)
  {
    return [
      'context_id' => $event->uniqueId(),
    ];
  }
}

@taylorotwell taylorotwell merged commit 87a36e9 into laravel:5.x Dec 29, 2023
11 of 12 checks passed
@mateusjatenee mateusjatenee deleted the feature/listener-tags branch January 5, 2024 22:12
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.

2 participants