diff options
| author | 2022-09-20 12:00:13 +0200 | |
|---|---|---|
| committer | 2022-09-20 12:00:13 +0200 | |
| commit | 5d843a488ec349d94e22314e90a73885ebfce007 (patch) | |
| tree | ce103859ce4d4ee90564192cd56160a54cf61a71 | |
| parent | Added muted functions. (diff) | |
| download | snac2-5d843a488ec349d94e22314e90a73885ebfce007.tar.gz snac2-5d843a488ec349d94e22314e90a73885ebfce007.tar.xz snac2-5d843a488ec349d94e22314e90a73885ebfce007.zip | |
New function enqueue().
| -rw-r--r-- | data.c | 37 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | snac.c | 4 | ||||
| -rw-r--r-- | snac.h | 2 |
4 files changed, 40 insertions, 5 deletions
| @@ -391,7 +391,7 @@ void timeline_add(snac *snac, char *id, char *msg, char *parent) | |||
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | /* build the new filename */ | 393 | /* build the new filename */ |
| 394 | xs *ntid = tid(); | 394 | xs *ntid = tid(0); |
| 395 | xs *md5 = xs_md5_hex(id, strlen(id)); | 395 | xs *md5 = xs_md5_hex(id, strlen(id)); |
| 396 | xs *fn = xs_fmt("%s/timeline/%s-%s.json", snac->basedir, ntid, md5); | 396 | xs *fn = xs_fmt("%s/timeline/%s-%s.json", snac->basedir, ntid, md5); |
| 397 | xs *md; | 397 | xs *md; |
| @@ -519,3 +519,38 @@ int is_muted(snac *snac, char *actor) | |||
| 519 | 519 | ||
| 520 | return !!(mtime(fn) != 0.0); | 520 | return !!(mtime(fn) != 0.0); |
| 521 | } | 521 | } |
| 522 | |||
| 523 | |||
| 524 | void enqueue(snac *snac, char *actor, char *msg, int retries) | ||
| 525 | /* enqueues a message for an actor */ | ||
| 526 | { | ||
| 527 | if (strcmp(actor, snac->actor) == 0) { | ||
| 528 | snac_debug(snac, 1, xs_str_new("enqueue refused to myself")); | ||
| 529 | return; | ||
| 530 | } | ||
| 531 | |||
| 532 | int qrt = xs_number_get(xs_dict_get(srv_config, "query_retry_minutes")); | ||
| 533 | xs *ntid = tid(retries * 60 * qrt); | ||
| 534 | xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid); | ||
| 535 | xs *tfn = xs_str_cat(fn, ".tmp"); | ||
| 536 | FILE *f; | ||
| 537 | |||
| 538 | if ((f = fopen(tfn, "w")) != NULL) { | ||
| 539 | xs *qmsg = xs_dict_new(); | ||
| 540 | xs *rn = xs_number_new(retries); | ||
| 541 | xs *j; | ||
| 542 | |||
| 543 | qmsg = xs_dict_append(qmsg, "actor", actor); | ||
| 544 | qmsg = xs_dict_append(qmsg, "object", msg); | ||
| 545 | qmsg = xs_dict_append(qmsg, "retries", rn); | ||
| 546 | |||
| 547 | j = xs_json_dumps_pp(qmsg, 4); | ||
| 548 | |||
| 549 | fwrite(j, strlen(j), 1, f); | ||
| 550 | fclose(f); | ||
| 551 | |||
| 552 | rename(tfn, fn); | ||
| 553 | |||
| 554 | snac_debug(snac, 2, xs_fmt("enqueue %s %s %d", actor, fn, retries)); | ||
| 555 | } | ||
| 556 | } | ||
| @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) | |||
| 9 | { | 9 | { |
| 10 | snac snac; | 10 | snac snac; |
| 11 | 11 | ||
| 12 | printf("%s\n", tid()); | 12 | printf("%s\n", tid(0)); |
| 13 | 13 | ||
| 14 | srv_open("/home/angel/lib/snac/comam.es/"); | 14 | srv_open("/home/angel/lib/snac/comam.es/"); |
| 15 | 15 | ||
| @@ -42,7 +42,7 @@ d_char *xs_time(char *fmt, int local) | |||
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | d_char *tid(void) | 45 | d_char *tid(int offset) |
| 46 | /* returns a time-based Id */ | 46 | /* returns a time-based Id */ |
| 47 | { | 47 | { |
| 48 | struct timeval tv; | 48 | struct timeval tv; |
| @@ -50,7 +50,7 @@ d_char *tid(void) | |||
| 50 | 50 | ||
| 51 | gettimeofday(&tv, &tz); | 51 | gettimeofday(&tv, &tz); |
| 52 | 52 | ||
| 53 | return xs_fmt("%10d.%06d", tv.tv_sec, tv.tv_usec); | 53 | return xs_fmt("%10d.%06d", tv.tv_sec + offset, tv.tv_usec); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | 56 | ||
| @@ -11,7 +11,7 @@ d_char *xs_time(char *fmt, int local); | |||
| 11 | #define xs_local_time(fmt) xs_time(fmt, 1) | 11 | #define xs_local_time(fmt) xs_time(fmt, 1) |
| 12 | #define xs_utc_time(fmt) xs_time(fmt, 0) | 12 | #define xs_utc_time(fmt) xs_time(fmt, 0) |
| 13 | 13 | ||
| 14 | d_char *tid(void); | 14 | d_char *tid(int offset); |
| 15 | 15 | ||
| 16 | void srv_debug(int level, d_char *str); | 16 | void srv_debug(int level, d_char *str); |
| 17 | #define srv_log(str) srv_debug(0, str) | 17 | #define srv_log(str) srv_debug(0, str) |