From e923a4f5ec586d9dcec90e585b8d50cfbeafb8a1 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 20 Sep 2022 12:43:49 +0200 Subject: New function queue(). --- data.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index fe21be6..e875f90 100644 --- a/data.c +++ b/data.c @@ -554,3 +554,36 @@ void enqueue(snac *snac, char *actor, char *msg, int retries) snac_debug(snac, 2, xs_fmt("enqueue %s %s %d", actor, fn, retries)); } } + + +d_char *queue(snac *snac) +/* returns a list with filenames that can be dequeued */ +{ + xs *spec = xs_fmt("%s/queue/" "*.json", snac->basedir); + d_char *list = xs_list_new(); + glob_t globbuf; + time_t t = time(NULL); + + /* get the list in reverse order */ + if (glob(spec, 0, NULL, &globbuf) == 0) { + int n; + char *p; + + for (n = 0; (p = globbuf.gl_pathv[n]) != NULL; n++) { + /* get the retry time from the basename */ + char *bn = strrchr(p, '/'); + time_t t2 = atol(bn + 1); + + if (t2 > t) + snac_debug(snac, 2, xs_fmt("queue not yet time for %s", p)); + else { + list = xs_list_append(list, p); + snac_debug(snac, 2, xs_fmt("queue ready for %s", p)); + } + } + } + + globfree(&globbuf); + + return list; +} -- cgit v1.2.3