コード例 #1
0
ファイル: timer.php プロジェクト: pythias/Tarth
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);
}
コード例 #2
0
ファイル: AbstractTask.php プロジェクト: asfan/Tarth
 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;
 }