Пример #1
0
 public function edit()
 {
     $this->assertLoggedIn();
     $this->set('area', 'queues');
     try {
         //how do we find them?
         $queue = new Queue($this->args('id'));
         //did we really get someone?
         if (!$queue->isHydrated()) {
             throw new Exception("Could not find that queue.");
         }
         if (!$queue->isMine()) {
             throw new Exception("You do not own this queue.");
         }
         $this->set('queue', $queue);
         $this->setTitle('Edit Queue - ' . $queue->getName());
         //load up our form.
         $form = $this->_createQueueForm($queue);
         $form->action = $queue->getUrl() . "/edit";
         //handle our form
         if ($form->checkSubmitAndValidate($this->args())) {
             $queue->set('name', $this->args('name'));
             $queue->set('delay', $this->args('delay'));
             $queue->save();
             Activity::log("edited the queue " . $queue->getLink() . ".");
             $this->forwardToUrl($queue->getUrl());
         }
         $this->set('form', $form);
     } catch (Exception $e) {
         $this->setTitle('Edit Queue - Error');
         $this->set('megaerror', $e->getMessage());
     }
 }
Пример #2
0
 public function listjobs()
 {
     $this->assertLoggedIn();
     try {
         //did we get a queue?
         $queue = new Queue($this->args('id'));
         if (!$queue->isHydrated()) {
             throw new Exception("Could not find that queue.");
         }
         if (!$queue->isMine()) {
             throw new Exception("You do not have permission to view this queue.");
         }
         $this->set('queue', $queue);
         //what sort of jobs to view?
         $status = $this->args('status');
         if ($status == 'available') {
             $this->setTitle($queue->getName() . "'s Available Jobs");
             $collection = $queue->getJobs($status);
         } else {
             if ($status == 'taken') {
                 $this->setTitle($queue->getName() . "'s Working Jobs");
                 $collection = $queue->getJobs($status);
             } else {
                 if ($status == 'complete') {
                     $this->setTitle($queue->getName() . "'s Finished Jobs");
                     $collection = $queue->getJobs($status);
                 } else {
                     if ($status == 'failure') {
                         $this->setTitle($queue->getName() . "'s Failed Jobs");
                         $collection = $queue->getJobs($status);
                     } else {
                         if ($status == 'all') {
                             $this->setTitle($queue->getName() . "'s Jobs");
                             $collection = $queue->getJobs(null);
                         } else {
                             throw new Exception("That is not a valid status!");
                         }
                     }
                 }
             }
         }
         $per_page = 20;
         $page = $collection->putWithinBounds($this->args('page'), $per_page);
         $this->set('per_page', $per_page);
         $this->set('total', $collection->count());
         $this->set('page', $page);
         $this->set('jobs', $collection->getPage($page, $per_page));
         $this->set('status', $status);
     } catch (Exception $e) {
         $this->setTitle('View Queue - Error');
         $this->set('megaerror', $e->getMessage());
     }
 }
Пример #3
0
 /**
  * @param $file StorageInterface
  * @param $quantity mixed
  * @param $queue_id mixed
  * @param $priority mixed
  * @return array
  * @throws Exception
  */
 private function _createJobsFromFile($file, $quantity, $queue_id, $priority)
 {
     //pull in our quantity
     $quantity = (int) $quantity;
     $quantity = max(1, $quantity);
     $quantity = min(1000, $quantity);
     //queue error checking.
     $queue = new Queue($queue_id);
     if (!$queue->isHydrated()) {
         throw new Exception("That queue does not exist.");
     }
     if (!$queue->isMine()) {
         throw new Exception("You do not have permission to add to that queue.");
     }
     //okay, we good?
     $jobs = $queue->addFile($file, $quantity);
     //priority or not?
     if ($priority) {
         if (!empty($jobs)) {
             foreach ($jobs as $job) {
                 /* @var $job Job */
                 $job->pushToTop();
             }
         }
     }
     return $jobs;
 }