/** * @test */ public function executes() { $filelib = new FileLibrary(new MemoryStorageAdapter(), new MemoryBackendAdapter()); $this->assertFileNotExists(ROOT_TESTS . '/data/temp/ping.txt'); $strategy = new PekkisQueueExecutionStrategy($this->queue); $strategy->attachTo($filelib); $strategy->execute('\\touchMyTrallala', [6]); $this->assertFileNotExists(ROOT_TESTS . '/data/temp/ping.txt'); $processor = new Processor(new EventDispatchingQueue($strategy->getQueue(), $filelib->getEventDispatcher())); $processor->registerHandler(new FilelibMessageHandler()); $result = $processor->process(); $this->assertTrue($result); $this->assertFileExists(ROOT_TESTS . '/data/temp/ping.txt'); }
/** * @test * @group loso */ public function handlesDequeueError() { $ed = $this->prophesize(EventDispatcherInterface::class); $queue = $this->prophesize(EventDispatchingQueue::class); $e = new RuntimeException('Xoo'); $e->setContext(['tussenhofer', 'identificado']); $queue->getEventDispatcher()->willReturn($ed->reveal()); $queue->dequeue()->shouldBeCalled()->willThrow($e); $processor = new Processor($queue->reveal()); $this->assertEquals(0, $this->counter); $processor->process(function (Processor $p, RuntimeException $e) use($processor) { $this->assertSame($processor, $p); $this->assertEquals(['tussenhofer', 'identificado'], $e->getContext()); $this->counter += 1; }); $this->assertEquals(1, $this->counter); }
<?php namespace Pekkis\Queue\Example; use Pekkis\Queue\Processor\ConsoleOutputSubscriber; use Pekkis\Queue\Processor\Processor; use Pekkis\Queue\SymfonyBridge\EventDispatchingQueue; require_once __DIR__ . '/real-life-bootstrap.php'; /** @var EventDispatchingQueue $queue */ // Queue processor has it's own console output subscriber to add to our queue. $queue->addSubscriber(new ConsoleOutputSubscriber($output)); $processor = new Processor($queue); // Register our handler to handle reservation request messages $processor->registerHandler(new ReservationHandler()); // A single processor should process only n messages because PHP sometime leaks like a hamster with bladder problems. $processor->processWhile(function ($ret) { static $count = 0; $count = $count + 1; if ($count >= 1000) { return false; } if (!$ret) { sleep(2); } return true; });