flyingL123
10 months ago
119
8
Laravel

Is there a shorthand to schedule commands to be queued?

Posted 10 months ago by flyingL123

I can schedule artisan commands like this:

$schedule->command('emails:send --force')->daily();

I can schedule a queue job like this:

$schedule->job(new Heartbeat)->everyFiveMinutes();

I can queue an artisan command like this:

Artisan::queue('email:send', [
    'user' => 1, '--queue' => 'default'
]);

But, from what I can tell, there is no way to nicely schedule a queued artisan command. In other words, I can accomplish what I need like this:

$schedule->call(function () {
    Artisan::queue('command:name');
})->everyMinute();

But it seems like there should be a better way. Is there any way to use the $schedule->job() method, but pass it a command name?

Please sign in or create an account to participate in this conversation.