Exemple #1
0
 /**
  * Construct the API class
  */
 public function __construct()
 {
     $this->ResqueStatus = new \ResqueStatus\ResqueStatus(\ResqueBoard\Lib\Service\Service::Redis());
 }
 /**
  * Create Mongo Collection index
  *
  * @since 1.1.0
  * @return void
  */
 private function setupIndexes()
 {
     Service::Mongo()->selectCollection(Service::$settings['Mongo']['database'], 'got_events')->ensureIndex('d.args.queue');
     Service::Mongo()->selectCollection(Service::$settings['Mongo']['database'], 'got_events')->ensureIndex('d.args.payload.class');
     Service::Mongo()->selectCollection(Service::$settings['Mongo']['database'], 'got_events')->ensureIndex('d.worker');
     Service::Mongo()->selectCollection(Service::$settings['Mongo']['database'], 'fail_events')->ensureIndex('d.job_id');
     Service::Mongo()->selectCollection(Service::$settings['Mongo']['database'], 'done_events')->ensureIndex('d.job_id');
     Service::Mongo()->selectCollection(Service::$settings['Mongo']['database'], 'shutdown_events')->ensureIndex('d.worker');
     Service::Mongo()->selectCollection(Service::$settings['Mongo']['database'], 'start_events')->ensureIndex('d.worker');
 }
 /**
  * Return an array of scheduled jobs
  *
  * @param string $start timestamp
  * @param string $end   timestamp
  *
  * @return array array of jobs
  */
 public function getJobs($start = 0, $end = null)
 {
     if ($end === null) {
         $end = (int) Service::Redis()->zcard(\ResqueScheduler\ResqueScheduler::QUEUE_NAME);
     }
     $timestamps = Service::Redis()->zrangebyscore(\ResqueScheduler\ResqueScheduler::QUEUE_NAME, $start, $end);
     if (empty($timestamps)) {
         return array();
     }
     $pipelineCommands = array();
     foreach ($timestamps as $key) {
         $pipelineCommands[] = array('llen', \ResqueScheduler\ResqueScheduler::QUEUE_NAME . ':' . $key);
     }
     $timestampLength = Service::Redis()->pipeline($pipelineCommands, \Redis::PIPELINE);
     $i = 0;
     $pipelineCommands = array();
     foreach ($timestamps as $key) {
         $pipelineCommands[] = array('lrange', array(\ResqueScheduler\ResqueScheduler::QUEUE_NAME . ':' . $key, 0, (int) $timestampLength[$i++]));
     }
     $jobs = Service::Redis()->pipeline($pipelineCommands, \Redis::PIPELINE);
     $results = array();
     $i = 0;
     foreach ($jobs as &$job) {
         foreach ($job as &$j) {
             $j = json_decode($j, true);
             $j['job_id'] = $j['args'][0]['id'];
             unset($j['args'][0]['id']);
             $j['args'] = var_export($j['args'][0], true);
             $j['time'] = date('c', $timestamps[$i]);
             $j['status'] = self::JOB_STATUS_SCHEDULED;
             $results[] = $j;
         }
         $i++;
     }
     return $results;
 }
set_time_limit(0);
require "../src/ResqueBoard/Config/Bootstrap.php";
use ResqueBoard\Lib\Service\Service;
$timezone = new \DateTimeZone(date_default_timezone_get());
$offset = $timezone->getOffset(new \DateTime("now", new \DateTimeZone("UTC")));
$offsetHours = round(abs($offset) / 3600);
$offsetMinutes = round((abs($offset) - $offsetHours * 3600) / 60);
$offsetString = ($offset < 0 ? '-' : '+') . ($offsetHours < 10 ? '0' : '') . $offsetHours . ':' . ($offsetMinutes < 10 ? '0' : '') . $offsetMinutes;
if ($offsetHours == 0) {
    echo "All your dates does not need the timezone fix\n";
    die;
}
$events = array('check', 'kill', 'done', 'fail', 'fork', 'found', 'got', 'kill', 'pause', 'process', 'prune', 'reconnect', 'resume', 'shutdown', 'signal', 'sleep', 'start');
$start = microtime(true);
foreach ($events as $eventName) {
    $collection = Service::Mongo()->selectCollection(Service::$settings['Mongo']['database'], $eventName . '_events');
    $count = $collection->count();
    echo "\nFound " . $count . " results for events : " . strtoupper($eventName) . " \n";
    echo "Start updating all " . $eventName . " dates to " . date_default_timezone_get() . " timezone\n";
    echo "--- \n";
    $cursor = $collection->find(array(), array('t' => true));
    $i = 0;
    foreach ($cursor as $data) {
        $date = new \DateTime("@" . $data['t']->sec, new \DateTimeZone("UTC"));
        $usec = "" . $data['t']->usec;
        if (count($usec) < 6) {
            $usec = str_pad($usec, 7 - count($usec), "0", STR_PAD_LEFT);
        }
        $oldDate = $date->format('Y-m-d\\TH:i:s.') . $usec . "+00:00";
        $newDate = new \DateTime($date->format('Y-m-d\\TH:i:s.') . $usec . $offsetString);
        echo $i . ") " . $oldDate . " -> " . $newDate->format('Y-m-d\\TH:i:s.uO') . "\n";