Example #1
0
 public function getArguments()
 {
     $args = json_encode($this->job->getArguments());
     $lockHash = $this->job->getClass() . ':' . $args;
     // Could SHA1 this or something, but it could be useful to read this value
     return array(Time::microtime(), (int) $this->lockType, $this->job->getId(), $this->job->getClass(), $args, $lockHash, Job::JOB_PENDING, $this->queueId);
 }
Example #2
0
 public function testDelayedJobIsPushedWithJobArguments()
 {
     \Phresque\Util\Time::$testing = 500;
     $this->queueMock->expects($this->once())->method('addTimedJob')->with($this->getJobExpectation(), \Phresque\Util\Time::microtime() + 10);
     $this->builder->job('TestJob')->with(array('args' => 1))->in(10)->to($this->queueMock);
     \Phresque\Util\Time::$testing = false;
 }
Example #3
0
 /**
  * Queue the job after the specified number of seconds
  *
  * @param $seconds
  * @return Builder
  */
 public function in($seconds)
 {
     if ((int) $seconds != $seconds || !$seconds > 0) {
         throw new \InvalidArgumentException('Please ensure the seconds field is a positive integer');
     }
     return $this->at((int) Time::time() + $seconds);
 }
Example #4
0
 public function getArguments()
 {
     return array($this->hostId, Time::microtime());
 }
Example #5
0
 public function isSleeping()
 {
     return Time::microtime() < $this->sleepUntil;
 }
Example #6
0
 public function getArguments()
 {
     return array($this->time ?: Time::microtime(), Job::JOB_PENDING);
 }
Example #7
0
 public function getArguments()
 {
     return array(Time::microtime(), Job::JOB_RUNNING, $this->error ? Job::JOB_FAILED : Job::JOB_SUCCEEDED, $this->error ? $this->error->getMessage() : '', (string) $this->error, $this->error ? 'failed' : 'succeeded');
 }
Example #8
0
 public function getArguments()
 {
     return array(Time::microtime(), $this->hostId, $this->startHash, $this->saveJobDataDefault);
 }
Example #9
0
 public function getArguments()
 {
     return array(Time::microtime(), $this->jobId, $this->maxObjects, $this->removeObjectsMax, Job::JOB_FAILED, Job::JOB_SUCCEEDED);
 }
Example #10
0
 public function getArguments()
 {
     return array(Time::microtime());
 }
Example #11
0
 public function search($page = 0, $limit = 200)
 {
     $end = $this->timeEnd ? $this->timeEnd->getTimestamp() : Time::microtime() + 1;
     $start = $this->timeStart ? $this->timeStart->getTimestamp() : 0;
     $args = array($start, $end, $page * $limit, $limit);
     $keys = $this->buildSearchKeys();
     if (($keysCount = count($keys)) > 1) {
         $args[] = $keysCount;
         $keysString = "ARGV[5]";
         foreach ($keys as $i => $k) {
             $keysString .= " ,KEYS[" . ($i + 2) . "]";
         }
         $command = "redis.call('zinterstore', KEYS[1], {$keysString}, 'AGGREGATE', 'MAX')" . PHP_EOL;
         array_unshift($keys, 'searchtmp:' . uniqid(getmypid() . ':', true));
     } else {
         $command = "";
         count($keys) or $keys[0] = 'index:job:all';
     }
     // zREVrangebyscore so ARG[2] ARG[1] are reversed
     $command .= "local result = redis.call('zrevrangebyscore', KEYS[1], ARGV[2], ARGV[1], 'LIMIT', ARGV[3], ARGV[4])" . PHP_EOL;
     $command .= "local count = redis.call('zcount', KEYS[1], ARGV[1], ARGV[2])" . PHP_EOL;
     if ($keysCount > 1) {
         $command .= "redis.call('del', KEYS[1])" . PHP_EOL;
     }
     $command .= 'return {count, result}';
     list($count, $list) = $this->commandExecutor->execute(new Phresque\Redis\Commands\DynamicCommand($command, $keys, $args));
     $jobs = array();
     foreach ($list as $jobID) {
         $jobs[] = $this->commandExecutor->execute(new Phresque\Redis\Commands\GetJob($jobID));
     }
     return $this->withCount ? array($jobs, $count) : $jobs;
 }
Example #12
0
 public function __construct($olderThan = null)
 {
     $this->olderThan = max($olderThan ? Time::microtime() - $olderThan : 0, 0);
 }
Example #13
0
 /**
  * @return $this
  */
 public function saveTimeSeriesData()
 {
     if (!$this->saveTimeseriesData) {
         return $this;
     }
     $time = Time::time();
     $time -= $time % self::LOG_INTERVAL_SECONDS;
     if ($time >= $this->lastLog + self::LOG_INTERVAL_SECONDS) {
         $this->lastLog = $time;
         $this->commandExecutor->execute(new SaveTimeSeriesData($time));
         // clear the data appx once every 50 times this function is called
         //rand(0, 50) or
         $this->commandExecutor->execute(new ClearTimeSeriesData($this->saveTimeseriesData));
     }
     return $this;
 }
Example #14
0
 public function getArguments()
 {
     return array(Time::microtime(), Job::JOB_RUNNING, $this->hostId);
 }
Example #15
0
 /**
  *
  */
 public function updateHostStatus()
 {
     if (Time::microtime() > $this->nextUpdateTime) {
         $this->logger->debug('Host: Memory usage: ' . memory_get_peak_usage());
         $this->logger->debug('Host: Memory usage: ' . memory_get_usage());
         $this->host->updateStatus() or $this->terminate();
         $this->pause = $this->host->isPaused();
         $this->host->isShutdown() and $this->shutdown();
         $this->host->resolveScheduledJobs();
         $this->host->resolveTimedJobs();
         $this->host->saveTimeSeriesData();
         $this->nextUpdateTime = Time::microtime() + 1;
     }
 }