在我的應用程序中,用戶可以安排一條消息(如提醒),時間爲何時,應用程序上會顯示一個彈出窗口。爲此,我創建了一個通知,並通過WebSocket發送。Laravel - 如何刪除作業(通知)
現在,假設使用了插入錯誤的日期(或者簡單地說,想更改提醒日期),我需要在執行此操作之前訪問JOB。
我也嘗試了很多的解決方案,但沒有作品...
我的通知類是:
class RemindNote extends Notification implements ShouldQueue, ShouldBroadcast
{
use Queueable;
use InteractsWithQueue;
}
試圖處理方法上RemindNote:
public function handle($event) {
$this->delete();
}
有php artisan queue:work
激活,當我安排通知時,句柄方法從不被調用。
試圖Queue::before
上AppServiceProvider
這種方法被稱爲但是如果我叫$event->job->delete()
,該通知是始終點火 - 作業刪除。但是,例如,如果我打電話$event->job->release()
,這項工作是重新計劃的
所以,有一種方法來訪問作業有效載荷,並刪除它之前執行?
編輯
\Queue::before(function(JobProcessing $event) {
\Log::debug($event->job->isDeleted());
$event->job->delete();
});
這樣,當處理作業我laravel.log看到這一點:
[2017-07-27 16:44:35] stage.DEBUG:
[2017-07-27 16:44:36] stage.DEBUG:
而且,通知始終點火。看起來hook之前的delete()沒有效果。
編輯 這是登錄的隊列中的載荷::之前(方法$事件 - >求職>的有效載荷()):
[2017-07-27 15:00:13] stage.INFO: array (
'job' => 'Illuminate\\Queue\\[email protected]',
'data' =>
array (
'commandName' => 'Illuminate\\Notifications\\SendQueuedNotifications',
'command' => 'O:48:"Illuminate\\Notifications\\SendQueuedNotifications":6:{s:14:"' . "\0" . '*' . "\0" . 'notifiables";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:26:"App\\Repositories\\User\\User";s:2:"id";a:1:{i:0;i:29;}}s:15:"' . "\0" . '*' . "\0" . 'notification";O:28:"App\\Notifications\\RemindNote":7:{s:4:"body";s:3:"ddf";s:4:"user";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:26:"App\\Repositories\\User\\User";s:2:"id";i:29;}s:2:"id";s:36:"e160802c-e9e5-4d2c-a1e1-d63cbdceb54c";s:10:"connection";N;s:5:"queue";N;s:5:"delay";O:13:"Carbon\\Carbon":3:{s:4:"date";s:26:"2017-07-27 14:31:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:11:"Europe/Rome";}s:6:"' . "\0" . '*' . "\0" . 'job";N;}s:11:"' . "\0" . '*' . "\0" . 'channels";a:1:{i:0;s:9:"broadcast";}s:10:"connection";N;s:5:"queue";N;s:5:"delay";r:14;}',
),
)
[2017-07-27 15:00:13] stage.INFO: array (
'job' => 'Illuminate\\Broadcasting\\BroadcastEvent',
'data' =>
array (
'event' => 'O:60:"Illuminate\\Notifications\\Events\\BroadcastNotificationCreated":6:{s:10:"notifiable";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:26:"App\\Repositories\\User\\User";s:2:"id";i:29;}s:12:"notification";O:28:"App\\Notifications\\RemindNote":7:{s:4:"body";s:3:"ddf";s:4:"user";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:26:"App\\Repositories\\User\\User";s:2:"id";i:29;}s:2:"id";s:36:"e160802c-e9e5-4d2c-a1e1-d63cbdceb54c";s:10:"connection";N;s:5:"queue";N;s:5:"delay";O:13:"Carbon\\Carbon":3:{s:4:"date";s:26:"2017-07-27 14:31:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:11:"Europe/Rome";}s:6:"' . "\0" . '*' . "\0" . 'job";N;}s:4:"data";a:1:{s:4:"body";s:3:"ddf";}s:10:"connection";N;s:5:"queue";N;s:5:"delay";N;}',
),
)
您必須將其從隊列中移除。你如何做*取決於你正在使用哪個隊列引擎。 – ceejayoz
我正在使用數據庫隊列 – Mistre83
然後,您可以在數據庫中找到記錄並將其刪除。 – ceejayoz