Ejemplo n.º 1
0
function run($worker, $data)
{
    //读取定时任务
    $currentTime = time();
    $data = Redis::queueRedis()->lPop('tarth-timer-' . $worker->tarthTimerLastTime);
    if ($data == false) {
        //在不超过当前时间情况下,获取下一秒的数据
        if ($worker->tarthTimerLastTime < $currentTime) {
            $worker->tarthTimerLastTime++;
        }
        return false;
    }
    $task = AbstractTask::createTask(json_decode($data, true));
    return $task->push(true);
}
Ejemplo n.º 2
0
 public function push($toQueue = false)
 {
     try {
         if ($toQueue == false) {
             $runTimeInFuture = $this->_runAtFuture();
         } else {
             $runTimeInFuture = false;
         }
         if ($runTimeInFuture) {
             if (Redis::queueRedis()->rPush('tarth-timer-' . $runTimeInFuture, (string) $this)) {
                 return $this->id;
             }
         } else {
             if (Redis::queueRedis()->rPush('tarth-queue-' . $this->priority, (string) $this)) {
                 return $this->id;
             }
         }
     } catch (Exception $e) {
         Log::logger()->addError($e->getMessage);
     }
     return false;
 }