diff options
| author | 2022-10-18 11:40:10 +0200 | |
|---|---|---|
| committer | 2022-10-18 11:40:10 +0200 | |
| commit | a62cde3d9dc074bac6e10d1f3124d6b24d648f63 (patch) | |
| tree | 3b9b45d90ee3c5ea5e12d81117362f7c38e5270e /data.c | |
| parent | xs_base64_dec() can now be used as a string, so do it. (diff) | |
| download | snac2-a62cde3d9dc074bac6e10d1f3124d6b24d648f63.tar.gz snac2-a62cde3d9dc074bac6e10d1f3124d6b24d648f63.tar.xz snac2-a62cde3d9dc074bac6e10d1f3124d6b24d648f63.zip | |
Rewritten queue() using xs_glob().
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 32 |
1 files changed, 14 insertions, 18 deletions
| @@ -978,31 +978,27 @@ void enqueue_output(snac *snac, char *msg, char *actor, int retries) | |||
| 978 | d_char *queue(snac *snac) | 978 | d_char *queue(snac *snac) |
| 979 | /* returns a list with filenames that can be dequeued */ | 979 | /* returns a list with filenames that can be dequeued */ |
| 980 | { | 980 | { |
| 981 | xs *spec = xs_fmt("%s/queue/" "*.json", snac->basedir); | 981 | xs *spec = xs_fmt("%s/queue/" "*.json", snac->basedir); |
| 982 | d_char *list = xs_list_new(); | 982 | d_char *list = xs_list_new(); |
| 983 | glob_t globbuf; | 983 | time_t t = time(NULL); |
| 984 | time_t t = time(NULL); | 984 | char *p, *v; |
| 985 | 985 | ||
| 986 | if (glob(spec, 0, NULL, &globbuf) == 0) { | 986 | xs *fns = xs_glob(spec, 0, 0); |
| 987 | int n; | ||
| 988 | char *p; | ||
| 989 | 987 | ||
| 990 | for (n = 0; (p = globbuf.gl_pathv[n]) != NULL; n++) { | 988 | p = fns; |
| 991 | /* get the retry time from the basename */ | 989 | while (xs_list_iter(&p, &v)) { |
| 992 | char *bn = strrchr(p, '/'); | 990 | /* get the retry time from the basename */ |
| 993 | time_t t2 = atol(bn + 1); | 991 | char *bn = strrchr(v, '/'); |
| 992 | time_t t2 = atol(bn + 1); | ||
| 994 | 993 | ||
| 995 | if (t2 > t) | 994 | if (t2 > t) |
| 996 | snac_debug(snac, 2, xs_fmt("queue not yet time for %s", p)); | 995 | snac_debug(snac, 2, xs_fmt("queue not yet time for %s", v)); |
| 997 | else { | 996 | else { |
| 998 | list = xs_list_append(list, p); | 997 | list = xs_list_append(list, v); |
| 999 | snac_debug(snac, 2, xs_fmt("queue ready for %s", p)); | 998 | snac_debug(snac, 2, xs_fmt("queue ready for %s", v)); |
| 1000 | } | ||
| 1001 | } | 999 | } |
| 1002 | } | 1000 | } |
| 1003 | 1001 | ||
| 1004 | globfree(&globbuf); | ||
| 1005 | |||
| 1006 | return list; | 1002 | return list; |
| 1007 | } | 1003 | } |
| 1008 | 1004 | ||