public function handle(WriteLine $aCommand) { if (!@file_put_contents($this->file, $aCommand->getLine() . "\n", FILE_APPEND)) { throw new \RuntimeException(sprintf('Can not write new line to file %s. Access denied. Please check the permissions', $this->file)); } }
if (isset($_GET['write'])) { //We are on the write side, so the resque-sample-bus needs information of how to send a message $commandBus = new CommandBus(); $messageDispatcher = new MessageDispatcher(['track_job_status' => true, 'queue' => 'resque-sample']); $commandBus->utilize(new RegexRouter([RegexRouter::ALL => $messageDispatcher])); $commandBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator())); //The PhpResqueMessageDispatcher uses a Redis-Server to manage background jobs //We want to track the status of the job and therefor we use the event system of MessageDispatcher to capture the JobId //of a new created Job $jobId = null; //After the MessageDispatcher has done it's work, we capture the JobId with an EventListener $messageDispatcher->events()->attach('dispatch.post', function (EventInterface $e) use(&$jobId) { $jobId = $e->getParam('jobId'); }); //Prepare the Command $writeLine = WriteLine::fromPayload($_GET['write']); //...and send it to the message dispatcher via CommandBus $commandBus->dispatch($writeLine); echo 'Message is sent with JobId: ' . $jobId . '. You can check the status with ' . strtok($_SERVER["REQUEST_URI"], '?') . '<b>?status=' . $jobId . '</b>'; } elseif (isset($_GET['status'])) { $status = new \Resque_Job_Status($_GET['status']); switch ($status->get()) { case \Resque_Job_Status::STATUS_WAITING: echo 'Status: waiting. If you did not start a worker yet, than open a console, and run: <b>php ' . __DIR__ . '/start-worker.php</b>'; break; case \Resque_Job_Status::STATUS_RUNNING: echo 'Status: running. Wait a moment, the job should finish soon.'; break; case \Resque_Job_Status::STATUS_COMPLETE: echo 'Status: complete. You should see a new line with your text, when you open: <b>' . strtok($_SERVER["REQUEST_URI"], '?') . '</b>'; break;