Ejemplo n.º 1
0
 private static function getQueue(Criteria $c, $schedulerId, $workerId, $max_exe_attempts)
 {
     $schd = BatchJobLockPeer::SCHEDULER_ID;
     $work = BatchJobLockPeer::WORKER_ID;
     $stat = BatchJobLockPeer::STATUS;
     $atmp = BatchJobLockPeer::EXECUTION_ATTEMPTS;
     $expr = BatchJobLockPeer::EXPIRATION;
     $recheck = BatchJobLockPeer::START_AT;
     $schd_id = $schedulerId;
     $work_id = $workerId;
     $now = time();
     $now_str = date('Y-m-d H:i:s', $now);
     // same workers unfinished jobs
     $query1 = "(\n\t\t\t\t\t\t\t{$schd} = {$schd_id}\n\t\t\t\t\t\tAND {$work} = {$work_id}\n\t\t\t\t\t\tAND {$stat} IN (" . BatchJobPeer::getInProcStatusList() . ")\n\t\t\t\t\t)";
     //	"others unfinished jobs " - the expiration should be SMALLER than the current time to make sure the job is not
     // being processed
     $unclosedStatuses = BatchJobPeer::getUnClosedStatusList();
     $unclosedStatuses = implode(',', $unclosedStatuses);
     $query2 = "(\n\t\t\t\t\t\t\t{$stat} IN ({$unclosedStatuses})\n\t\t\t\t\t\tAND\t{$expr} <= '{$now_str}'\n\t\t\t\t\t)";
     // "retry jobs"
     $query3 = "(\n\t\t\t\t\t\t{$stat} IN (" . BatchJob::BATCHJOB_STATUS_RETRY . ", " . BatchJob::BATCHJOB_STATUS_ALMOST_DONE . ")\n\t\t\t\t\t\tAND {$recheck} <= '{$now_str}'\n\t\t\t\t\t)";
     // "max attempts jobs"
     $queryMaxAttempts = "(\n\t\t\t\t\t\t\t\t{$atmp} <= {$max_exe_attempts}\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t{$atmp} IS NULL\n\t\t\t\t\t\t\t)";
     $crit1 = $c->getNewCriterion($stat, BatchJob::BATCHJOB_STATUS_PENDING);
     if ($schedulerId && $workerId) {
         $crit1->addOr($c->getNewCriterion($schd, $query1, Criteria::CUSTOM));
     }
     $crit1->addOr($c->getNewCriterion($schd, $query2, Criteria::CUSTOM));
     $crit1->addOr($c->getNewCriterion($schd, $query3, Criteria::CUSTOM));
     $c->addAnd($crit1);
     $c->addAnd($c->getNewCriterion($atmp, $queryMaxAttempts, Criteria::CUSTOM));
     $c->addAnd($c->getNewCriterion(BatchJobLockPeer::DC, kDataCenterMgr::getCurrentDcId()));
     return BatchJobLockPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
 }
Ejemplo n.º 2
0
 /**
  * will return $max_count of objects using the peer.
  * The criteria will be used to filter the basic parameter, the function will encapsulate the inner logic of the BatchJob
  * and the exclusiveness.
  *
  * @param Criteria $c
  */
 private static function getExclusive(Criteria $c, kExclusiveLockKey $lockKey, $max_execution_time, $number_of_objects, $max_exe_attempts)
 {
     $schd = BatchJobPeer::SCHEDULER_ID;
     $work = BatchJobPeer::WORKER_ID;
     $btch = BatchJobPeer::BATCH_INDEX;
     $stat = BatchJobPeer::STATUS;
     $atmp = BatchJobPeer::EXECUTION_ATTEMPTS;
     $expr = BatchJobPeer::PROCESSOR_EXPIRATION;
     $recheck = BatchJobPeer::CHECK_AGAIN_TIMEOUT;
     $schd_id = $lockKey->getSchedulerId();
     $work_id = $lockKey->getWorkerId();
     $btch_id = $lockKey->getBatchIndex();
     $now = time();
     $now_str = date('Y-m-d H:i:s', $now);
     $unClosedStatuses = implode(',', BatchJobPeer::getUnClosedStatusList());
     $inProgressStatuses = BatchJobPeer::getInProcStatusList();
     $query = "\t\r\n\t\t\t\t\t\t{$stat} IN ({$unClosedStatuses})\r\n\t\t\t\t\tAND\t(\r\n\t\t\t\t\t\t\t{$expr} <= '{$now_str}'\r\n\t\t\t\t\t\tOR\t(\r\n\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t{$stat} = " . BatchJob::BATCHJOB_STATUS_PENDING . " \r\n\t\t\t\t\t\t\t\tOR (\r\n\t\t\t\t\t\t\t\t\t\t{$stat} = " . BatchJob::BATCHJOB_STATUS_RETRY . "\r\n\t\t\t\t\t\t\t\t\tAND {$recheck} <= {$now}\r\n\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t) \r\n\t\t\t\t\t\t\tAND (\r\n\t\t\t\t\t\t\t\t\t{$schd} IS NULL\r\n\t\t\t\t\t\t\t\tAND {$work} IS NULL \r\n\t\t\t\t\t\t\t\tAND {$btch} IS NULL \r\n\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t) \r\n\t\t\t\t\t\tOR (\r\n\t\t\t\t\t\t\t\t{$schd} = {$schd_id} \r\n\t\t\t\t\t\t\tAND {$work} = {$work_id} \r\n\t\t\t\t\t\t\tAND {$btch} = {$btch_id} \r\n\t\t\t\t\t\t\tAND {$stat} IN ({$inProgressStatuses}) \r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t) \r\n\t\t\t\t\tAND (\r\n\t\t\t\t\t\t\t{$atmp} <= {$max_exe_attempts}\r\n\t\t\t\t\t\tOR\t{$atmp} IS NULL\r\n\t\t\t\t\t)";
     $c->add($stat, $query, Criteria::CUSTOM);
     $c->add(BatchJobPeer::DC, kDataCenterMgr::getCurrentDcId());
     $c->addAscendingOrderByColumn(BatchJobPeer::ID);
     $c->setLimit($number_of_objects);
     //		$objects = BatchJobPeer::doSelect ( $c );
     $objects = BatchJobPeer::doSelect($c, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
     return self::lockObjects($lockKey, $objects, $max_execution_time);
 }