lalo
lalo

Reputation: 929

Relation between a Laravel Command and a Job

Let's say I have a long-lived process to run "Backup Database 1"

What's the best approach?

  1. Should a Job call the Artisan Command?
  2. Should an Artisan Command call a Job?
  3. Should both call a third Class?
  4. Should the html button call a Job and then output the log file?

Notes:

Laravel documentation says you can execute commands in the queue, adding more confusion.

I tried the example, but the --queue option is not automatically implemented

https://laravel.com/docs/5.6/artisan#programmatically-executing-commands

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

Upvotes: 1

Views: 1166

Answers (1)

latr.88
latr.88

Reputation: 859

Create the artisan command and make the job call it in your app/Console/Kernel like this:

$schedule->command("command_name")->dailyAt("00:00")->thenPing(env("PING_BACKUP_DB"));

Use the ping part if you're using forge to check that your command is running.

Then create the route you need and run the command you need, see here from Laravel Docs

Try Artisan:call instead of queue, you'll see the example if you scroll down a little bit on the link attached

Upvotes: 4

Related Questions