Esempio n. 1
0
 /**
  * @covers \Qutee\Queue::setPersistor
  * @covers \Qutee\Queue::getPersistor
  */
 public function testGettingAndSettingPersistor()
 {
     $persistor = $this->object->getPersistor();
     $this->assertInstanceOf('\\Qutee\\Persistor\\Memory', $persistor);
     $this->object->setPersistor(new \Qutee\Persistor\Redis());
     $persistor = $this->object->getPersistor();
     $this->assertInstanceOf('\\Qutee\\Persistor\\Redis', $persistor);
 }
Esempio n. 2
0
<?php

/*
 * php app.php
 */
$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;
        }