summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2022-09-20 12:43:49 +0200
committerGravatar default2022-09-20 12:43:49 +0200
commite923a4f5ec586d9dcec90e585b8d50cfbeafb8a1 (patch)
treefee0e977c9e74eedf29b37b962814619e3a0f32a /data.c
parentNew function enqueue(). (diff)
downloadsnac2-e923a4f5ec586d9dcec90e585b8d50cfbeafb8a1.tar.gz
snac2-e923a4f5ec586d9dcec90e585b8d50cfbeafb8a1.tar.xz
snac2-e923a4f5ec586d9dcec90e585b8d50cfbeafb8a1.zip
New function queue().
Diffstat (limited to 'data.c')
-rw-r--r--data.c33
1 files changed, 33 insertions, 0 deletions
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)
554 snac_debug(snac, 2, xs_fmt("enqueue %s %s %d", actor, fn, retries)); 554 snac_debug(snac, 2, xs_fmt("enqueue %s %s %d", actor, fn, retries));
555 } 555 }
556} 556}
557
558
559d_char *queue(snac *snac)
560/* returns a list with filenames that can be dequeued */
561{
562 xs *spec = xs_fmt("%s/queue/" "*.json", snac->basedir);
563 d_char *list = xs_list_new();
564 glob_t globbuf;
565 time_t t = time(NULL);
566
567 /* get the list in reverse order */
568 if (glob(spec, 0, NULL, &globbuf) == 0) {
569 int n;
570 char *p;
571
572 for (n = 0; (p = globbuf.gl_pathv[n]) != NULL; n++) {
573 /* get the retry time from the basename */
574 char *bn = strrchr(p, '/');
575 time_t t2 = atol(bn + 1);
576
577 if (t2 > t)
578 snac_debug(snac, 2, xs_fmt("queue not yet time for %s", p));
579 else {
580 list = xs_list_append(list, p);
581 snac_debug(snac, 2, xs_fmt("queue ready for %s", p));
582 }
583 }
584 }
585
586 globfree(&globbuf);
587
588 return list;
589}