Example #1
0
 public function aging()
 {
     $max_ticks = (int) $this->config->item('test_aging_ticks_to_priority_increase');
     $max_raising = (int) $this->config->item('test_aging_max_tests_to_raise_priority');
     $max_lifetime = (int) $this->config->item('test_queue_done_error_lifetime');
     $max_lifetime = $max_lifetime < 60 ? 60 : $max_lifetime;
     $old_test_queue = new Test_queue();
     $old_test_queue->where('status >=', 2);
     $old_test_queue->where('finish + INTERVAL ' . $max_lifetime . ' MINUTE < NOW()', NULL, TRUE);
     $old_test_queue->get();
     $old_test_queue->delete_all();
     if ($max_ticks < 10) {
         $max_ticks = 10;
     }
     if ($max_raising <= 0) {
         $max_raising = 1;
     }
     $this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;');
     $this->db->trans_start();
     $tests_queue = new Test_queue();
     $tests_queue->distinct();
     $tests_queue->select('priority');
     $tests_queue->order_by('priority', 'asc');
     $tests_queue->where('status', 0);
     $tests_queue->where('worker', NULL);
     $tests_queue->get_iterated();
     $priorities = array();
     foreach ($tests_queue as $test_queue) {
         $priorities[] = (int) $test_queue->priority;
     }
     if (count($priorities) >= 2) {
         unset($priorities[0]);
         foreach ($priorities as $priority) {
             if ($priority <= 1) {
                 continue;
             }
             $tests_with_max_ticks = new Test_queue();
             $tests_with_max_ticks->where('age >=', $max_ticks);
             $tests_with_max_ticks->where('status', 0);
             $tests_with_max_ticks->where('worker', NULL);
             $tests_with_max_ticks->where('priority', $priority);
             $tests_with_max_ticks->order_by('start', 'asc');
             $tests_with_max_ticks->limit($max_raising);
             $tests_with_max_ticks->get_iterated();
             if ($tests_with_max_ticks->exists()) {
                 foreach ($tests_with_max_ticks as $test_with_max_ticks) {
                     $test_with_max_ticks->priority = $priority - 1;
                     $test_with_max_ticks->age = 0;
                     $test_with_max_ticks->save();
                 }
                 $tests_queue_with_priority = new Test_queue();
                 $tests_queue_with_priority->where('status', 0);
                 $tests_queue_with_priority->where('worker', NULL);
                 $tests_queue_with_priority->where('priority', $priority);
                 $tests_queue_with_priority->update('age', '0', FALSE);
                 continue;
             }
             $tests_queue_with_priority = new Test_queue();
             $tests_queue_with_priority->where('status', 0);
             $tests_queue_with_priority->where('worker', NULL);
             $tests_queue_with_priority->where('priority', $priority);
             $tests_queue_with_priority->update('age', 'age + 1', FALSE);
         }
     }
     $this->db->trans_complete();
 }