mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
New function process_queue_item().
This commit is contained in:
parent
f0ef1d4115
commit
c2524323a9
1 changed files with 100 additions and 92 deletions
|
@ -845,7 +845,7 @@ void notify(snac *snac, char *type, char *utype, char *actor, char *msg)
|
|||
|
||||
/** queues **/
|
||||
|
||||
int process_message(snac *snac, char *msg, char *req)
|
||||
int process_input_message(snac *snac, char *msg, char *req)
|
||||
/* processes an ActivityPub message from the input queue */
|
||||
{
|
||||
/* actor and type exist, were checked previously */
|
||||
|
@ -1065,49 +1065,37 @@ int send_email(char *msg)
|
|||
}
|
||||
|
||||
|
||||
void process_queue(snac *snac)
|
||||
/* processes the queue */
|
||||
void process_queue_item(snac *snac, xs_dict *q_item)
|
||||
/* processes an item from the queue */
|
||||
{
|
||||
xs *list;
|
||||
char *p, *fn;
|
||||
int queue_retry_max = xs_number_get(xs_dict_get(srv_config, "queue_retry_max"));
|
||||
|
||||
list = queue(snac);
|
||||
|
||||
p = list;
|
||||
while (xs_list_iter(&p, &fn)) {
|
||||
xs *q_item = dequeue(snac, fn);
|
||||
char *type;
|
||||
|
||||
if (q_item == NULL) {
|
||||
snac_log(snac, xs_fmt("process_queue q_item error"));
|
||||
continue;
|
||||
}
|
||||
int queue_retry_max = xs_number_get(xs_dict_get(srv_config, "queue_retry_max"));
|
||||
|
||||
if ((type = xs_dict_get(q_item, "type")) == NULL)
|
||||
type = "output";
|
||||
|
||||
if (strcmp(type, "message") == 0) {
|
||||
char *msg = xs_dict_get(q_item, "message");
|
||||
xs_dict *msg = xs_dict_get(q_item, "message");
|
||||
xs *inboxes = inbox_list(snac, msg);
|
||||
char *p, *v;
|
||||
xs_list *p;
|
||||
xs_str *inbox;
|
||||
|
||||
p = inboxes;
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
enqueue_output(snac, msg, v, 0);
|
||||
while (xs_list_iter(&p, &inbox)) {
|
||||
enqueue_output(snac, msg, inbox, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (strcmp(type, "output") == 0) {
|
||||
int status;
|
||||
char *inbox = xs_dict_get(q_item, "inbox");
|
||||
char *msg = xs_dict_get(q_item, "message");
|
||||
xs_str *inbox = xs_dict_get(q_item, "inbox");
|
||||
xs_dict *msg = xs_dict_get(q_item, "message");
|
||||
int retries = xs_number_get(xs_dict_get(q_item, "retries"));
|
||||
xs *payload = NULL;
|
||||
int p_size = 0;
|
||||
|
||||
if (xs_is_null(inbox) || xs_is_null(msg))
|
||||
continue;
|
||||
return;
|
||||
|
||||
/* deliver */
|
||||
status = send_to_inbox(snac, inbox, msg, &payload, &p_size, retries == 0 ? 3 : 8);
|
||||
|
@ -1132,14 +1120,14 @@ void process_queue(snac *snac)
|
|||
else
|
||||
if (strcmp(type, "input") == 0) {
|
||||
/* process the message */
|
||||
char *msg = xs_dict_get(q_item, "message");
|
||||
char *req = xs_dict_get(q_item, "req");
|
||||
xs_dict *msg = xs_dict_get(q_item, "message");
|
||||
xs_dict *req = xs_dict_get(q_item, "req");
|
||||
int retries = xs_number_get(xs_dict_get(q_item, "retries"));
|
||||
|
||||
if (xs_is_null(msg))
|
||||
continue;
|
||||
return;
|
||||
|
||||
if (!process_message(snac, msg, req)) {
|
||||
if (!process_input_message(snac, msg, req)) {
|
||||
if (retries > queue_retry_max)
|
||||
snac_log(snac, xs_fmt("process_queue input giving up"));
|
||||
else {
|
||||
|
@ -1152,7 +1140,7 @@ void process_queue(snac *snac)
|
|||
else
|
||||
if (strcmp(type, "email") == 0) {
|
||||
/* send this email */
|
||||
char *msg = xs_dict_get(q_item, "message");
|
||||
xs_str *msg = xs_dict_get(q_item, "message");
|
||||
int retries = xs_number_get(xs_dict_get(q_item, "retries"));
|
||||
|
||||
if (!send_email(msg))
|
||||
|
@ -1170,6 +1158,26 @@ void process_queue(snac *snac)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void process_queue(snac *snac)
|
||||
/* processes the queue */
|
||||
{
|
||||
xs *list = queue(snac);
|
||||
|
||||
xs_list *p = list;
|
||||
xs_str *fn;
|
||||
|
||||
while (xs_list_iter(&p, &fn)) {
|
||||
xs *q_item = dequeue(snac, fn);
|
||||
|
||||
if (q_item == NULL) {
|
||||
snac_log(snac, xs_fmt("process_queue q_item error"));
|
||||
continue;
|
||||
}
|
||||
|
||||
process_queue_item(snac, q_item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue