lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.49k stars 121 forks source link

Dispatch job with named queue #190

Closed rafap4j closed 2 years ago

rafap4j commented 2 years ago

Hi, I've been searching the docs to find a way to dispatch actions as jobs in specific queues, but I haven't found it yet. I'm pretty sure I'm missing something. Does anyone know how to achieve it with this (wonderful) package? For example:

config.php:

// ... (this is a custom config.php entry, it doesn't exist in fresh Laravel installations)

'default_queue_names' => [
    'erp' => [
        'data_receive' => 'erp_data_receive',
        'data_send' => 'erp_data_send'
    ]
]

CreateCustomer.php

...
use AsAction;

public function handle(array $data): Customer
{
    try {
        $customer = Customer::create($data);
    } catch (\Throwable $th) {
        throw_error($th);
    }

    // here I would want to do something like <---
    SendCustomerToErp::onQueue(
        config('queue.default_queue_names.erp.data_send')
    )->dispatch($customer);
}
leandrodiogenes commented 2 years ago

Hi @rfaugusto.

Fist of all, use AsJob method. Check docs https://laravelactions.com/2.x/as-job.html;

Next step is configure the Job dispatch https://laravelactions.com/2.x/as-job.html#configurejob

rafap4j commented 2 years ago

Awesome! Thank you very much.