/** * @covers \Qutee\Worker::run * @covers \Qutee\Worker::_runTask * @expectedException \InvalidArgumentException */ public function testCallingRunThrowsExceptionIfTaskCanNotRun() { $priority = Task::PRIORITY_LOW; $task = $this->getMock('\\Qutee\\Task', array('getClassName')); $task->expects($this->once())->method('getClassName')->will($this->returnValue('UnknownClass')); $queue = $this->getMock('\\Qutee\\Queue', array('getTask')); $queue->expects($this->once())->method('getTask')->with($priority)->will($this->returnValue($task)); $this->object->setPriority($priority); $this->object->run(); }
*/ $loader = (require_once __DIR__ . "/../vendor/autoload.php"); $loader->add('Acme', __DIR__); use Qutee\Queue; use Qutee\Task; use Qutee\Worker; // Setup our queue with persistor of choice, preferably in // Dependency Injection Container $redisParams = array('host' => '127.0.0.1', 'port' => 6379); $queuePersistor = new Qutee\Persistor\Redis($redisParams); $queue = new Queue(); $queue->setPersistor($queuePersistor); // Create a task $task = new Task(); $task->setName('Acme/SendMail')->setData(array('to' => '*****@*****.**', 'from' => '*****@*****.**', 'subject' => 'Hi!', 'text' => 'It\'s your faithful QuTee!'))->setPriority(Task::PRIORITY_HIGH)->setUniqueId('*****@*****.**'); // Queue it $queue->addTask($task); // Or do this in one go, if you set the queue (bootstrap maybe?) Task::create('Acme/SendMail', array('to' => '*****@*****.**', 'from' => '*****@*****.**', 'subject' => 'Hi!', 'text' => 'It\'s your faithful QuTee!'), Task::PRIORITY_HIGH); // Send worker to do it $worker = new Worker(); $worker->setQueue($queue)->setPriority(Task::PRIORITY_HIGH); while (true) { try { if (null !== ($task = $worker->run())) { echo 'Ran task: ' . $task->getName() . PHP_EOL; } } catch (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; } }