/** * @return JobModel */ public function getModel() { if ($this->model instanceof JobModel) { return $this->model; } else { return $this->model = JobModel::findFirst($this->getId()); } }
/** * Finds a job given certain conditions. * @param array|string $conditions One or more SQL conditions. Each array entry will be joined with "AND". * @param array $bind Bind params, if needed. * @return null|Job */ protected function queriedPeek($conditions, array $bind = []) { $conditions = array_merge((array) $conditions, ['tube IN ({tubes:array})']); $job = JobModel::findFirst(['conditions' => implode(' AND ', $conditions), 'bind' => array_merge(['tubes' => $this->watching], $bind), 'order' => 'priority ASC, id ASC']); return $job ? new Job($this, $job) : 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; }