refactor(job-queue): change free functions

job-queue
Jef Roosens 2023-04-04 14:57:31 +02:00
parent ec6e217801
commit 07f793d768
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 28 additions and 29 deletions

View File

@ -38,7 +38,7 @@ typedef struct vieter_job_failure_report {
vieter_job_failure_report *vieter_job_failure_report_init(); vieter_job_failure_report *vieter_job_failure_report_init();
void vieter_job_failure_report_free(vieter_job_failure_report **ptp); void vieter_job_failure_report_free(vieter_job_failure_report *report);
/* /*
* Represents a job currently being processed in the system. A job migrates * Represents a job currently being processed in the system. A job migrates
@ -62,7 +62,7 @@ typedef struct vieter_job {
*/ */
vieter_job *vieter_job_init(); vieter_job *vieter_job_init();
void vieter_job_free(vieter_job **ptp); void vieter_job_free(vieter_job *job);
/* /*
* Represents the actual queue managing the list of jobs. * Represents the actual queue managing the list of jobs.
@ -87,7 +87,7 @@ vieter_job_queue *vieter_job_queue_init();
/* /*
* Free a job queue. * Free a job queue.
*/ */
void vieter_job_queue_free(vieter_job_queue **ptp); void vieter_job_queue_free(vieter_job_queue *queue);
/* /*
* Insert the given job into the system. * Insert the given job into the system.

View File

@ -0,0 +1,24 @@
#include "vieter_job_queue_internal.h"
vieter_job *vieter_job_init() { return calloc(1, sizeof(vieter_job)); }
void vieter_job_free(vieter_job *job) {
if (job->schedule != NULL) {
vieter_cron_expr_free(job->schedule);
}
if (job->failure_report != NULL) {
vieter_job_failure_report_free(job->failure_report);
}
free(job);
}
vieter_job_failure_report *vieter_job_failure_report_init() {
return calloc(1, sizeof(vieter_job_failure_report));
}
void vieter_job_failure_report_free(vieter_job_failure_report *report) {
free(report->msg);
free(report);
}

View File

@ -16,9 +16,7 @@ vieter_job_queue *vieter_job_queue_init() {
return queue; return queue;
} }
void vieter_job_queue_free(vieter_job_queue **ptp) { void vieter_job_queue_free(vieter_job_queue *queue) {
vieter_job_queue *queue = *ptp;
vieter_tree_free(queue->tree); vieter_tree_free(queue->tree);
for (int i = 0; i < VIETER_JOB_STATES; i++) { for (int i = 0; i < VIETER_JOB_STATES; i++) {
@ -30,25 +28,6 @@ void vieter_job_queue_free(vieter_job_queue **ptp) {
} }
free(queue); free(queue);
*ptp = NULL;
}
vieter_job *vieter_job_init() { return calloc(1, sizeof(vieter_job)); }
void vieter_job_free(vieter_job **ptp) {
vieter_job *job = *ptp;
if (job->schedule != NULL) {
vieter_cron_expr_free(job->schedule);
}
if (job->failure_report != NULL) {
vieter_job_failure_report_free(&job->failure_report);
}
free(job);
*ptp = NULL;
} }
vieter_job_queue_error vieter_job_queue_insert(vieter_job_queue *queue, vieter_job_queue_error vieter_job_queue_insert(vieter_job_queue *queue,
@ -160,10 +139,6 @@ vieter_job_queue_error vieter_job_queue_remove(vieter_job **out,
return vieter_job_queue_ok; return vieter_job_queue_ok;
} }
vieter_job_failure_report *vieter_job_failure_report_init() {
return calloc(1, sizeof(vieter_job_failure_report));
}
vieter_job_queue_error vieter_job_queue_fail(vieter_job_queue *queue, vieter_job_queue_error vieter_job_queue_fail(vieter_job_queue *queue,
uint64_t id, uint64_t id,
char *report_message) { char *report_message) {