diff options
| author | 2025-09-28 14:40:24 +0200 | |
|---|---|---|
| committer | 2025-09-28 14:40:24 +0200 | |
| commit | cddb2724d56ce8e1d80d4eec3c13702634704022 (patch) | |
| tree | e3d9099cd43b0370a976155371e91cff68d97b20 | |
| parent | Revert "New function actor_failure()." (diff) | |
| download | penes-snac2-cddb2724d56ce8e1d80d4eec3c13702634704022.tar.gz penes-snac2-cddb2724d56ce8e1d80d4eec3c13702634704022.tar.xz penes-snac2-cddb2724d56ce8e1d80d4eec3c13702634704022.zip | |
New function actor_failure() (again, but much better).
| -rw-r--r-- | data.c | 39 | ||||
| -rw-r--r-- | snac.h | 1 |
2 files changed, 40 insertions, 0 deletions
| @@ -3042,6 +3042,45 @@ xs_list *content_search(snac *user, const char *regex, | |||
| 3042 | } | 3042 | } |
| 3043 | 3043 | ||
| 3044 | 3044 | ||
| 3045 | int actor_failure(const char *actor, int op) | ||
| 3046 | /* actor failure maintenance */ | ||
| 3047 | { | ||
| 3048 | int ret = 0; | ||
| 3049 | |||
| 3050 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | ||
| 3051 | xs *fn = xs_fmt("%s/failure/%s", srv_basedir, md5); | ||
| 3052 | |||
| 3053 | switch (op) { | ||
| 3054 | case 0: /** check **/ | ||
| 3055 | if (mtime(fn)) | ||
| 3056 | ret = -1; | ||
| 3057 | |||
| 3058 | break; | ||
| 3059 | |||
| 3060 | case 1: /** register a failure **/ | ||
| 3061 | if (mtime(fn) == 0.0) { | ||
| 3062 | FILE *f; | ||
| 3063 | |||
| 3064 | /* only create once, as the date will be used */ | ||
| 3065 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 3066 | fprintf(f, "%s\n", actor); | ||
| 3067 | fclose(f); | ||
| 3068 | } | ||
| 3069 | } | ||
| 3070 | |||
| 3071 | break; | ||
| 3072 | |||
| 3073 | case 2: /** clear a failure **/ | ||
| 3074 | /* called whenever a message comes from this instance */ | ||
| 3075 | unlink(fn); | ||
| 3076 | |||
| 3077 | break; | ||
| 3078 | } | ||
| 3079 | |||
| 3080 | return ret; | ||
| 3081 | } | ||
| 3082 | |||
| 3083 | |||
| 3045 | int instance_failure(const char *url, int op) | 3084 | int instance_failure(const char *url, int op) |
| 3046 | /* do some checks and accounting on instance failures */ | 3085 | /* do some checks and accounting on instance failures */ |
| 3047 | { | 3086 | { |
| @@ -278,6 +278,7 @@ int content_match(const char *file, const xs_dict *msg); | |||
| 278 | xs_list *content_search(snac *user, const char *regex, | 278 | xs_list *content_search(snac *user, const char *regex, |
| 279 | int priv, int skip, int show, int max_secs, int *timeout); | 279 | int priv, int skip, int show, int max_secs, int *timeout); |
| 280 | 280 | ||
| 281 | int actor_failure(const char *actor, int op); | ||
| 281 | int instance_failure(const char *url, int op); | 282 | int instance_failure(const char *url, int op); |
| 282 | 283 | ||
| 283 | void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); | 284 | void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); |