-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
[4.x dev] Added support for handler-url and headers per job #139
Changes from 2 commits
8bb520a
b461e1e
7a0f7df
e642299
fa0d675
4cf5598
829f720
4b224ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stackkit\LaravelGoogleCloudTasksQueue; | ||
|
||
interface HasTaskHandlerUrl | ||
{ | ||
public function taskHandlerUrl(): string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stackkit\LaravelGoogleCloudTasksQueue; | ||
|
||
interface HasTaskHeaders | ||
{ | ||
/** @return array<string, mixed> */ | ||
public function taskHeaders(): array; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, I really like this. I think we can remove the trait WithDefaultTaskHeaders
{
public function taskHeaders(): array
{
return [];
}
} Much more clear where the task headers are defined rather than a global method somewhere in a service provider. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I personally also want to have 1 way to add task headers, but was doubting if I should remove the Will do so now. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Support; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Stackkit\LaravelGoogleCloudTasksQueue\HasTaskHandlerUrl; | ||
|
||
class CustomHandlerUrlJob implements ShouldQueue, HasTaskHandlerUrl | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function handle(): void | ||
{ | ||
event(new JobOutput('CustomHandlerUrlJob:success')); | ||
} | ||
|
||
public function taskHandlerUrl(): string | ||
{ | ||
return 'https://example.com/api/my-custom-route'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Support; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Stackkit\LaravelGoogleCloudTasksQueue\HasTaskHeaders; | ||
|
||
class CustomHeadersJob implements ShouldQueue, HasTaskHeaders | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function handle(): void | ||
{ | ||
event(new JobOutput('CustomHandlerUrlJob:success')); | ||
} | ||
|
||
/** @inheritdoc */ | ||
public function taskHeaders(): array | ||
{ | ||
return [ | ||
'X-MyJobHeader' => 'MyJobValue', | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say there is a
staging
andproduction
environment. How can I use a separate high performance queue in production (because it's high traffic) but use the same single queue setup in staging?Or when both environments do have a high-performance queue, they need to point to different URLs which will need a configuration and environment variable. How can we make that possible?
I feel like you'd encounter that situation quickly, which is why I toyed with the idea of putting this into the
config/queue.php
settings:Code snippet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I understand the need and use case, but is this something this package needs to take care of, or is this logic that can be put in the
taskHandlerUrl()
method of the job? Because I can imagine that jobs A and B will behave differently than jobs C and D, url wise (and environment) wise.I do like the option to have multiple handlers in the config, but personally I would not hard-code these. Other than a
'default'
.Something like this:
The package or project that implements this cloud-tasks package is free to update the config as they desire and add other handlers.
With this config setup, the
taskHandlerUrl()
implementation of the job can fetch the appropriate handler url from the config if needed. Or add other logic to return the right handler url for that job. That's up to the job.The main 'problem' I got with these hardcoded handlers: not all projects have "low performance" or "high performance".
Without going into too much detail: my use case is that I have 2 different handlers: the default and one with a static outgoing IP address. This does not fit the hardcoded performance handlers.
Let me know what you think of this, or perhaps have other suggestion(s) based on this.