public function __construct(Interval $timeToWaitAtLeast, Interval $timeToWaitAtMost, $howToWait = 'usleep') { $this->timeToWaitAtLeast = $timeToWaitAtLeast->milliseconds(); $this->timeToWaitAtMost = $timeToWaitAtMost->milliseconds(); $this->timeToWait = $timeToWaitAtLeast->milliseconds(); $this->howToWait = $howToWait; }
public function pickFrom(GetOpt\GetOpt $optionsFromCommandLine) { if ($option = $optionsFromCommandLine->getOption($this->name)) { return T\Interval::parse($option); } return $this->default; }
public function setUp() { $this->clock = T\clock()->stop(); $this->now = $this->clock->now(); $this->jobRepository = $this->getMockBuilder('Recruiter\\Job\\Repository')->disableOriginalConstructor()->getMock(); $this->mongoLock = $this->getMock('Onebip\\Concurrency\\Lock'); $this->cleaner = new Cleaner($this->jobRepository, $this->mongoLock); $this->interval = Interval::parse('10s'); }
private function validate($argument) { if (!is_null($argument)) { try { return T\Interval::parse($argument); } catch (T\InvalidIntervalFormat $e) { throw new UnexpectedValueException(sprintf("Option '%s' has an invalid value: %s", $this->name, $e->getMessage())); } } return $this->timeToWaitAtMost; }
public function scheduleIn(Interval $in) { $this->scheduleAt($in->fromNow()); }
/** * @expectedException Timeless\InvalidIntervalFormat */ public function testBadString() { Interval::parse('whatever'); }
/** * @return integer seconds */ private function leaseTimeOfLock(Interval $maximumBackoff) { return round($maximumBackoff->seconds() * self::LOCK_FACTOR); }
public function scheduleIn(Interval $duration) { return $this->scheduleAt($duration->fromNow()); }
public function before(Interval $d) { return new self($this->ms - $d->ms()); }
public static function retireDeadWorkers(Repository $roster, Clock $clock, Interval $consideredDeadAfter) { $now = $clock->current(); $consideredDeadAt = clone $now; $consideredDeadAt->sub($consideredDeadAfter->toDateInterval()); $deadWorkers = $roster->deadWorkers($consideredDeadAt); $jobsToReassign = []; foreach ($deadWorkers as $deadWorker) { $roster->retireWorkerWithId($deadWorker['_id']); if (array_key_exists('assigned_to', $deadWorker)) { if (array_key_exists((string) $deadWorker['_id'], $deadWorker['assigned_to'])) { $jobsToReassign[] = $deadWorker['assigned_to'][(string) $deadWorker['_id']]; } } } return $jobsToReassign; }