fix(job-queue): use time as key for heaps

pull/7/head
Jef Roosens 2023-04-01 17:24:25 +02:00
parent 1f4887118f
commit c7d2db4e42
1 changed files with 8 additions and 5 deletions

View File

@ -60,7 +60,8 @@ vieter_job_queue_error vieter_job_queue_insert(vieter_job_queue *queue,
}
// We assume that the initial state is not a category heap
vieter_heap_insert(queue->heaps[VIETER_JOB_INITIAL_STATE].heap, job->id, job);
vieter_heap_insert(queue->heaps[VIETER_JOB_INITIAL_STATE].heap,
job->next_scheduled_time, job);
job->current_state = VIETER_JOB_INITIAL_STATE;
job->dispatched = false;
@ -124,10 +125,11 @@ vieter_job_queue_error vieter_job_queue_transition(vieter_job_queue *queue,
}
if (VIETER_JOB_STATE_IS_ARCH(new_state)) {
vieter_cat_heap_insert(queue->heaps[new_state].cat_heap, job->arch, job->id,
job);
vieter_cat_heap_insert(queue->heaps[new_state].cat_heap, job->arch,
job->next_scheduled_time, job);
} else {
vieter_heap_insert(queue->heaps[new_state].heap, job->id, job);
vieter_heap_insert(queue->heaps[new_state].heap, job->next_scheduled_time,
job);
}
job->current_state = new_state;
@ -178,7 +180,8 @@ vieter_job_queue_error vieter_job_queue_fail(vieter_job_queue *queue,
}
// We assume the failure state is not categorized
vieter_heap_insert(queue->heaps[VIETER_JOB_FAILURE_STATE].heap, job->id, job);
vieter_heap_insert(queue->heaps[VIETER_JOB_FAILURE_STATE].heap,
job->next_scheduled_time, job);
job->dispatched = false;
job->state_transition_times[VIETER_JOB_FAILURE_STATE] = time(NULL);