Esempio n. 1
0
 public function job_update()
 {
     $this->set('area', 'jobs');
     try {
         //load the data and check for errors.
         $job = new SliceJob($this->args('id'));
         if (!$job->isHydrated()) {
             throw new Exception("That slice job does not exist.");
         }
         if ($job->get('user_id') != User::$me->id) {
             throw new Exception("You do not have access to view this slice job.");
         }
         if ($job->get('status') != 'pending') {
             throw new Exception("This slice job is not in a pending state.");
         }
         if ($this->args('pass')) {
             $job->pass();
         }
         if ($this->args('fail')) {
             $job->fail();
         }
         $this->forwardToUrl($job->getUrl());
     } catch (Exception $e) {
         $this->setTitle("Slice Job - Error");
         $this->set('megaerror', $e->getMessage());
     }
 }
Esempio n. 2
0
 public function grab($uid)
 {
     if ($this->get('status') == 'available') {
         $this->setStatus('slicing');
         $this->set('taken_date', date('Y-m-d H:i:s'));
         $this->set('uid', $uid);
         $this->save();
         // Begin a transaction to avoid the race condition
         db()->beginTransaction();
         $sj = new SliceJob($this->id);
         if ($sj->get('uid') != $uid) {
             db()->rollBack();
             // Nothing really to rollback
             throw new Exception("Unable to lock slice job #{$this->id}");
         }
         db()->commit();
         $bot = $this->getBot();
         $bot->setStatus(BotState::Slicing);
         $bot->save();
     }
 }
Esempio n. 3
0
 public function api_updateslicejob()
 {
     if (!$this->args('job_id')) {
         throw new Exception("You must provide the 'bot_id' parameter.");
     }
     $sj = new SliceJob($this->args('job_id'));
     if (!$sj->isHydrated()) {
         throw new Exception("Slice job does not exist.");
     }
     if ($sj->get('user_id') != User::$me->id) {
         throw new Exception("This slice job is not yours.");
     }
     //load up our objects
     $job = $sj->getJob();
     //upload our file
     $file = $_FILES['file'];
     $emptyFile = false;
     try {
         $this->ensureGoodFile($file);
     } catch (InvalidUploadedFile $ex) {
         if ($ex->getCode() == UPLOAD_ERR_EMPTY) {
             $emptyFile = true;
         } else {
             throw $ex;
         }
     }
     $data_file = Storage::newFile();
     if (!$emptyFile) {
         //okay, we're good.. do it.
         $data_file->set('user_id', User::$me->id);
         $data_file->upload($file['tmp_name'], StorageInterface::getNiceDir($file['name']));
     }
     //update our status.
     $sj->set('output_log', $this->args('output'));
     $sj->set('error_log', $this->args('errors'));
     if (!$emptyFile) {
         $sj->set('output_id', $data_file->id);
     }
     $sj->save();
     //update our job
     $job->set('slice_complete_time', date("Y-m-d H:i:s"));
     if (!$emptyFile) {
         $job->set('file_id', $data_file->id);
     }
     $job->save();
     //what do do with it now?
     if ($this->args('status') == 'complete') {
         $sj->pass();
     } else {
         if ($this->args('status') == 'failure') {
             $sj->fail();
         } else {
             if ($this->args('status') == 'pending') {
                 $sj->setStatus('pending');
                 $sj->set('finish_date', date("Y-m-d H:i:s"));
                 $sj->save();
             }
         }
     }
     Activity::log($job->getBot()->getLink() . " sliced the " . $job->getLink() . " job via the API.");
     return $job->getBot()->getAPIData();
 }