feat(job-queue): initial implementation of functionality

This commit is contained in:
Jef Roosens 2023-03-07 11:55:12 +01:00
parent 02bd2c24b7
commit 83b3198a49
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
3 changed files with 194 additions and 6 deletions

View file

@ -20,6 +20,8 @@ typedef enum vieter_job_state {
// This macro should be kept in sync with the above enum
#define VIETER_JOB_STATES 4
#define VIETER_JOB_INITIAL_STATE vieter_job_state_queued
#define VIETER_JOB_FAILURE_STATE vieter_job_state_failed
/*
* Struct storing a report for why a certain job failed to be processed in the
@ -64,7 +66,10 @@ typedef struct vieter_job_queue vieter_job_queue;
typedef enum vieter_job_queue_error {
vieter_job_queue_ok = 0,
vieter_job_queue_not_found = 1
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_error;
/*
@ -72,24 +77,51 @@ typedef enum vieter_job_queue_error {
*/
vieter_job_queue *vieter_job_queue_init();
/*
* Free a job queue.
*/
void vieter_job_queue_free(vieter_job_queue **ptp);
/*
* Insert the given job into the system.
*/
vieter_job_queue_error vieter_job_queue_insert(vieter_job *job);
vieter_job_queue_error vieter_job_queue_insert(vieter_job_queue *queue,
vieter_job *job);
/*
* Dispatch the job with the given id, returning the pointer to the job.
* Dispatching a job removes it from its respective state's queue.
* Pop a job from the given state's queue. The job will then be marked as
* dispatched.
*/
vieter_job_queue_error vieter_job_queue_dispatch(vieter_job **out, uint64_t id);
vieter_job_queue_error vieter_job_queue_pop(vieter_job **out,
vieter_job_queue *queue,
vieter_job_state state);
/*
* 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.
*
* NOTE: this can only be done with dispatched jobs.
*/
vieter_job_queue_error vieter_job_queue_transition(uint64_t id,
vieter_job_queue_error vieter_job_queue_transition(vieter_job_queue *queue,
uint64_t id,
vieter_job_state new_state);
/*
* Remove the given job from the job queue, returning its pointer to the caller.
*
* NOTE: this can only be done with dispatched jobs.
*/
vieter_job_queue_error
vieter_job_queue_remove(vieter_job **out, vieter_job_queue *queue, uint64_t id);
/*
* Transition a job into the failure state, and attach a failure report with the
* provided message. The message is copied, so the caller is responsible for
* freeing the provided string.
*
* NOTE: this can only be done with dispatched jobs.
*/
vieter_job_queue_error vieter_job_queue_fail(vieter_job_queue *queue,
uint64_t id, char *report_message);
#endif