Skip to content

Custom handler url? #136

Closed
Closed

Description

@aaajeetee

This package is very nice, and I use it with great pleasure. However, I got to ask: why is the handler url always fixed at /handle-task? Personally, I would like to be able to overwrite this with my own handle-task endpoint, pass additional query-parameters etcetera. Also, I would like to have a different handler for different jobs. As of now, I'm forced to overwrite the config value, which doesn't quite feel right.

I'm happy to make a pull request with a change for this. Perhaps by checking if a method exists on the job and call that method? And fall back to /handle-task, to make it backwards compatible.

I'm wondering if there is a specific reason for this not to be adjustable, and if you'd be willing to look into (and merge) such a feature?

Activity

  1. Plytas commented on Feb 22, 2024

    @Plytas
    Contributor

    I'd like to see ability to specify url per queue too. We're actually running a fork because of this reason. It was my colleague that implemented this so I'm not yet familiar with how we do it, but I'd be willing to investigate and help contribute.

  2. marickvantuil commented on Feb 22, 2024

    @marickvantuil
    Member

    This package is very nice, and I use it with great pleasure

    Thanks!

    I'm open to all ideas, and I'm interested to know: What is the reasoning for having different endpoints for jobs? Is it, so a job can be dispatched on app A, but be handled by app B? Some examples/use-cases would help!

    pass additional query-parameters

    Some examples would help here too. I'm currently working on 4.x which has a configurable /handle-task route name, but it's app specific, not job specific. 4.x will also make it possible to add additional headers which can be accepted in the job:

    use Illuminate\Queue\Queue;
    
    Queue::connection()->setTaskHeaders(fn (array $job) => [
        'X-My-Header' => $job['displayName']
    ]);

    Would that solve that problem?

    Anyway, love to hear more. Thanks!

  3. Plytas commented on Feb 22, 2024

    @Plytas
    Contributor

    Using different routes per queue lets us route tasks to differently sized containers. Some tasks are simple and fast so they don't need as much processing power as others. This lets us save on costs too.

    Another benefit is being able to query our logs by request url to see logs from a specific queue.

  4. aaajeetee commented on Feb 22, 2024

    @aaajeetee
    ContributorAuthor

    Basically exactly the same 2 use cases that @Plytas mentions, I'm having as well.

    A configurable /handle-task route is a big improvement, but I'd like to extend that idea by having it configurable per job - like having a "handlerUrl()" method available on the job for example.

    As I said, I'm more than happy to contribute or help in some way, but I didn't want to 'push' it without consulting first.

  5. marickvantuil commented on Feb 24, 2024

    @marickvantuil
    Member

    Sounds like a great idea. Feel free to make a PR with the changes. Can you please make them against the 4.x-dev branch? I've tidied up the code base quite a bit in 4.x so that should also make it easier to make this change. I'll release it when the rest of 4.x is done too, which will take hopefully no more than a few more weeks.

    Thinking of it, if we're doing this on a by-job basis, it might make more sense to have the headers also be a by-job basis... Something like:

    class ProcessPodcast implements ShouldQueue
    {
        use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
        public $tries = 3;
    
        public function handle()
        {
            // ...
        }
        
        public function taskHandlerUrl(): string
        {
            // ...
        }
        
        public function taskHeaders(): array
        {
            return [
                'X-My-Header' => 'My-Value',
            ];
        }
    }

    Doing it through the queue.php config file might also be an option. Keeping these sorts of configurations together. Also, more flexible if there is a test/staging environment.

    'cloudtasks' => [
        'handler'               => env('STACKKIT_CLOUD_TASKS_HANDLER', ''),
        'service_account_email' => env('STACKKIT_CLOUD_TASKS_SERVICE_EMAIL', ''),
        'signed_audience'       => env('STACKKIT_CLOUD_TASKS_SIGNED_AUDIENCE', true),
        // The default handler
        'handler'               => env('STACKKIT_CLOUD_TASKS_HANDLER'),
        // Queue specific handlers
        'queue_handlers'        => [
          'low_performance' => env('STACKKIT_CLOUD_TASKS_LOW_PERF_HANDLER', env('STACKKIT_CLOUD_TASKS_HANDLER')),
          'high_performance' => env('STACKKIT_CLOUD_TASKS_HIGH_PERF_HANDLER', env('STACKKIT_CLOUD_TASKS_HANDLER')),
        ]
    ],
    
    ResourceHeavyJob::dispatch()->onQueue('high_performance');
  6. locked and limited conversation to collaborators on Feb 26, 2024
  7. converted this issue into a discussion #137 on Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions