Пример #1
0
 /**
  * OK here's the situation
  *
  * Our signal processing stuff is supposed to prevent jobs from being hung in a RUNNING state.
  *
  * The way this works is that essentially anytime a job is INTERRUPTED un-gracefully, we will just pretend that the job never ran.
  * Since it's marked as RUNNING in the DB, this means that we need to update the DB to show it as QUEUED (mulligan retry).
  *
  * Here's where it gets really ugly. If the signal fires after the data has been applied to the Propel instance, but before it's committed to the DB,
  * then it's possible for the software model to be differnt from the DB model in a way that makes the graceful signal handler think that the job's status
  * was successfully reported to the DB when it wasn't. 
  *
  * So the graceful signal handler needs to be sure to know what the DB thinks, and to re-queue the job if it's checked out as running.
  *
  * If propel's instance cache is hit for the job, then you risk the problem that the data from the "get job from DB" will be the not-yet-persisted status
  * which would foil the check described above from working. This test just ensures that this isn't broken.
  *
  */
 function testGracefulRetryDuringSplitBrain()
 {
     $q = $this->jqStore;
     // exit our transaction insanity since abort() inside of gracefullyRetryCurrentJob() needs to actually work
     $q->abort();
     $this->assertEquals(0, $q->count('test'), "Test database not empty; you should re-initialize the test db.");
     $mJob = $q->enqueue(new SampleFailJob());
     // mark job as running in DB to simulate a job that's running when interrupted
     $mJob->markJobStarted();
     // will save to DB
     $this->assertEquals(0, $q->count('test', JQManagedJob::STATUS_QUEUED));
     // mark job as FAILED on the PROPEL object to create split-brain (DB thinks RUNNING, MEMORY thinks FAILED)
     $dbJob = JQStoreManagedJobPeer::retrieveByPK($mJob->getJobId());
     $mJob->setStatus(JQManagedJob::STATUS_FAILED);
     $dbJob->setStatus(JQManagedJob::STATUS_FAILED);
     // attempt to gracefully retry; should mark as queued
     $w = new JQWorker($q, array('queueName' => 'test', 'exitIfNoJobs' => true, 'silent' => true, 'enableJitter' => false));
     $w->gracefullyRetryCurrentJob($mJob);
     $this->assertEquals(1, $q->count('test', JQManagedJob::STATUS_QUEUED));
     // cleanup
     $q->delete($mJob);
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(JQStoreManagedJobPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(JQStoreManagedJobPeer::DATABASE_NAME);
         $criteria->add(JQStoreManagedJobPeer::JOB_ID, $pks, Criteria::IN);
         $objs = JQStoreManagedJobPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return    JQStoreManagedJob A model object, or null if the key is not found
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT ATTEMPT_NUMBER, COALESCE_ID, CREATION_DTS, END_DTS, ERROR_MESSAGE, JOB, JOB_ID, MAX_ATTEMPTS, MAX_RUNTIME_SECONDS, PRIORITY, QUEUE_NAME, START_DTS, STATUS FROM jqstore_managed_job WHERE JOB_ID = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new JQStoreManagedJob();
         $obj->hydrate($row);
         JQStoreManagedJobPeer::addInstanceToPool($obj, (string) $row[0]);
     }
     $stmt->closeCursor();
     return $obj;
 }
Пример #4
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = JQStoreManagedJobPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setAttemptNumber($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setCoalesceId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setCreationDts($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setEndDts($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setErrorMessage($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setJob($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setJobId($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setMaxAttempts($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setMaxRuntimeSeconds($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setPriority($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setQueueName($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setStartDts($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setStatus($arr[$keys[12]]);
     }
 }