1
votes

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

  • I want that to run in every night. (and see result in log)

  • Also, I want to run it manually sometimes via Artisan Command. (see result in command line)

  • Also, I need an html button to run it in my HTML Interface. (see result in screen)

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'
    ]);
1

1 Answers

4
votes

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