0
我試圖通過laravel 5.1隊列服務設置提醒, 工作執行並且工作正常,唯一的問題是它不會延遲工作,我不確定是否我做正確的方式,有人可以告訴我我做錯了什麼嗎?我SetReminder作業類看起來像laravel 5.1隊列作業延遲不起作用
namespace LM2\Jobs;
use LM2\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use LM2\Models\Lead;
use LM2\Models\User;
class SetReminder extends Job implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, SerializesModels;
public $user;
public $lead;
public function __construct(User $user, Lead $lead)
{
$this->user = $user;
$this->lead = $lead;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$user = new User(['client_id' => 1, 'name'=>'asdasd', 'password' => '123' , 'email' => microtime().'@gmail.com']);
$user->save();
}
}
和控制器函數調用這項工作是:
public function setReminder($lead_id, Request $request)
{
$due_time = $request->input('due_time');
$message = $request->input('message');
$user = \Auth::user();
$lead = Lead::where('_id',$lead_id)->first();
$lead->reminders = ['message' => $message , 'due_time' => $due_time, 'user_id' => $user->id, 'active' => 1];
$lead->save();
$job = (new SetReminder(
\Auth::user(),
Lead::find($lead_id)
))->delay(10);
$this->dispatch($job);
return $lead;
}
調用函數之前我在終端運行php artisan queue:listen
。 非常感謝大家:) :)
p.s新用戶插入句柄函數只是爲了測試它。
有人有想法嗎? :/ – benjah
對我而言,延遲不是一種方法。 – rajangupta