Reworked enqueue_email().

This commit is contained in:
default 2023-01-31 21:49:43 +01:00
parent 4e62b409af
commit 274ae3d142
2 changed files with 8 additions and 14 deletions

16
data.c
View file

@ -1318,7 +1318,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)
} }
static xs_dict *_new_qmsg(const char *type, const xs_dict *msg, int retries) static xs_dict *_new_qmsg(const char *type, const xs_val *msg, int retries)
/* creates a queue message */ /* creates a queue message */
{ {
int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes")); int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes"));
@ -1371,7 +1371,7 @@ void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries)
} }
void enqueue_output_by_actor(snac *snac, char *msg, char *actor, int retries) void enqueue_output_by_actor(snac *snac, xs_dict *msg, xs_str *actor, int retries)
/* enqueues an output message for an actor */ /* enqueues an output message for an actor */
{ {
xs *inbox = get_actor_inbox(snac, actor); xs *inbox = get_actor_inbox(snac, actor);
@ -1383,18 +1383,12 @@ void enqueue_output_by_actor(snac *snac, char *msg, char *actor, int retries)
} }
void enqueue_email(snac *snac, char *msg, int retries) void enqueue_email(snac *snac, xs_str *msg, int retries)
/* enqueues an email message to be sent */ /* enqueues an email message to be sent */
{ {
int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes")); xs *qmsg = _new_qmsg("email", msg, retries);
xs *ntid = tid(retries * 60 * qrt); char *ntid = xs_dict_get(qmsg, "ntid");
xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid); xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid);
xs *qmsg = xs_dict_new();
xs *rn = xs_number_new(retries);
qmsg = xs_dict_append(qmsg, "type", "email");
qmsg = xs_dict_append(qmsg, "message", msg);
qmsg = xs_dict_append(qmsg, "retries", rn);
qmsg = _enqueue_put(fn, qmsg); qmsg = _enqueue_put(fn, qmsg);

4
snac.h
View file

@ -123,8 +123,8 @@ d_char *history_list(snac *snac);
void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries); void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries);
void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries); void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries);
void enqueue_output_by_actor(snac *snac, char *msg, char *actor, int retries); void enqueue_output_by_actor(snac *snac, xs_dict *msg, xs_str *actor, int retries);
void enqueue_email(snac *snac, char *msg, int retries); void enqueue_email(snac *snac, xs_str *msg, int retries);
void enqueue_message(snac *snac, char *msg); void enqueue_message(snac *snac, char *msg);
d_char *queue(snac *snac); d_char *queue(snac *snac);