/** * 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; }
/** * @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; }