Exemplo n.º 1
0
 public function get_student_test_queue($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()) {
         $max_allowed_to_enqueue = (int) $this->config->item('test_maximum_enqueued_pe_student');
         if ($max_allowed_to_enqueue <= 0) {
             $max_allowed_to_enqueue = 1;
         }
         $test_status_0 = new Test();
         $test_status_0->select_func('COUNT', array('@id'), 'tests_count');
         $test_status_0->where_related('test_queue', 'id', '${parent}.id');
         $test_queue_status_0 = new Test_queue();
         $test_queue_status_0->select('*');
         $test_queue_status_0->select_subquery($test_status_0, 'tests_count');
         $test_queue_status_0->where_related($task_set);
         $test_queue_status_0->where_related($student);
         $test_queue_status_0->where('status', 0);
         $test_queue_status_0->order_by('status', 'desc');
         $test_queue_status_0->order_by('finish', 'desc');
         $test_queue_status_0->order_by('start', 'asc');
         $test_status_1 = new Test();
         $test_status_1->select_func('COUNT', array('@id'), 'tests_count');
         $test_status_1->where_related('test_queue', 'id', '${parent}.id');
         $test_queue_status_1 = new Test_queue();
         $test_queue_status_1->select('*');
         $test_queue_status_1->select_subquery($test_status_1, 'tests_count');
         $test_queue_status_1->where_related($task_set);
         $test_queue_status_1->where_related($student);
         $test_queue_status_1->where('status', 1);
         $test_queue_status_1->order_by('status', 'desc');
         $test_queue_status_1->order_by('finish', 'desc');
         $test_queue_status_1->order_by('start', 'asc');
         $test_status_2 = new Test();
         $test_status_2->select_func('COUNT', array('@id'), 'tests_count');
         $test_status_2->where_related('test_queue', 'id', '${parent}.id');
         $test_queue_status_2 = new Test_queue();
         $test_queue_status_2->select('*');
         $test_queue_status_2->select_subquery($test_status_2, 'tests_count');
         $test_queue_status_2->where_related($task_set);
         $test_queue_status_2->where_related($student);
         $test_queue_status_2->where('status', 2);
         $test_queue_status_2->order_by('status', 'desc');
         $test_queue_status_2->order_by('finish', 'desc');
         $test_queue_status_2->order_by('start', 'asc');
         $test_queue_status_2->limit($max_allowed_to_enqueue * 2);
         $test_status_3 = new Test();
         $test_status_3->select_func('COUNT', array('@id'), 'tests_count');
         $test_status_3->where_related('test_queue', 'id', '${parent}.id');
         $test_queue_status_3 = new Test_queue();
         $test_queue_status_3->select('*');
         $test_queue_status_3->select_subquery($test_status_3, 'tests_count');
         $test_queue_status_3->where_related($task_set);
         $test_queue_status_3->where_related($student);
         $test_queue_status_3->where('status', 3);
         $test_queue_status_3->order_by('status', 'desc');
         $test_queue_status_3->order_by('finish', 'desc');
         $test_queue_status_3->order_by('start', 'asc');
         $test_queue_status_3->limit($max_allowed_to_enqueue * 2);
         $test_queue_status_0->union_iterated(array($test_queue_status_1, $test_queue_status_2, $test_queue_status_3));
         $test_queue = $test_queue_status_0;
     }
     //$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.tpl', array('test_queue' => $test_queue, 'task_set' => $task_set, 'student' => $student, 'test_types' => $test_types));
 }
Exemplo 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();
 }