예제 #1
0
 public function execute() {
     $task = new Gpf_Db_Task();
     $task->setClassName('Gpf_Mail_OutboxRunner');
     $task->loadFromData(array(Gpf_Db_Table_Tasks::CLASSNAME));
     
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add(Gpf_Db_Table_MailOutbox::ID);
     $select->from->add(Gpf_Db_Table_MailOutbox::getName());
     $select->orderBy->add(Gpf_Db_Table_MailOutbox::ID);
     $select->limit->set(0,1);
     try {
     	$row = $select->getOneRow();
     	$begining = $row->get(Gpf_Db_Table_MailOutbox::ID);
     } catch (Gpf_Exception $e) {
     	$begining = 1;
     }
     
     try {
         $task->load();
         $task->setParams($begining);
         $task->setWorkingAreaFrom($begining);   
         $task->setWorkingAreaTo(Gpf_Mail_OutboxRunner::MAX_MAIL_WORKERS_COUNT);
         $task->update(array(Gpf_Db_Table_Tasks::WORKING_AREA_FROM, Gpf_Db_Table_Tasks::WORKING_AREA_TO, Gpf_Db_Table_Tasks::PARAMS));
     } catch (Gpf_Exception $e) {
         throw new Gpf_Exception('Cannot update Gpf_Mail_OutboxRunner task to paralel version');
     }
 }
 /**
  * Delete pending background task if it is allowed
  *
  * @service tasks delete
  * @param $params
  * @return Gpf_Rpc_Action
  */
 public function deleteTask(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     $dbTask = new Gpf_Db_Task();
     try {
         $dbTask->setId($action->getParam('taskid'));
         $dbTask->load();
     } catch (Gpf_Exception $e) {
         $action->addError();
         $action->setErrorMessage($this->_('Failed to delete task.'));
         return $action;
     }
     if ($dbTask->isExecuting()) {
         $action->addError();
         $action->setErrorMessage($this->_('It is not possible to delete running task.'));
         return $action;
     }
     try {
         $longTask = Gpf::newObj($dbTask->getClassName());
         if (!$longTask->canUserDeleteTask()) {
             $action->addError();
             $action->setErrorMessage($this->_('This type of task is not allowed to be deleted.'));
             return $action;
         }
     } catch (Gpf_Exception $e) {
     }
     $dbTask->delete();
     $action->addOk();
     $action->setInfoMessage($this->_('Task deleted.'));
     return $action;
 }
예제 #3
0
 /**
  * @return Gpf_Db_Task
  */
 private function getMaxFreeWorker()
 {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->addAll(Gpf_Db_Table_Tasks::getInstance());
     $select->from->add(Gpf_Db_Table_Tasks::getName());
     $select->where->add(Gpf_Db_Table_Tasks::CLASSNAME, '=', $this->getClassName());
     $select->where->add(Gpf_Db_Table_Tasks::DATEFINISHED, '=', null);
     $select->orderBy->add(Gpf_Db_Table_Tasks::WORKING_AREA_TO . '-' . Gpf_Db_Table_Tasks::WORKING_AREA_FROM, false);
     $select->limit->set(0, 1);
     $workerId = $select->getOneRow()->get(Gpf_Db_Table_Tasks::ID);
     $task = new Gpf_Db_Task();
     $task->setId($workerId);
     $task->load();
     return $task;
 }