Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class TO_LocalJobDispatcher implements TO_IJobDispatcher
- {
- const START_JOB_CLI_COMMAND = 'AGAVI_ENVIRONMENT=%1$s setsid %2$s %3$s job_queue.execute --job %4$d &> /dev/null & echo $!';
- const KILL_JOB_CLI_COMMAND = 'kill %1$s';
- const ENDPOINT_NOTIFICATION_ROUTE = 'tonline.job_handler.notify';
- public function dispatchProcessRequest(TO_BaseJob $job, $action)
- {
- if ($action === TO_IJobDispatcher::ACTION_EXECUTE)
- {
- return $this->executeJob($job);
- }
- return $this->cancelJob($job);
- }
- public function dispatchEndPointNotification(TO_BaseJob $job, $event)
- {
- /**
- * Create forward container here. Don't need to call an url
- * and bootstrap from the scratch.
- */
- $url = $this->getContext()->getRouting()->gen(
- self::ENDPOINT_NOTIFICATION_ROUTE,
- array(
- $job->getId(),
- $event
- )
- );
- }
- protected function cancelJob(TO_IJob $job)
- {
- $output = array();
- $command = sprintf(
- self::KILL_JOB_CLI_COMMAND,
- $job_execution->getJobPid()
- );
- exec($command, $output);
- /*
- * @todo If output>1 we are dealing with a possible error.
- */
- return true;
- }
- protected function executeJob(TO_IJob $job)
- {
- $output = array();
- exec(
- $this->buildExecuteJobCliCommandString($job),
- $output
- );
- /*
- * @todo If output>1 we are dealing with a possible error.
- */
- return (int) $output[0];
- }
- protected function buildExecuteJobCliCommandString(TO_BaseJob $job)
- {
- $php_cli_path = AgaviConfig::get("exo_cms.cli_path");
- $agavi_cli_entry_point = dirname(
- AgaviConfig::get('core.app_dir')
- ).DIRECTORY_SEPARATOR."bin".DIRECTORY_SEPARATOR."cli.php";
- return sprintf(
- self::START_JOB_CLI_COMMAND,
- AgaviConfig::get('core.environment'),
- $php_cli_path,
- $agavi_cli_entry_point,
- $job->getId()
- );
- }
- }
- ?>
Add Comment
Please, Sign In to add comment