mapper = $mapper; $this->redis = $this->container->get(Redis::class); } /** * 保存 * @param array $data * @return int */ public function save(array $data): int { $id = parent::save($data); $this->redis->del($this->prefix . 'crontab'); return $id; } /** * 更新 * @param int $id * @param array $data * @return bool */ public function update(int $id, array $data): bool { $res = parent::update($id, $data); $this->redis->del($this->prefix . 'crontab'); return $res; } /** * 删除 * @param array $ids * @return bool */ public function delete(array $ids): bool { $res = parent::delete($ids); $this->redis->del($this->prefix . 'crontab'); return $res; } /** * 立即执行一次定时任务 * @param $id * @return bool|null * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ public function run($id): ?bool { $crontab = new MineCrontab(); $model = $this->read($id); $crontab->setCallback($model->target); $crontab->setType((string) $model->type); $crontab->setEnable(true); $crontab->setCrontabId($model->id); $crontab->setName($model->name); $crontab->setParameter($model->parameter ?: ''); $crontab->setRule($model->rule); $executor = $this->container->get(MineExecutor::class); return $executor->execute($crontab, true); } }