/** * Execute the task * * @param array $taskData Task data * * @return bool True on success, false otherwise */ public function run($taskData) { $tasksNeedToBeCleanUp = NenoTask::load(array('_field' => 'numberOfAttemps', '_condition' => '>', '_value' => 3)); /* @var $taskNeedToBeCleanUp NenoTask */ foreach ($tasksNeedToBeCleanUp as $taskNeedToBeCleanUp) { NenoLog::add($taskNeedToBeCleanUp->getTask() . ' task has been deleted because reaches the maximum number of attempts allowed'); $taskNeedToBeCleanUp->remove(); } return false; }
/** * Load a task from the queue * * @return NenoTask */ protected static function fetchTask() { // Load tasks that hasn't started yet and they have less than 4 attempts $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select(array('id', 'IF(task = ' . $db->quote('language') . ', 1,0) AS ordering'))->from('#__neno_tasks')->where('time_started = ' . $db->quote('0000-00-00 00:00:00'))->order(array('ordering DESC', 'time_added ASC')); $db->setQuery($query, 0, 1); $data = $db->loadRow(); /* @var $task NenoTask */ $task = NenoTask::load($data[0]); if (empty($task)) { self::addTask('job_scanner'); self::addTask('scan', array('group' => 1)); self::addTask('discover'); $task = self::fetchTask(); } // If the task is different from discovering language, delete it and fetch a new one. if ($task->getNumberOfAttempts() > 3 && $task->getTask() != 'language') { $task->remove(); $task = self::fetchTask(); } return $task; }
/** * Load a task from the queue * * @return NenoTask */ protected static function fetchTask() { // Load tasks that hasn't started yet and they have less than 4 attempts $task = NenoTask::load(array('attemps_filter' => array('_field' => 'number_of_attempts', '_condition' => '<=', '_value' => 3), 'time_started' => '0000-00-00 00:00:00', '_order' => array('time_added' => 'ASC'), '_limit' => 1)); if (empty($task)) { self::addTask('job_scanner'); self::addTask('scan', array('group' => 1)); self::addTask('discover'); $task = self::fetchTask(); } return $task; }