summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-02-02 05:07:20 +0100
committerGravatar default2023-02-02 05:07:20 +0100
commitc639553836c4b8aa5e98ca6a48e5464e9aa76057 (patch)
tree713cc654a67f2966a68c18c8d76cec42bac18151
parentRenamed process_queue_item() to process_user_queue_item(). (diff)
downloadsnac2-c639553836c4b8aa5e98ca6a48e5464e9aa76057.tar.gz
snac2-c639553836c4b8aa5e98ca6a48e5464e9aa76057.tar.xz
snac2-c639553836c4b8aa5e98ca6a48e5464e9aa76057.zip
New function queue() (the global queue).
-rw-r--r--activitypub.c31
-rw-r--r--data.c37
2 files changed, 64 insertions, 4 deletions
diff --git a/activitypub.c b/activitypub.c
index aea353b..5cc059d 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -1066,7 +1066,7 @@ int send_email(char *msg)
1066 1066
1067 1067
1068void process_user_queue_item(snac *snac, xs_dict *q_item) 1068void process_user_queue_item(snac *snac, xs_dict *q_item)
1069/* processes an item from the queue */ 1069/* processes an item from the user queue */
1070{ 1070{
1071 char *type; 1071 char *type;
1072 int queue_retry_max = xs_number_get(xs_dict_get(srv_config, "queue_retry_max")); 1072 int queue_retry_max = xs_number_get(xs_dict_get(srv_config, "queue_retry_max"));
@@ -1172,7 +1172,7 @@ void process_user_queue(snac *snac)
1172 xs *q_item = dequeue(fn); 1172 xs *q_item = dequeue(fn);
1173 1173
1174 if (q_item == NULL) { 1174 if (q_item == NULL) {
1175 snac_log(snac, xs_fmt("process_queue q_item error")); 1175 snac_log(snac, xs_fmt("process_user_queue q_item error"));
1176 continue; 1176 continue;
1177 } 1177 }
1178 1178
@@ -1181,6 +1181,33 @@ void process_user_queue(snac *snac)
1181} 1181}
1182 1182
1183 1183
1184void process_queue_item(xs_dict *q_item)
1185/* processes an item from the global queue */
1186{
1187}
1188
1189
1190void process_queue(void)
1191/* processes the global queue */
1192{
1193 xs *list = queue();
1194
1195 xs_list *p = list;
1196 xs_str *fn;
1197
1198 while (xs_list_iter(&p, &fn)) {
1199 xs *q_item = dequeue(fn);
1200
1201 if (q_item == NULL) {
1202 srv_log(xs_fmt("process_queue q_item error"));
1203 continue;
1204 }
1205
1206 process_queue_item(q_item);
1207 }
1208}
1209
1210
1184/** HTTP handlers */ 1211/** HTTP handlers */
1185 1212
1186int activitypub_get_handler(d_char *req, char *q_path, 1213int activitypub_get_handler(d_char *req, char *q_path,
diff --git a/data.c b/data.c
index 1adf4cd..96583aa 100644
--- a/data.c
+++ b/data.c
@@ -86,6 +86,10 @@ int srv_open(char *basedir, int auto_upgrade)
86 if (error != NULL) 86 if (error != NULL)
87 srv_log(error); 87 srv_log(error);
88 88
89 /* create the queue/ subdir, just in case */
90 xs *qdir = xs_fmt("%s/queue", srv_basedir);
91 mkdir(qdir, 0755);
92
89#ifdef __OpenBSD__ 93#ifdef __OpenBSD__
90 char *v = xs_dict_get(srv_config, "disable_openbsd_security"); 94 char *v = xs_dict_get(srv_config, "disable_openbsd_security");
91 95
@@ -1429,10 +1433,39 @@ xs_list *user_queue(snac *snac)
1429 time_t t2 = atol(bn + 1); 1433 time_t t2 = atol(bn + 1);
1430 1434
1431 if (t2 > t) 1435 if (t2 > t)
1432 snac_debug(snac, 2, xs_fmt("queue not yet time for %s [%ld]", v, t)); 1436 snac_debug(snac, 2, xs_fmt("user_queue not yet time for %s [%ld]", v, t));
1437 else {
1438 list = xs_list_append(list, v);
1439 snac_debug(snac, 2, xs_fmt("user_queue ready for %s", v));
1440 }
1441 }
1442
1443 return list;
1444}
1445
1446
1447xs_list *queue(void)
1448/* returns a list with filenames that can be dequeued */
1449{
1450 xs *spec = xs_fmt("%s/queue/" "*.json", srv_basedir);
1451 xs_list *list = xs_list_new();
1452 time_t t = time(NULL);
1453 xs_list *p;
1454 xs_val *v;
1455
1456 xs *fns = xs_glob(spec, 0, 0);
1457
1458 p = fns;
1459 while (xs_list_iter(&p, &v)) {
1460 /* get the retry time from the basename */
1461 char *bn = strrchr(v, '/');
1462 time_t t2 = atol(bn + 1);
1463
1464 if (t2 > t)
1465 srv_debug(2, xs_fmt("queue not yet time for %s [%ld]", v, t));
1433 else { 1466 else {
1434 list = xs_list_append(list, v); 1467 list = xs_list_append(list, v);
1435 snac_debug(snac, 2, xs_fmt("queue ready for %s", v)); 1468 srv_debug(2, xs_fmt("queue ready for %s", v));
1436 } 1469 }
1437 } 1470 }
1438 1471