[英]Laravel queue:listen queue:work not working
我正在嘗試在后台發送電子郵件以減少服務器響應時間。
我使用php artisan queue:table
和php artisan queue:failed-table
命令創建了jobs表和failed_jobs表。 並在.env文件中設置QUEUE_DRIVER=database
。
當我執行以下代碼時,它在作業表中創建一個作業。
\Mail::later(5, 'email.new-friend-request', ['data'=>$friend_request], function($message) use (&$friend_request){
$message->to($friend_request->notifiable->email, $friend_request->notifiable->name)->from('info@example.com','ABC')->subject('New Friend Request');
});
但是當我執行php artisan queue:listen
或php artisan queue:work
命令時。 它既不處理作業表中保存的作業,也不提供控制台上的任何輸出。
但是,當我檢查作業表時,作業的嘗試字段不斷增加。 但工作沒有得到處理。
此外,當我使用以下代碼直接發送郵件,即不將其添加到隊列。 郵件發送沒有任何問題。
\Mail::send('email.new-friend-request', ['data'=>$friend_request], function($message) use (&$friend_request){
$message->to($friend_request->notifiable->email, $friend_request->notifiable->name)->from('info@example.com','ABC')->subject('New Friend Request');
});
更新
我嘗試發送沒有任何數據的電子郵件,它也沒有任何問題。 即
\Mail::later(5, 'email.new-friend-request', [], function($message) use (&$friend_request){
$message->to($friend_request->notifiable->email, $friend_request->notifiable->name)->from('info@example.com','ABC')->subject('New Friend Request');
});
我明白了,問題在於Eloquent關系。 當qued電子郵件時,需要序列化Eloquent模型對象。 因此,一旦模型對象被序列化,那么就無法訪問關系。
所以我只是嘗試加載模型關系,並使用toArray()
方法將我的模型對象轉換為數組,然后開始處理作業。
那是在召喚之前
\Mail::later(5, 'email.new-friend-request', ['data'=>$friend_request], function($message) use (&$friend_request){
$message->to($friend_request->notifiable->email, $friend_request->notifiable->name)->from('info@example.com','ABC')->subject('New Friend Request');
});
我渴望在$friend_request
對象上加載所有關系。
例如:-
$friend_request = FriendRequest::with('notifiable')->find($request_id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.