Heim  >  Artikel  >  Backend-Entwicklung  >  laravel 如何已经存在的删除队列任务

laravel 如何已经存在的删除队列任务

不言
不言Original
2018-05-15 11:28:495348Durchsuche

加入了一个定时任务到队列中.因为某些原因,不需要执行这个任务了.

那么请问如何从队列中删除指定的任务?

回复内容:

加入了一个定时任务到队列中.因为某些原因,不需要执行这个任务了.
那么请问如何从队列中删除指定的任务?

完整流程比較複雜且冗長,我就直接就重點講了,基本上在加入 Queue 時會進行一系列處理,那其中就會執行到這段:

CallQueuedHandler

protected function setJobInstanceIfNecessary(Job $job, $instance)
{
    // class_uses_recursive 可以取得類所使用到的 trait
    if (in_array('Illuminate\Queue\InteractsWithQueue', class_uses_recursive(get_class($instance)))) {
        // 所以假如類有 use Illuminate\Queue\InteractsWithQueue
        // 就呼叫 setJob($job)
        $instance->setJob($job);
    }
    return $instance;
}

setJob 則是 InteractsWithQueue 的方法,單純的賦值

InteractsWithQueue

public function setJob(JobContract $job)
{
    $this->job = $job;
    return $this;
}
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn