Skip to content

Commit

Permalink
Perform check sticky redis data at launch time
Browse files Browse the repository at this point in the history
  • Loading branch information
steven.chiu committed Jun 10, 2019
1 parent ce2dfd7 commit f43e461
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,32 @@ public function removeJobByScheduleKey($redis, $scheduleKey)

public function run($redis, callable $cb)
{
$this->check($redis, $cb);
$timer = $this->looper->addPeriodicTimer($this->pollingInterval, function () use (&$redis, $cb) {
$ts = time();
try {
$candidates = $redis->zRangeByScore(self::JOB_KEY, 0, $ts, array('withscores' => true));
if ($candidates) {
foreach ($candidates as $key => $candidate) {
$command = $this->removeJobByScheduleKey($redis, $key);
$cb($key, $command, 0);
}
}
if (sizeof($candidates) > 0) {
print_r($candidates);
}
} catch (\RedisException $exception) {
echo "Exception:$exception\n";
echo "Quit looper...\n";
$this->looper->stop();
}
$this->check($redis, $cb);
});

$this->looper->run();
}

private function check(&$redis, callable $cb)
{
$ts = time();
try {
$candidates = $redis->zRangeByScore(self::JOB_KEY, 0, $ts, array('withscores' => true));
if ($candidates) {
foreach ($candidates as $key => $candidate) {
$command = $this->removeJobByScheduleKey($redis, $key);
$cb($key, $command, 0);
}
}
if (sizeof($candidates) > 0) {
print_r($candidates);
}
} catch (\RedisException $exception) {
echo "Exception:$exception\n";
echo "Quit looper...\n";
$this->looper->stop();
}
}
}

0 comments on commit f43e461

Please sign in to comment.