/** * Process the job * * @param Job $job */ public function process(Job $job) { $job->active(); $job->set('worker', $this->id); try { $start = Util::now(); $this->queue->emit('process:' . $job->type, $job); // Retry when failed if ($job->state == 'failed') { throw new AttemptException("failed to attempts"); } $duration = Util::now() - $start; $job->complete(); $job->set('duration', $duration); } catch (\Exception $e) { if ($e instanceof AttemptException) { $e = null; } $this->failed($job, $e); } }