/** * Executes index action * * @param sfRequest $request A request object public function executeIndex(sfWebRequest $request) { $this->forward('default', 'module'); } */ public function executeList(sfWebRequest $request) { $requestTasks_query = EtvaAsynchronousJobQuery::create(); // use query for filter if ($query_str = $request->getParameter('query')) { $query = (array) json_decode($query_str); foreach ($query as $oEl) { $el = (array) $oEl; $field = $el['field']; $value = $el['value']; //error_log("field=$field value=$value min=".$el['min']." max=".$el['max']); $column = EtvaAsynchronousJobPeer::translateFieldName(sfInflector::camelize($field), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); if (isset($el['min']) && isset($el['max'])) { // betwee min and max $requestTasks_query->addUsingAlias($column, $el['min'], Criteria::GREATER_EQUAL); $requestTasks_query->addUsingAlias($column, $el['max'], Criteria::LESS_EQUAL); } else { if (isset($el['min'])) { // great or equal $requestTasks_query->addUsingAlias($column, $el['min'], Criteria::GREATER_EQUAL); } else { if (isset($el['max'])) { // less or equal $requestTasks_query->addUsingAlias($column, $el['max'], Criteria::LESS_EQUAL); } else { if (isset($el['in'])) { // in set $in_arr = (array) $el['in']; $op = $el['not'] ? Criteria::NOT_IN : Criteria::IN; $requestTasks_query->addUsingAlias($column, $in_arr, $op); } else { // equal $op = $el['not'] ? Criteria::NOT_EQUAL : Criteria::EQUAL; $requestTasks_query->addUsingAlias($column, $el['value'], $op); } } } } } } //error_log("EtvaAsynchronousJob List SQL Query = ".$requestTasks_query->toString()); // run $requestTasks = $requestTasks_query->orderByUpdatedAt('desc')->orderById('desc')->find(); $elements = array(); foreach ($requestTasks as $task) { $task_array = $task->toArray(); $res_str = $task->getResult(); $task_array['type'] = $task->getStatus() ? $task->getStatus() : EtvaAsynchronousJob::WAITING; if ($task->getStatus() == EtvaAsynchronousJob::FINISHED) { if ($res_str) { $resObj = (array) json_decode($res_str); $task_array['type'] = 'info'; if ($resObj['success']) { $task_array['type'] = 'success'; } else { $task_array['type'] = 'error'; } } } $elements[] = $task_array; } $result = array('success' => true, 'total' => count($elements), 'data' => $elements); $return = json_encode($result); if (sfConfig::get('sf_environment') == 'soap') { return $return; } $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($return); }
public function calcDepends($depends = null, $dispatcher = null) { $task = $this->getTask($dispatcher); if ($task && method_exists($task, 'dependsOnIt')) { $aJobs_query = EtvaAsynchronousJobQuery::create()->addAnd(EtvaAsynchronousJobPeer::STATUS, array(self::ABORTED, self::INVALID, self::FINISHED), Criteria::NOT_IN)->addOr(EtvaAsynchronousJobPeer::STATUS, null, Criteria::ISNULL); $depends_asyncJobs = $aJobs_query->find(); foreach ($depends_asyncJobs as $aJob) { if ($task->dependsOnIt($this, $aJob)) { if ($depends) { $depends .= ","; } $depends .= sprintf('finished(%d)', $aJob->getId()); } } return $depends; } return $depends; }
private function launch_worker_abort($arguments, $options) { if (!$this->abort_worker) { $cpid = pcntl_fork(); if (0 === $cpid) { pcntl_signal(SIGTERM, array(&$this, 'term_handler')); // init database $this->init_database($arguments, $options); $this->log("[INFO] check expired asynchronous jobs... "); $expire_asyncjob_ttl = 24 * 60 * 60; // expires after 1 day (24 * 60 * 60) // query $query_asyncJobs = EtvaAsynchronousJobQuery::create()->add(EtvaAsynchronousJobPeer::STATUS, array(EtvaAsynchronousJob::ABORTED, EtvaAsynchronousJob::INVALID, EtvaAsynchronousJob::FINISHED), Criteria::NOT_IN)->addOr(EtvaAsynchronousJobPeer::STATUS, null, Criteria::ISNULL)->addAnd(EtvaAsynchronousJobPeer::ABORT_AT, time(), Criteria::LESS_THAN)->addOr(EtvaAsynchronousJobPeer::UPDATED_AT, time() - $expire_asyncjob_ttl, Criteria::LESS_THAN)->addAnd(EtvaAsynchronousJobPeer::RUN_AT, null, Criteria::ISNULL)->addOr(EtvaAsynchronousJobPeer::RUN_AT, time(), Criteria::LESS_THAN); //$this->log("[DEBUG] abort query = ".$query_asyncJobs->toString()); // find $asyncJobs = $query_asyncJobs->find(); // treat... for ($i = 0; $i < count($asyncJobs) && $this->running; $i++) { $aJob = $asyncJobs[$i]; $this->log("[WARN] abort the task id=" . $aJob->getId()); $this->log(" task=" . $aJob->getTasknamespace() . ":" . $aJob->getTaskname()); $aJob->abort(); } if (!$this->running) { $this->log("[INFO] Worker exit normally...."); } $this->close_database($arguments, $options); exit(0); } else { $this->abort_worker = $cpid; // regist abort worker } } }