mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
New function queue().
This commit is contained in:
parent
5d843a488e
commit
e923a4f5ec
3 changed files with 48 additions and 0 deletions
33
data.c
33
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));
|
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;
|
||||||
|
}
|
||||||
|
|
12
main.c
12
main.c
|
@ -15,6 +15,17 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
user_open(&snac, "mike");
|
user_open(&snac, "mike");
|
||||||
|
|
||||||
|
{
|
||||||
|
xs *list = queue(&snac);
|
||||||
|
char *p, *fn;
|
||||||
|
|
||||||
|
p = list;
|
||||||
|
while (xs_list_iter(&p, &fn)) {
|
||||||
|
printf("%s\n", fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
{
|
{
|
||||||
xs *list = follower_list(&snac);
|
xs *list = follower_list(&snac);
|
||||||
char *p, *obj;
|
char *p, *obj;
|
||||||
|
@ -50,6 +61,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
3
snac.h
3
snac.h
|
@ -57,3 +57,6 @@ int following_check(snac *snac, char *actor);
|
||||||
void mute(snac *snac, char *actor);
|
void mute(snac *snac, char *actor);
|
||||||
void unmute(snac *snac, char *actor);
|
void unmute(snac *snac, char *actor);
|
||||||
int is_muted(snac *snac, char *actor);
|
int is_muted(snac *snac, char *actor);
|
||||||
|
|
||||||
|
void enqueue(snac *snac, char *actor, char *msg, int retries);
|
||||||
|
d_char *queue(snac *snac);
|
||||||
|
|
Loading…
Reference in a new issue