Author: Vasily Zorin (maintainer@daemon.io)
Inheritance: extends MongoId
Exemple #1
0
 /**
  * @param $cb
  * @param $type
  * @param $args
  */
 public function enqueue($cb, $type, $args, $add = [], $pushcb = null)
 {
     $ts = microtime(true);
     return $this->appInstance->jobqueue->push($type, $args, $ts, $add, function ($job) use($cb, $pushcb) {
         if ($cb !== NULL) {
             $this->callbacks[(string) MongoId::import($job->getId())] = CallbackWrapper::wrap($cb);
         }
         if ($pushcb !== null) {
             call_user_func($pushcb);
         }
     });
 }
Exemple #2
0
 public static function resultMap(&$m)
 {
     if (is_array($m)) {
         foreach ($m as &$v) {
             static::resultMap($v);
         }
     } else {
         if ($m instanceof \WakePHP\Objects\Generic) {
             $m = $m->toArray();
             static::resultMap($m);
         } elseif ($m instanceof \MongoBinData) {
             $m = base64_encode($m->bin);
         } elseif ($m instanceof \MongoId) {
             $m = (string) MongoId::import($m, true);
         } elseif ($m instanceof MongoId) {
             $m = (string) $m;
         }
     }
 }
Exemple #3
0
 /**
  * getPlainObject
  * @return \MongoId
  */
 public function getPlainObject()
 {
     return new \MongoId(parent::__toString());
 }
Exemple #4
0
 public function getJobInfo($id, $accesskey, $cb)
 {
     $id = MongoId::import($id);
     $this->getJob($accesskey !== null ? ['_id' => $id, 'accesskey' => (string) $accesskey] : ['_id' => $id], $cb);
 }
Exemple #5
0
 public function sendResult($result)
 {
     $this['status'] = $result !== false ? 's' : 'f';
     if ($this['status'] === 's') {
         $this->progress = 1;
     }
     $this['result'] = $result;
     $this->cond = ['_id' => $this->getId(), 'worker' => $this->orm->appInstance->ipcId];
     $this->save(function () {
         $id = (string) MongoId::import($this->getId());
         foreach ($this['instance'] as $i) {
             $this->orm->appInstance->redis->publish($this->orm->appInstance->config->redisprefix->value . 'jobFinished:' . MongoId::import($i), $id);
         }
     });
     $this->orm->appInstance->unlinkJob($this);
 }
Exemple #6
0
 public function condSetId($id)
 {
     if (func_num_args() === 2) {
         $k = func_get_arg(0);
         $id = func_get_arg(1);
     } else {
         $k = '_id';
     }
     $id = MongoId::import($s = $id);
     if (!$id) {
         throw new WrongCondition('condSetId: wrong value: ' . $s);
     }
     $this->cond[$k] = $id;
     return $this;
 }