/** * @test */ public function it_sends_remove_file_command_to_file_remover_via_php_resque() { $this->assertTrue(file_exists($this->testFile)); $commandBus = new CommandBus(); $commandRouter = new CommandRouter(); $messageDispatcher = new MessageDispatcher(['track_job_status' => true, 'queue' => 'php-resque-test-queue']); $commandRouter->route('Prooph\\ServiceBusTest\\Mock\\RemoveFileCommand')->to($messageDispatcher); $commandBus->utilize($commandRouter); $commandBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator())); $jobId = null; $messageDispatcher->events()->attach('dispatch.post', function (EventInterface $e) use(&$jobId) { $jobId = $e->getParam('jobId'); }); $removeFile = RemoveFileCommand::fromPayload($this->testFile); $commandBus->dispatch($removeFile); $this->assertNotNull($jobId); $status = new \Resque_Job_Status($jobId); $this->assertEquals(\Resque_Job_Status::STATUS_WAITING, $status->get()); $worker = new \Resque_Worker(array('php-resque-test-queue')); $worker->logLevel = 1; $worker->work(0); $worker->shutdown(); $this->assertEquals(\Resque_Job_Status::STATUS_COMPLETE, $status->get()); $this->assertFalse(file_exists($this->testFile)); }
/** * Schedule a worker for shutdown. Will finish processing the current job * and when the timeout interval is reached, the worker will shut down. */ public function shutdown() { parent::shutdown(); $this->getEventManager()->trigger('Zf2Resque.shutdown', null, array()); }