public function kick() { $payload = []; switch ($this->getState()) { case self::ST_BURIED: $payload = ['buried' => 0]; break; case self::ST_DELAYED: $payload = ['delay' => 0]; break; //FIXME: missing tests for kicking a delayed job! } return $payload ? $this->model->update($payload) : true; }
/** * Kicks back into the queue $number buried jobs (at least one). * @param int $number * @return bool|int total of actually kicked jobs, or false on failure */ public function kick($number = 1) { //from the Beanstalk tutorial: "Buried jobs are maintained in a special FIFO-queue outside of // the normal job processing lifecycle until they are kicked alive again" // so, there's no need to filter by tubes or use special order //TODO: actually, to make it perfect we would need to store the timestamp the job was buried and order by it $entries = JobModel::query()->where('buried = 1')->orderBy('id DESC')->limit($number)->execute(); $total = sizeof($entries); $updated = $entries->update(['buried' => 0]); return $updated ? $total : false; }
/** * @param null $criteria Query to run through to get a job instance. By default, gets a random job. * @return bool|Job */ public function getAJob($criteria = null) { $model = JobModel::findFirst($criteria ?: ['order' => 'RANDOM()']); return $model ? new Job(new Db(), $model) : false; }