feat(job-queue): add cat-heap support

This commit is contained in:
Jef Roosens 2023-04-01 17:04:40 +02:00
parent 8e076f8543
commit 1f4887118f
5 changed files with 71 additions and 15 deletions

View file

@ -13,7 +13,7 @@ typedef enum vieter_cat_heap_error {
vieter_cat_heap *vieter_cat_heap_init();
void vieter_cat_heap_free(vieter_cat_heap **ptp);
void vieter_cat_heap_free(vieter_cat_heap *cheap);
uint64_t vieter_cat_heap_size(vieter_cat_heap *cheap);

View file

@ -20,8 +20,12 @@ typedef enum vieter_job_state {
// This macro should be kept in sync with the above enum
#define VIETER_JOB_STATES 4
// Neither of these states are allowed to be categorized
#define VIETER_JOB_INITIAL_STATE vieter_job_state_queued
#define VIETER_JOB_FAILURE_STATE vieter_job_state_failed
// Bitmap describing what states should be divided into multiple architectures
#define VIETER_JOB_STATES_ARCH 0b0010
#define VIETER_JOB_STATE_IS_ARCH(i) (VIETER_JOB_STATES_ARCH & (1 << i))
/*
* Struct storing a report for why a certain job failed to be processed in the
@ -45,6 +49,7 @@ typedef struct vieter_job {
uint64_t next_scheduled_time;
vieter_cron_expression *schedule;
void *build_config;
char *arch;
vieter_job_failure_report *failure_report;
uint64_t state_transition_times[VIETER_JOB_STATES];
vieter_job_state current_state;
@ -69,7 +74,9 @@ typedef enum vieter_job_queue_error {
vieter_job_queue_not_present = 1,
vieter_job_queue_already_present = 2,
vieter_job_queue_state_empty = 3,
vieter_job_queue_not_dispatched = 4
vieter_job_queue_not_dispatched = 4,
vieter_job_queue_state_is_arch = 5,
vieter_job_queue_state_is_not_arch = 6,
} vieter_job_queue_error;
/*
@ -89,13 +96,22 @@ vieter_job_queue_error vieter_job_queue_insert(vieter_job_queue *queue,
vieter_job *job);
/*
* Pop a job from the given state's queue. The job will then be marked as
* dispatched.
* Pop a job from the given non-categorized state's queue. The job will then be
* marked as dispatched.
*/
vieter_job_queue_error vieter_job_queue_pop(vieter_job **out,
vieter_job_queue *queue,
vieter_job_state state);
/*
* Pop a job from the given categorized state's queue. The job will then be
* marked as dispatched.
*/
vieter_job_queue_error vieter_job_queue_pop_arch(vieter_job **out,
vieter_job_queue *queue,
vieter_job_state state,
char *arch);
/*
* Transition the job with the given id to the new state. This sets the
* job's dispatch flag to false, and adds it to the new state's queue.