/** * Execute the task * * @param array $taskData Task data * * @return bool True on success, false otherwise * * @throws Exception */ public function run($taskData) { $jobs = NenoJob::load(array('_order' => array('created_time' => 'ASC'), '_limit' => 1)); // If it's not an array, let's convert to that if (!is_array($jobs)) { $jobs = array($jobs); } /* @var $job NenoJob */ foreach ($jobs as $job) { $job->sendJob(); } }
/** * Fetch job file from server * * @return void */ public function fetch() { $app = JFactory::getApplication(); $input = $app->input; $jobId = $input->getInt('jobId'); /* @var $job NenoJob */ $job = NenoJob::load($jobId, false, true); if ($job->fetchJobFromServer() === true) { if ($job->processJobFinished() === true) { $job->setState(NenoJob::JOB_STATE_PROCESSED)->persist(); $app->enqueueMessage('Job #' . $job->getId() . ' has been successfully processed.'); } else { $app->enqueueMessage('There as an error reading the content of the file.', 'error'); } } else { $app->enqueueMessage('There was an error fetching the file from the API server', 'error'); } $app->redirect('index.php?option=com_neno&view=jobs'); }
/** * Execute the task * * @param array|null $taskData Task data * * @return bool True on success, false otherwise */ public function run($taskData) { $jobs = NenoJob::load(array('state' => NenoJob::JOB_STATE_COMPLETED)); // If there is only one job, let's transform it to an array if (!is_array($jobs)) { $jobs = array($jobs); } /* @var $job NenoJob */ foreach ($jobs as $job) { if ($job->fetchJobFromServer() === true) { if ($job->processJobFinished() === true) { $job->setState(NenoJob::JOB_STATE_PROCESSED)->persist(); NenoLog::add('Job #' . $job->getId() . ' has been successfully processed.'); } else { NenoLog::add('There as an error reading the content of the file.', NenoLog::PRIORITY_ERROR); } } else { NenoLog::add('There was an error fetching the file from the API server', NenoLog::PRIORITY_ERROR); } } }
/** * Set a translation as ready * * @return void */ public function translationReady() { $input = $this->input; $jobId = $input->get->getString('jobId'); /* @var $job NenoJob */ $job = NenoJob::load($jobId); if ($job === null) { NenoLog::add('Job not found. Job Id:' . $jobId, NenoLog::PRIORITY_ERROR); } else { // Set the job as completed by the server but the component hasn't processed it yet. $job->setState(NenoJob::JOB_STATE_COMPLETED)->persist(); // Create task into the queue NenoTaskMonitor::addTask('job_fetcher'); echo 'ok'; } JFactory::getApplication()->close(); }
/** * Get the total amount of record * * @return int */ public function getTotal() { $result = NenoJob::load(array('_select' => array('COUNT(*) AS counter'))); return (int) $result['counter']; }