2017-04-07 3 views
0

사용자가 응용 프로그램에 등록 할 때 전자 메일을 보낼 작업이 있습니다.대기열 작업을 만드는 방법 : work

SendWelcomeEmail.php

<?php 

namespace App\Jobs; 

use App\Jobs\Job; 
use App\User; 
use Illuminate\Contracts\Mail\Mailer; 
use Illuminate\Contracts\Queue\ShouldQueue; 
use Illuminate\Queue\InteractsWithQueue; 
use Illuminate\Queue\SerializesModels; 

class SendWelcomeEmail extends Job implements ShouldQueue 
{ 
    use InteractsWithQueue, SerializesModels; 

    protected $user; 
    /** 
    * Create a new job instance. 
    * 
    * @return void 
    */ 
    public function __construct(User $user) 
    { 
     $this->user = $user; 
    } 

    /** 
    * Execute the job. 
    * 
    * @return void 
    */ 
    public function handle(Mailer $mailer) 
    { 
     $user = &$this->user; 

     $message = sprintf('Hello %s', $user->name); 

     $mailer->raw($message, function ($m) use ($user){ 
      $m->from('[email protected]', 'Lucas Lopes'); 
      $m->to($user->email, $user->name); 
     }); 
    } 
} 

나는 PHP 장인 큐를 실행하는 작업을 생성하고 싶습니다 : 작업 명령 큐에있는 전자 메일을 보낼 수있는 모든 분.

답변

0

가장 쉬운 방법은 수퍼바이저를 설정하는 것입니다.

https://laravel.com/docs/5.4/queues#supervisor-configuration, 실패하면 대기열 : 작업 프로세스가 자동으로 다시 시작됩니다.

당신을 위해 혼란을 해결하려면

파일 app/Console/Kernel.php에서 스케줄 함수 내에서 당신은 당신이 특정 간격으로 실행해야 할 명령을 추가합니다. 예제는 다음과 같습니다 서버에 $schedule->command('SendFailedLoginsReport')->weekly()->mondays()->at('03:00');

, 당신은

0

명령을 실행하지 않고 큐 데몬을 실행하려고합니다. laravels 예약 된 명령을 사용하지 않고 서버 환경에서이 작업을 수행해야합니다.

당신은 당신의 명령을 배치하는 리눅스의 screen 같은 것을 사용할 수 있습니다.

이를 consinuiously 새로운 일자리에 대한 큐 서버를 폴링, 다음을 처리합니다.

+0

가있는 명령을 설정할 필요가 없습니다이 크론은 Laravel 명령 스케줄러에게 매 순간을 호출 할이 * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

처럼 크론을 추가 할 수 있습니다 'app/Console/Kernel.php' 얼마나 자주 실행됩니까? –

관련 문제