diff --git a/vendors/shells/tasks/queue_execute.php b/vendors/shells/tasks/queue_execute.php new file mode 100644 index 0000000..4733f9c --- /dev/null +++ b/vendors/shells/tasks/queue_execute.php @@ -0,0 +1,97 @@ +out('CakePHP Queue Execute task.'); + $this->hr(); + if (count($this->args) < 2) { + $this->out('This will run an shell command on the Server.'); + $this->out('The task is mainly intended to serve as a kind of buffer for programm calls from a cakephp application.'); + $this->out(' '); + $this->out('Call like this:'); + $this->out(' cake queue add execute *command* *param1* *param2* ...'); + $this->out(' '); + } else { + + $data = array( + 'command' => $this->args[1], + 'params' => array_slice($this->args, 2) + ); + if ($this->QueuedTask->createJob('execute', $data)) { + $this->out('Job created'); + } else { + $this->err('Could not create Job'); + } + + } + } + + /** + * Run function. + * This function is executed, when a worker is executing a task. + * The return parameter will determine, if the task will be marked completed, or be requeued. + * + * @param array $data the array passed to QueuedTask->createJob() + * @return bool Success + */ + public function run($data) { + $command = escapeshellcmd($data['command']) . ' ' . implode(' ', $data['params']); + $this->out('Executing: ' . $command); + exec($command, $output, $status); + $this->out(' '); + $this->out($output); + return (!$status); + } +} +?> \ No newline at end of file