/** * Test resetiranja joba * @depends testRunJob * @param \UnitTester $I */ public function testResetJob(\UnitTester $I) { $job = $this->job; $this->jm->resetJob($job); $I->assertEquals(0, $job->getStatus()); $I->assertEquals(0, count($job->getReports())); $I->assertEquals(0, strlen($job->getLog())); $I->assertEmpty($job->getAlert()); }
public function testGetJobStatistics() { $stat = $this->object->getJobStatistics($this->job); $this->assertInternalType('array', $stat); $this->assertNotEmpty($stat); $this->assertEquals('Time', $stat[0][0]); $this->assertEquals('memory', $stat[0][1]); $this->assertInternalType('float', $stat[1][1]); $this->assertEquals(780, (int) $stat[1][1]); }
public static function _init() { if (self::$initialized) { return; } foreach (glob(__DIR__ . '/JobHandlers/*.php') as $file) { $class = "JobHandlers\\" . basename($file, ".php"); self::addHandler($class); } self::$initialized = true; }
/** * Enqueues a batch of similar jobs * * @param string $worker Worker class to enqueue (In CakePHP format) * @param array $jobsToEnqueue Array of jobs to enqueue. Can either be a simple array for the payload, or contain two keys (_payload, and _options) * @param array $options Default options for all jobs. Can be overridden with the `_options` key * @return array */ public function enqueueBatch($worker, array $jobsToEnqueue, array $options = []) { $jobs = []; foreach ($jobsToEnqueue as $jobInfo) { $jobPayload = $jobInfo; $jobOptions = $options; if (isset($jobInfo['_payload'])) { $jobPayload = $jobInfo['_payload']; } if (isset($jobInfo['_options'])) { $jobOptions = $jobInfo['_options'] + $options; } $job = new Job(); $job->setWorker($worker)->setPayload($jobPayload)->setData($jobOptions); $jobs[] = $job; } return JobManager::instance()->enqueueBatch($jobs); }
public function addJob() { try { $data = $this->getJsonRequest(); if (!$data) { return $this->serverError(); } $job_id = $this->manager->addJob($data); return $job_id; } catch (NotFoundEntityException $ex1) { SS_Log::log($ex1, SS_Log::WARN); return $this->notFound($ex1->getMessage()); } catch (EntityValidationException $ex2) { SS_Log::log($ex2, SS_Log::WARN); return $this->validationError($ex2->getMessages()); } catch (Exception $ex) { SS_Log::log($ex, SS_Log::ERR); return $this->serverError(); } }