public function beforeRun(TaskInterface $task) { if ($this->canClose) { $closed = Redis::cacheRedis()->hDel('closed_tasks', $task->parentId > 0 ? $task->parentId : $task->id); if ($closed) { return TaskInterface::STATUS_CLOSED_BY_CLIENT; } } if ($this->runAt > $task->beginTime) { return TaskInterface::STATUS_NOT_READY; } return true; }
public function beforeRun(TaskInterface $task) { if (isset($this->_units[$this->unit]) == false) { $this->unit = self::UNIT_MINUTE; } $timeString = date($this->_units[$this->unit][0]) . $this->unit; $cacheKey = sprintf(self::CACHE_KEY, $task->key(), $timeString); $currentCount = Redis::cacheRedis()->incrBy($cacheKey, 1); if ($currentCount == 1) { $timeout = $this->_units[$this->unit][1]; Redis::cacheRedis()->setTimeout($cacheKey, $timeout); } if ($currentCount > $this->max) { return TaskInterface::STATUS_SKIP_BY_LIMIT; } return true; }
public function afterRun(TaskInterface $task) { Redis::cacheRedis()->delete($this->_key); }
/** * 关闭等待中的定时任务 * @param integer $taskId 任务ID * @return [type] [description] */ public static function closeTask($taskId) { return Redis::cacheRedis()->hSet('closed_tasks', $taskId, 1); }