public function next($queueName = NULL) { $nextMJob = NULL; $this->con->beginTransaction(); try { // find "next" job $selectColumnsForPropelHydrate = join(',', call_user_func(array("{$this->propelClassName}Peer", 'getFieldNames'), BasePeer::TYPE_COLNAME)); // options is trusted w/r/t sql-injection $sql = "select\n {$selectColumnsForPropelHydrate}\n from {$this->options['tableName']}\n where\n {$this->options['jobStatusColName']} = '" . JQManagedJob::STATUS_QUEUED . "'\n AND ({$this->options['jobStartDtsColName']} IS NULL OR {$this->options['jobStartDtsColName']} < now())\n " . ($queueName ? "AND {$this->options['jobQueueNameColName']} = '" . pg_escape_string($queueName) . "'" : NULL) . "\n order by\n {$this->options['jobPriorityColName']} desc,\n coalesce(now(), {$this->options['jobStartDtsColName']}) asc,\n {$this->options['jobIdColName']} asc\n limit 1\n for update\n "; $stmt = $this->con->query($sql); if ($stmt->rowCount() === 1) { $dbJobRow = $stmt->fetch(); $dbJob = new $this->propelClassName(); $dbJob->hydrate($dbJobRow); $nextMJob = new JQManagedJob($this); $nextMJob->fromArray($dbJob->toArray(BasePeer::TYPE_STUDLYPHPNAME)); $nextMJob->markJobStarted(); } $this->con->commit(); } catch (Exception $e) { $this->con->rollback(); throw $e; } return $nextMJob; }
/** * @dataProvider failedJobDetectionDataProvider * @testdox JQManagedJob::run() will gracefully detect and fail a job that */ function testFailedJobDetection($errorGeneratorF, $exceptionMessageContains) { // setup $q = new JQStore_Array(); $mJob = new JQManagedJob($q, new SampleCallbackJob($errorGeneratorF)); $mJob->setStatus(JQManagedJob::STATUS_QUEUED); $mJob->markJobStarted(); // run $err = $mJob->run($mJob); $this->assertEquals(JQManagedJob::STATUS_FAILED, $mJob->getStatus(), "failed job not marked as failed."); $this->assertContains($exceptionMessageContains, $err, "JQManagedJob::run() failed to detect {$exceptionMessageContains}"); }