You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a recent project I've implemented a way to use Attributes to enrich properties into Job tags.
This is how I've implemented it:
class ReleasePodcast implements ShouldQueue {
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
publicfunction__construct(
#[EnrichTagAttribute('name')]
publicPodcast$podcast,
) {
}
}
$job = newReleasePodcast(
Podcast::make(['name' => 'My Podcast'])
);
ray($job->tags());
// array:2 [▼// 0 => "podcast:My_Podcast"// 1 => "App\Models\Podcast:1"// ]
In Horizon this then looks like this:
The Idea is to use EnrichTagAttribute to mark a property to be included into the tags for the jobs in the simplest possible way I could think of. When there are many Jobs, it is really bothering to always add the tags method and build up the array. Also the automatic model tags will be removed when using a custom tags method in a Job class.
A property name can also be passed to EnrichTagAttribute which will read the given property of the instance in the property to also support classes and array types.
What do you guy think about this?
If this is not a new Idea, feel free to comment a link to a existing package. Otherwise I will create a PR for Horizon which adds this functionality (PHP 8.0+ only of course...).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi Guys
For a recent project I've implemented a way to use Attributes to enrich properties into Job tags.
This is how I've implemented it:
In Horizon this then looks like this:
The Idea is to use
EnrichTagAttribute
to mark a property to be included into the tags for the jobs in the simplest possible way I could think of. When there are many Jobs, it is really bothering to always add the tags method and build up the array. Also the automatic model tags will be removed when using a custom tags method in a Job class.A property name can also be passed to
EnrichTagAttribute
which will read the given property of the instance in the property to also support classes and array types.What do you guy think about this?
If this is not a new Idea, feel free to comment a link to a existing package. Otherwise I will create a PR for Horizon which adds this functionality (PHP 8.0+ only of course...).
Beta Was this translation helpful? Give feedback.
All reactions