Browse Source

MT#61977 turn DB writing into a notification

Change-Id: I7a3d0ad048bc88aa638adfc618c60fe510f254c4
pull/1998/head
Richard Fuchs 4 months ago
parent
commit
3670f75448
6 changed files with 59 additions and 25 deletions
  1. +48
    -20
      recording-daemon/db.c
  2. +1
    -1
      recording-daemon/db.h
  3. +1
    -1
      recording-daemon/notify.c
  4. +2
    -0
      recording-daemon/notify.h
  5. +1
    -2
      recording-daemon/output.c
  6. +6
    -1
      recording-daemon/types.h

+ 48
- 20
recording-daemon/db.c View File

@ -10,6 +10,7 @@
#include "tag.h"
#include "recaux.h"
#include "output.h"
#include "notify.h"
/*
@ -376,39 +377,66 @@ void db_close_call(metafile_t *mf) {
}
}
bool db_close_stream(output_t *op) {
if (check_conn() || op->db_id == 0)
return !(output_storage & OUTPUT_STORAGE_DB); // error if DB storage is requested
int64_t now = now_us();
static bool do_notify(notif_req_t *req) {
if (check_conn())
return false;
str stream = STR_NULL;
MYSQL_BIND b[3];
bool ok = true;
content_t *content = NULL;
if ((output_storage & OUTPUT_STORAGE_DB)) {
content = output_get_content(op);
if (content)
stream = STR_GS(content->s);
else
ok = false;
}
int par_idx = 0;
double ts;
my_ts(&b[par_idx++], now, &ts);
if ((output_storage & OUTPUT_STORAGE_DB))
my_ts(&b[par_idx++], req->end_time, &ts);
if (req->content) {
str stream = STR_GS(req->content->s);
my_str(&b[par_idx++], &stream);
my_ull(&b[par_idx++], &op->db_id);
}
my_ull(&b[par_idx++], &req->db_id);
execute_wrap(&stm_close_stream, b, NULL);
bool ok = execute_wrap(&stm_close_stream, b, NULL);
obj_release(content);
// running in a thread pool, don't leave connection behind
reset_conn();
return ok;
}
static void setup_notify(notif_req_t *req, output_t *o, metafile_t *mf, tag_t *tag) {
req->end_time = now_us();
if ((output_storage & OUTPUT_STORAGE_DB))
req->content = output_get_content(o);
}
static void cleanup_notify(notif_req_t *req) {
obj_release(req->content);
}
static const notif_action_t db_action = {
.name = "DB",
.setup = setup_notify,
.perform = do_notify,
.cleanup = cleanup_notify,
};
void db_close_stream(output_t *op) {
if (!c_mysql_host || !c_mysql_db)
return;
if (op->db_id == 0) {
if (!(output_storage & OUTPUT_STORAGE_DB))
return;
ilog(LOG_ERR, "DB storage requested but no entry exists");
content_t *content = output_get_content(op);
if (content)
output_content_failure(content);
obj_release(content);
}
notify_push_setup(&db_action, op, NULL, NULL);
}
void db_delete_stream(metafile_t *mf, output_t *op) {
if (check_conn())
return;


+ 1
- 1
recording-daemon/db.h View File

@ -7,7 +7,7 @@
void db_do_call(metafile_t *);
void db_close_call(metafile_t *);
void db_do_stream(metafile_t *mf, output_t *op, stream_t *, unsigned long ssrc);
bool db_close_stream(output_t *op);
void db_close_stream(output_t *op);
void db_delete_stream(metafile_t *, output_t *op);
void db_config_stream(output_t *op);
void db_thread_end(void);


+ 1
- 1
recording-daemon/notify.c View File

@ -372,7 +372,7 @@ static const notif_action_t command_action = {
static void notify_push_setup(const notif_action_t *action, output_t *o, metafile_t *mf, tag_t *tag) {
void notify_push_setup(const notif_action_t *action, output_t *o, metafile_t *mf, tag_t *tag) {
notif_req_t *req = g_new0(__typeof(*req), 1);
req->name = g_strdup_printf("%s for '%s'", action->name, o->file_name);


+ 2
- 0
recording-daemon/notify.h View File

@ -7,6 +7,8 @@
void notify_setup(void);
void notify_cleanup(void);
void notify_push_setup(const notif_action_t *action, output_t *o, metafile_t *mf, tag_t *tag);
void notify_push_output(output_t *, metafile_t *, tag_t *);
void notify_push_call(metafile_t *);


+ 1
- 2
recording-daemon/output.c View File

@ -672,8 +672,7 @@ void output_close(metafile_t *mf, output_t *output, tag_t *tag, bool discard) {
bool do_delete = !(output_storage & OUTPUT_STORAGE_FILE);
if (!discard) {
if (output_shutdown(output)) {
if (!db_close_stream(output))
do_delete = false;
db_close_stream(output);
notify_push_output(output, mf, tag);
}
else


+ 6
- 1
recording-daemon/types.h View File

@ -248,17 +248,22 @@ struct notif_req_s {
// generic HTTP req
struct {
struct curl_slist *headers;
content_t *content;
};
// notify command
struct {
char **argv;
};
// db writer
struct {
int64_t end_time;
};
};
// used by multiple actions
unsigned long long db_id;
content_t *content;
const notif_action_t *action;


Loading…
Cancel
Save