Example #1
0
 /**
  * Cleans up the environment after running a test.
  */
 protected function tearDown()
 {
     Edo_Event_Engine::setDefaultEngine(null);
     FileEngineHelper::revertSystem($this->engine);
     $this->engine = null;
     $this->test_config = array();
     parent::tearDown();
 }
Example #2
0
 public function testsetGet()
 {
     $e = Edo_Event_Engine::getDefaultEngine();
     $this->assertSame($e, null);
     Edo_Event_Engine::setDefaultEngine($this->engine);
     $e = Edo_Event_Engine::getDefaultEngine();
     $this->assertSame($e, $this->engine);
     Edo_Event_Engine::setDefaultEngine(null);
 }
Example #3
0
 public static function create($eventOrData, $worker_name = 'manager', Edo_Event_Engine_Abstract $engine = null, $aquire_lock = false)
 {
     if (!$engine) {
         $engine = Edo_Event_Engine::getDefaultEngine();
     }
     if (!$engine) {
         throw new Edo_Event_Engine_Exception("Unable to initiate engine");
     }
     if (is_array($eventOrData)) {
         $event = new Edo_Event($eventOrData);
     } elseif ($eventOrData instanceof Edo_Event) {
         $event = $eventOrData;
     } else {
         throw new Edo_Event_Engine_Exception("Unable to create Edo_Event object");
     }
     if ($id = $engine->create($worker_name, $event)) {
         if (!$aquire_lock) {
             $engine->unlock($event->id, $worker_name);
         }
         return $id;
     }
 }
Example #4
0
 public static function setDefaultEngine(Edo_Event_Engine_Abstract $engine = null)
 {
     self::$engine = $engine;
 }
    if (is_file($fullLockPath)) {
        $lock_time = file_get_contents($fullLockPath);
        $currentLockTime = time() - $lock_time;
        if ($currentLockTime > $fullLockWarningTime) {
            echo "Full lock of worker {$worker_name} is not released for {$currentLockTime} seconds while the warning time is {$fullLockWarningTime} seconds. Might wanna have a look wassup." . PHP_EOL;
        }
        exit;
        //file is locked....some other worker of this name already working
    } else {
        //ackuire full lock
        file_put_contents($fullLockPath, time());
    }
}
//creating engine
$engine = Edo_Event_Engine_Factory::build($config['engine']);
Edo_Event_Engine::setDefaultEngine($engine);
//start timer
$start_time = time();
$elapsed_time = 0;
do {
    try {
        $failed = false;
        //check elapsed time
        $elapsed_time = time() - $start_time;
        if ($elapsed_time > $limit_time) {
            break;
        }
        $event = $engine->getFreeEvent($pool);
        if (!$event) {
            break;
            //no event to preocess...over
Example #6
0
 public function testWrongInputCreatesExceptionCreatesDefaultEngine()
 {
     $this->setExpectedException('Edo_Event_Engine_Exception');
     Edo_Event_Engine::setDefaultEngine(null);
     $id = Edo_Event_Factory::create('moooo', 'manager', $this->engine, true);
 }