Example #1
0
 /**
  * @covers \Qutee\Queue::getTasks
  */
 public function testGettingTasksQueriesGivenPriority()
 {
     $task1 = new Task('task1');
     $task1->setPriority(Task::PRIORITY_HIGH);
     $task2 = new Task('task2');
     $task2->setPriority(Task::PRIORITY_LOW);
     $this->object->addTask($task1)->addTask($task2);
     $outputTasks = $this->object->getTasks(Task::PRIORITY_LOW);
     $this->assertTrue(count($outputTasks) == 1);
     $outputTask = reset($outputTasks);
     $this->assertEquals($outputTask->getName(), $task2->getName());
 }
Example #2
0
 */
$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;
    }
}