Beispiel #1
0
 public function testRunCronJob()
 {
     $jobs = array(array('CommandExample', array('command' => 'ls', 'schedule' => '0 * * * *', 'output' => 'logs/command.log', 'enabled' => true)), array('ClosureExample', array('command' => function () {
         echo "I'm a function!\n";
         return true;
     }, 'schedule' => '* * * * *', 'output' => 'logs/closure.log', 'enabled' => true)));
     $loadBalancer = $this->getMockBuilder('Havlicek\\JobbyRabbitMq\\LoadBalancer')->disableOriginalConstructor()->getMock();
     $loadBalancer->expects($this->once())->method('connect');
     $loadBalancer->expects($this->at(1))->method('run')->with($this->equalTo($jobs[0][0]), $this->equalTo($jobs[0][1]));
     $loadBalancer->expects($this->at(2))->method('run')->with($this->equalTo($jobs[1][0]), $this->equalTo($jobs[1][1]));
     $loadBalancer->expects($this->once())->method('disconnect');
     $jobby = new Jobby($loadBalancer);
     $jobby->add($jobs[0][0], $jobs[0][1]);
     $jobby->add($jobs[1][0], $jobs[1][1]);
     $jobby->run();
 }
Beispiel #2
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Havlicek\JobbyRabbitMq\Jobby;
use Havlicek\JobbyRabbitMq\LoadBalancer;
// Run command "vagrant up" first
$jobby = new Jobby(new LoadBalancer('192.168.33.10', 5672));
// Every job has a name
$jobby->add('CommandExample', array('command' => 'ls', 'schedule' => '* * * * *', 'output' => 'logs/command.log', 'enabled' => true));
$jobby->add('ClosureExample', array('command' => function () {
    echo "I'm a function!\n";
    return true;
}, 'schedule' => '* * * * *', 'output' => 'logs/closure.log', 'enabled' => true, 'debug' => true));
$jobby->run();