public function test_release_claim()
 {
     $created_actions = array();
     $store = new ActionScheduler_wpPostStore();
     for ($i = 0; $i > -3; $i--) {
         $time = new DateTime($i . ' hours');
         $schedule = new ActionScheduler_SimpleSchedule($time);
         $action = new ActionScheduler_Action('my_hook', array($i), $schedule, 'my_group');
         $created_actions[] = $store->save_action($action);
     }
     $claim1 = $store->stake_claim();
     $store->release_claim($claim1);
     $claim2 = $store->stake_claim();
     $this->assertCount(3, $claim2->get_actions());
 }
 public function test_do_not_reset_failed_action()
 {
     $store = new ActionScheduler_wpPostStore();
     $random = md5(rand());
     $schedule = new ActionScheduler_SimpleSchedule(new DateTime('1 day ago'));
     $created_actions = array();
     for ($i = 0; $i < 5; $i++) {
         $action = new ActionScheduler_Action($random, array($random), $schedule);
         $created_actions[] = $store->save_action($action);
     }
     $claim = $store->stake_claim(10);
     foreach ($claim->get_actions() as $action_id) {
         // simulate the first action interrupted by an uncatchable fatal error
         $store->log_execution($action_id);
         break;
     }
     add_filter('action_scheduler_timeout_period', '__return_zero');
     // delete any finished job
     $cleaner = new ActionScheduler_QueueCleaner($store);
     $cleaner->reset_timeouts();
     remove_filter('action_scheduler_timeout_period', '__return_zero');
     $new_claim = $store->stake_claim(10);
     $this->assertCount(4, $new_claim->get_actions());
     add_filter('action_scheduler_failure_period', '__return_zero');
     $cleaner->mark_failures();
     remove_filter('action_scheduler_failure_period', '__return_zero');
     $failed = $store->query_actions(array('status' => ActionScheduler_Store::STATUS_FAILED));
     $this->assertEquals($created_actions[0], $failed[0]);
     $this->assertCount(1, $failed);
 }
 public function test_next_instance_of_action()
 {
     $store = new ActionScheduler_wpPostStore();
     $runner = new ActionScheduler_QueueRunner($store);
     $random = md5(rand());
     $schedule = new ActionScheduler_IntervalSchedule(new DateTime('12 hours ago'), DAY_IN_SECONDS);
     $action = new ActionScheduler_Action($random, array(), $schedule);
     $store->save_action($action);
     $runner->run();
     $claim = $store->stake_claim(10, new DateTime(DAY_IN_SECONDS - 60 . ' seconds'));
     $this->assertCount(0, $claim->get_actions());
     $claim = $store->stake_claim(10, new DateTime(DAY_IN_SECONDS . ' seconds'));
     $actions = $claim->get_actions();
     $this->assertCount(1, $actions);
     $action_id = reset($actions);
     $new_action = $store->fetch_action($action_id);
     $this->assertEquals($random, $new_action->get_hook());
     $this->assertEquals($schedule->next(new DateTime()), $new_action->get_schedule()->next(new DateTime()));
 }
コード例 #4
0
 public function test_changing_batch_count_limit()
 {
     $store = new ActionScheduler_wpPostStore();
     $runner = new ActionScheduler_QueueRunner($store);
     $random = md5(rand());
     $schedule = new ActionScheduler_SimpleSchedule(new DateTime('1 day ago'));
     for ($i = 0; $i < 30; $i++) {
         $action = new ActionScheduler_Action($random, array($random), $schedule);
         $store->save_action($action);
     }
     $claims = array();
     for ($i = 0; $i < 5; $i++) {
         $claims[] = $store->stake_claim(5);
     }
     $mock1 = new MockAction();
     add_action($random, array($mock1, 'action'));
     $actions_run = $runner->run();
     remove_action($random, array($mock1, 'action'));
     $this->assertEquals(0, $mock1->get_call_count());
     $this->assertEquals(0, $actions_run);
     add_filter('action_scheduler_max_claims', array($this, 'return_6'));
     $mock2 = new MockAction();
     add_action($random, array($mock2, 'action'));
     $actions_run = $runner->run();
     remove_action($random, array($mock2, 'action'));
     $this->assertEquals(5, $mock2->get_call_count());
     $this->assertEquals(5, $actions_run);
     remove_filter('action_scheduler_max_claims', array($this, 'return_6'));
     for ($i = 0; $i < 5; $i++) {
         // to make up for the actions we just processed
         $action = new ActionScheduler_Action($random, array($random), $schedule);
         $store->save_action($action);
     }
     $mock3 = new MockAction();
     add_action($random, array($mock3, 'action'));
     $actions_run = $runner->run();
     remove_action($random, array($mock3, 'action'));
     $this->assertEquals(0, $mock3->get_call_count());
     $this->assertEquals(0, $actions_run);
     remove_filter('action_scheduler_max_claims', array($this, 'return_6'));
 }