예제 #1
0
 /**
  * @depends test_get_task_without_set_process_by_uniqid
  */
 public function test_task_execution_time()
 {
     $simple_task = new Task(self::JOB);
     $simple_task->set_execution_date(date('Y-m-d H:i:s', strtotime('now') + 3));
     self::$queue->add_task($simple_task);
     $task = self::$queue->get_task();
     $this->assertFalse($task);
     sleep(10);
     $task = self::$queue->get_task();
     $this->check_asserts($task, array());
     self::$task_performer1->execute_task($task);
     $this->check_asserts($task, array('status' => Task::STATUS_DONE));
     self::$queue->modify_task($task);
 }
예제 #2
0
use PhpQueue\Drivers\SqlPdoDriver;
use PhpQueue\TaskPerformer;
AutoLoader::RegisterDirectory(array('Callbacks', 'Tasks/Example'));
AutoLoader::RegisterNamespaces(array('PhpQueue' => '../src/PhpQueue'));
AutoLoader::RegisterAutoLoader();
$pdo = new \PDO("sqlite:" . __DIR__ . "/../sql/queue.sqlite", "", "", array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$pdo->query("delete from queue_tasks");
$driver = new SqlPdoDriver($pdo);
$queue = new Queue($driver);
//one task
$task = new \PhpQueue\Task("Job");
$task->set_exclusive(true)->sub_tasks()->add(new \PhpQueue\Task("Job1", 5))->add(new \PhpQueue\Task("Job1", 10))->add(new \PhpQueue\Task("Job1", 15))->add(new \PhpQueue\Task("Job1", 15))->add(new \PhpQueue\Task("Job1", 15))->add(new \PhpQueue\Task("Job1", 15))->add(new \PhpQueue\Task("Job1", 15));
$queue->add_task($task);
$task = new \PhpQueue\Task("Job");
//$task->set_priority(2);
$queue->add_task($task);
$task = new \PhpQueue\Task("Job");
//$task->set_priority(1);
$queue->add_task($task);
$task = new \PhpQueue\Task("Job");
//$task->set_priority(3);
$queue->add_task($task);
$task_performer = new \PhpQueue\TaskPerformer();
for ($i = 0; $i < 10; $i++) {
    $new_task = $queue->get_task();
    if (!$new_task) {
        break;
    }
    $new_task = $task_performer->execute_task($new_task);
    $queue->modify_task($new_task);
}