/** * Test getter/setter status */ public function testGetSetStatus() { $this->assertNull($this->getStatus()); $expectedStatus = 1; $this->assertEntity($this->jobInstance->setStatus($expectedStatus)); $this->assertEquals($expectedStatus, $this->jobInstance->getStatus()); }
public function testToString() { $startTime = new \DateTime('2013-02-01 12:34:56'); $updatedTime = new \DateTime('2013-02-03 23:45:01'); $status = BatchStatus::STOPPED; $exitStatus = ExitStatus::FAILED; $jobInstance = new JobInstance('test_connector', JobInstance::TYPE_IMPORT, 'test_job_instance'); $jobInstance->setCode('job instance code'); $endTime = new \DateTime('2013-03-04 21:43:05'); $this->jobExecution->setStartTime($startTime); $this->jobExecution->setUpdatedTime($updatedTime); $this->jobExecution->setStatus(new BatchStatus($status)); $this->jobExecution->setExitStatus(new ExitStatus($exitStatus, 'Test description')); $this->jobExecution->setJobInstance($jobInstance); $this->jobExecution->setEndTime($endTime); $timezone = $startTime->format('P'); $expectedOutput = 'startTime=2013-02-01T12:34:56' . $timezone . ', endTime=2013-03-04T21:43:05' . $timezone . ', ' . 'updatedTime=2013-02-03T23:45:01' . $timezone . ', status=5, exitStatus=[FAILED] Test description, ' . 'exitDescription=[Test description], job=[job instance code]'; $this->assertEquals($expectedOutput, (string) $this->jobExecution); }
public function api_downloadedjob() { $job = new Job($this->args('job_id')); if (!$job->isHydrated()) { throw new Exception("Job does not exist."); } $bot = $job->getBot(); if (!$bot->isHydrated()) { throw new Exception("Bot does not exist."); } if (!$bot->isMine()) { throw new Exception("This is not your bot."); } if (!$job->getQueue()->isMine()) { throw new Exception("This job is not in your queue."); } $job->setStatus('taken'); $job->set('downloaded_time', date("Y-m-d H:i:s")); $job->set('progress', 0); // clear our download progress meter. $job->save(); // This returns the new bot, but it's currently not needed $this->_markBotAsSeen($bot); return $job->getAPIData(); }
/** * @param $job Job * @param $can_slice bool * @return Job * @throws Exception */ public function grabJob($job, $can_slice = true) { $grabAttemptSQL = "\n UPDATE jobs\n SET bot_id =\n CASE\n WHEN bot_id=0\n THEN\n ?\n ELSE\n bot_id\n END\n WHERE id = ?\n "; // Attempt to grab the job unless another bot already has db()->execute($grabAttemptSQL, array($this->id, $job->id)); $job = new Job($job->id); // Reload the job if ($job->get('bot_id') != $this->id) { // We didn't grab it in time. throw new Exception("Unable to lock job #{$job->id}"); } $job->setStatus('taken'); $job->set('taken_time', date('Y-m-d H:i:s')); $job->save(); //do we need to slice this job? if (!$job->getFile()->isHydrated() && $can_slice) { //pull in our config and make sure it's legit. $config = $this->getSliceConfig(); if (!$config->isHydrated()) { $job->setStatus('available'); $job->set('bot_id', 0); $job->set('taken_time', 0); $job->save(); throw new Exception("This bot does not have a slice engine + configuration set."); } //is there an existing slice job w/ this exact file and config? $sj = SliceJob::byConfigAndSource($config->id, $job->get('source_file_id')); if ($sj->isHydrated()) { //update our job status. $job->set('slice_job_id', $sj->id); $job->set('slice_complete_time', $job->get('taken_time')); $job->set('file_id', $sj->get('output_id')); $job->save(); } else { //nope, create our slice job for processing. $sj->set('user_id', User::$me->id); $sj->set('job_id', $job->id); $sj->set('input_id', $job->get('source_file_id')); $sj->set('slice_config_id', $config->id); $sj->set('slice_config_snapshot', $config->getSnapshot()); $sj->set('add_date', date("Y-m-d H:i:s")); $sj->setStatus('available'); $sj->save(); //update our job status. $job->setStatus('slicing'); $job->set('slice_job_id', $sj->id); $job->save(); } } $log = new JobClockEntry(); $log->set('job_id', $job->id); $log->set('user_id', User::$me->id); $log->set('bot_id', $this->id); $log->set('queue_id', $job->get('queue_id')); $log->set('start_date', date("Y-m-d H:i:s")); $log->setStatus('working'); $log->save(); $this->set('job_id', $job->id); $this->setStatus(BotState::Working); $this->set('last_seen', date("Y-m-d H:i:s")); $this->save(); return $job; }
/** * @param $queue_id int * @param $file StorageInterface * @return Job */ public static function addFileToQueue($queue_id, $file) { $sortSQL = "SELECT max(id)+1 FROM jobs WHERE user_id = ?"; $sort = db()->getValue($sortSQL, array(User::$me->id)); // Special case for first sort value if ($sort == "") { $sort = 1; } $job = new Job(); $job->set('user_id', User::$me->id); $job->set('queue_id', $queue_id); $job->set('source_file_id', $file->id); if ($file->isGCode()) { $job->set('file_id', $file->id); } if ($file->isMakerbot()) { $job->set('file_id', $file->id); } $job->setName($file->get('path')); $job->setStatus('available'); $job->set('created_time', date("Y-m-d H:i:s")); $job->set('user_sort', $sort); $job->save(); return $job; }