Laravel 5.6-命令与作业计划电子邮件警报?

时间:2018-12-03 18:21:55

标签: command scheduled-tasks laravel-5.6

我需要每天向已订阅我的新闻通讯的用户发送电子邮件。

我是否通过创建job例如

来安排上述任务?
class ProcessEmailAlerts implements ShouldQueue
{
   use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


   public function __construct()
   {

   }

   public function handle()
   {
       $alerts = App\Alert::all();
       $articles = App\Article::latest()->orderBy('created_at')->get();

       foreach($alerts as $alert) {

           $alert->user->notify(new NewsLetterNotification($alert, $articles));
       }

   }
} 

然后在App\Console\Kernel中定义作业:

$schedule->job(new ProcessEmailAlerts)->daily();

还是应该创建如下命令:

class ProcessEmailAlerts extends Command
{
   protected $signature = 'emailalerts:send';

   protected $description = 'Send newsletter e-mails to subscribed users';


   public function __construct()
  {

  }

  public function handle()
  {
     $alerts = App\Alert::all();
       $articles = App\Article::latest()->orderBy('created_at')->get();

       foreach($alerts as $alert) {

           $alert->user->notify(new NewsLetterNotification($alert, $articles));
       }

   }
}

然后在App\Console\Kernel中定义作业:

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

基本上,我希望获得有关执行此类任务的正确方法的指南-使用作业进行调度还是使用命令进行调度?

0 个答案:

没有答案