Esempio n. 1
0
 public function get_student_test_queue_all($task_set_id, $student_id)
 {
     $task_set = new Task_set();
     $task_set->get_by_id((int) $task_set_id);
     $student = new Student();
     $student->get_by_id((int) $student_id);
     $test_queue = new Test_queue();
     if ($task_set->exists() && $student->exists()) {
         $test = new Test();
         $test->select_func('COUNT', array('@id'), 'tests_count');
         $test->where_related('test_queue', 'id', '${parent}.id');
         $test_queue->select('*');
         //$test_queue->select_func('COUNT', array('@test/id'), 'tests_count');
         $test_queue->select_subquery($test, 'tests_count');
         $test_queue->where_related($task_set);
         $test_queue->where_related($student);
         $test_queue->order_by('status', 'desc');
         $test_queue->order_by('finish', 'desc');
         $test_queue->order_by('start', 'asc');
         $test_queue->get_iterated();
     }
     //$test_queue->check_last_query();
     $this->load->helper('tests');
     $test_types = get_all_supported_test_types();
     $this->parser->parse('backend/tests/get_student_test_queue_all.tpl', array('test_queue' => $test_queue, 'task_set' => $task_set, 'student' => $student, 'test_types' => $test_types));
 }
Esempio n. 2
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();
 }