/**
  * 创建任务并写入队列
  *
  * @param string $tube
  * @param mixed  $data
  * @param array $options
  * @return bool
  */
 public function putInTube($tube, $data, $options = array())
 {
     $invoker = new Invoker($tube, $data);
     if (array_key_exists('delay', $options)) {
         $invoker->delay($options['delay']);
     }
     if (array_key_exists('timing', $options)) {
         $invoker->timing($options['timing']);
     }
     if (array_key_exists('periodic', $options)) {
         $invoker->periodic($options['periodic']);
     }
     if (array_key_exists('attempts', $options)) {
         $invoker->attempts($options['attempts']);
     }
     return $invoker->save();
 }
 /**
  * 激活到期的延时任务
  *
  * @param string $keyChip
  * @param int $timePort
  */
 private function expireActivate($keyChip, $timePort)
 {
     $page = 1000;
     $key = $keyChip . Job::STATE_DELAYED;
     $count = $this->client->zCount($key, '-inf', $timePort);
     $batchNum = ceil($count / $page);
     for ($i = 0; $i < $batchNum; $i++) {
         $ret = $this->client->zRevRangeByScore($key, $timePort, '-inf', array('limit' => array($i * $page, $page)));
         if (is_array($ret)) {
             foreach ($ret as $id) {
                 $job = Invoker::reload($id);
                 if (!$job) {
                     continue;
                 }
                 $job->state(Job::STATE_READY);
             }
         }
     }
 }