/** * Execute the task * * @param array $taskData Task data * * @return bool True on success, false otherwise */ public function run($taskData) { $languages = NenoHelper::getLanguages(); $defaultLanguage = NenoSettings::get('source_language'); $profiler = new JProfiler(); foreach ($languages as $language) { if ($language->lang_code !== $defaultLanguage) { $profiler->mark('Before create job' . $language->lang_code . ' Method: Machine'); $machineJob = NenoJob::createJob($language->lang_code, NenoContentElementTranslation::MACHINE_TRANSLATION_METHOD); $profiler->mark('After create job' . $language->lang_code . ' Method: Machine'); // If there are translations for this language and for this translation method if ($machineJob !== null) { NenoLog::add(count($machineJob->getTranslations()) . ' translations have been found to translate through machine translation'); } $proJob = NenoJob::createJob($language->lang_code, NenoContentElementTranslation::PROFESSIONAL_TRANSLATION_METHOD); // If there are translations for this language and for this translation method if ($proJob !== null) { NenoLog::add(count($proJob->getTranslations()) . ' translations have been found to translate through professional translation'); } if ($machineJob !== null || $proJob !== null) { NenoTaskMonitor::addTask('job_sender'); } } } }
/** * 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; }
/** * 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(); }
/** * Execute a particular task given by parameter * * @param NenoTask|null $task Task to execute * * @return bool True on success, false otherwise */ private static function executeTask($task) { NenoLog::log('Received translation job to execute', 2); // If there are task to execute, let's run it if (!empty($task)) { $task->execute(); NenoLog::add($task->getTask() . ' task has been executed properly'); $task->remove(); return true; } return false; }