mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Start refresh timer after transaction commit
This commit is contained in:
parent
533c1bfa7c
commit
ec0fba3fb5
2 changed files with 34 additions and 15 deletions
|
|
@ -43,12 +43,14 @@ extern struct list_head json_memhead;
|
|||
// micro-services should not use fork by default
|
||||
#define BBF_SUBPROCESS_DEPTH (0)
|
||||
// default instance updater timeout
|
||||
#define BBF_INSTANCES_UPDATE_TIMEOUT (30 * 1000)
|
||||
#define BBF_INSTANCES_UPDATE_TIMEOUT (60 * 1000)
|
||||
|
||||
LIST_HEAD(head_registered_service);
|
||||
|
||||
static void cancel_periodic_timers(struct ubus_context *ctx);
|
||||
static void run_schema_updater(struct bbfdm_context *u);
|
||||
static void periodic_instance_updater(struct uloop_timeout *t);
|
||||
static void register_instance_refresh_timer(struct ubus_context *ctx, int start_sec);
|
||||
|
||||
// Global variables
|
||||
static void *deamon_lib_handle = NULL;
|
||||
|
|
@ -58,7 +60,7 @@ static void sig_handler(int sig)
|
|||
if (sig == SIGSEGV) {
|
||||
handle_pending_signal(sig);
|
||||
} else if (sig == SIGUSR1) {
|
||||
ERR("# Exception in PID[%ld]", getpid());
|
||||
ERR("# SIGUSR1 handler for main process PID[%ld]", getpid());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -593,6 +595,7 @@ int bbfdm_set_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (data.trans_id == 0) {
|
||||
// Transaction-id is not defined so create an internal transaction
|
||||
cancel_periodic_timers(ctx);
|
||||
trans_id = transaction_start(&data, "INT_SET", 0);
|
||||
if (trans_id == 0) {
|
||||
WARNING("Failed to get the lock for the transaction");
|
||||
|
|
@ -605,6 +608,7 @@ int bbfdm_set_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (data.trans_id == 0) {
|
||||
// Internal transaction: need to commit the changes
|
||||
register_instance_refresh_timer(ctx, 100);
|
||||
transaction_commit(NULL, trans_id, true);
|
||||
}
|
||||
|
||||
|
|
@ -713,6 +717,7 @@ int bbfdm_add_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (data.trans_id == 0) {
|
||||
// Transaction-id is not defined so create an internal transaction
|
||||
cancel_periodic_timers(ctx);
|
||||
trans_id = transaction_start(&data, "INT_ADD", 0);
|
||||
if (trans_id == 0) {
|
||||
ERR("Failed to get the lock for the transaction");
|
||||
|
|
@ -727,6 +732,7 @@ int bbfdm_add_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (data.trans_id == 0) {
|
||||
// Internal transaction: need to abort the changes
|
||||
register_instance_refresh_timer(ctx, 0);
|
||||
transaction_abort(NULL, trans_id);
|
||||
}
|
||||
|
||||
|
|
@ -745,6 +751,7 @@ int bbfdm_add_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (data.trans_id == 0) {
|
||||
// Internal transaction: need to abort the changes
|
||||
register_instance_refresh_timer(ctx, 0);
|
||||
transaction_abort(NULL, trans_id);
|
||||
}
|
||||
|
||||
|
|
@ -761,6 +768,7 @@ int bbfdm_add_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (data.trans_id == 0) {
|
||||
// Internal transaction: need to commit the changes
|
||||
register_instance_refresh_timer(ctx, 100);
|
||||
transaction_commit(NULL, trans_id, true);
|
||||
}
|
||||
|
||||
|
|
@ -836,6 +844,7 @@ int bbfdm_del_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (data.trans_id == 0) {
|
||||
// Transaction-id is not defined so create an internal transaction
|
||||
cancel_periodic_timers(ctx);
|
||||
trans_id = transaction_start(&data, "INT_DEL", 0);
|
||||
if (trans_id == 0) {
|
||||
WARNING("Failed to get the lock for the transaction");
|
||||
|
|
@ -848,6 +857,7 @@ int bbfdm_del_handler(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
if (data.trans_id == 0) {
|
||||
// Internal transaction: need to commit the changes
|
||||
register_instance_refresh_timer(ctx, 100);
|
||||
transaction_commit(NULL, trans_id, true);
|
||||
}
|
||||
|
||||
|
|
@ -925,11 +935,11 @@ static int bbfdm_transaction_handler(struct ubus_context *ctx, struct ubus_objec
|
|||
transaction_status(&data.bb);
|
||||
}
|
||||
} else if (is_str_eq(trans_cmd, "commit")) {
|
||||
register_periodic_timers(ctx);
|
||||
register_instance_refresh_timer(ctx, 100);
|
||||
ret = transaction_commit(&data, data.trans_id, is_service_restart);
|
||||
blobmsg_add_u8(&data.bb, "status", (ret == 0));
|
||||
} else if (is_str_eq(trans_cmd, "abort")) {
|
||||
register_periodic_timers(ctx);
|
||||
register_instance_refresh_timer(ctx, 0);
|
||||
ret = transaction_abort(&data, data.trans_id);
|
||||
blobmsg_add_u8(&data.bb, "status", (ret == 0));
|
||||
} else if (is_str_eq(trans_cmd, "status")) {
|
||||
|
|
@ -1214,7 +1224,6 @@ static void update_instances_list(struct list_head *inst)
|
|||
bbf_cleanup(&bbf_ctx);
|
||||
}
|
||||
|
||||
static void periodic_instance_updater(struct uloop_timeout *t);
|
||||
static void instance_fork_done(struct uloop_process *p, int ret)
|
||||
{
|
||||
struct bbfdm_async_req *r = container_of(p, struct bbfdm_async_req, process);
|
||||
|
|
@ -1337,11 +1346,15 @@ static void periodic_instance_updater(struct uloop_timeout *t)
|
|||
}
|
||||
|
||||
if (list_empty(&u->instances)) {
|
||||
update_instances_list(&u->instances);
|
||||
DEBUG("Creating timer for instance update checker, init instances");
|
||||
u->instance_timer.cb = periodic_instance_updater;
|
||||
uloop_timeout_set(&u->instance_timer, u->config.refresh_time);
|
||||
return;
|
||||
if (!list_empty(&u->old_instances)) {
|
||||
list_splice_init(&u->old_instances, &u->instances);
|
||||
} else {
|
||||
update_instances_list(&u->instances);
|
||||
DEBUG("Creating timer for instance update checker, init instances");
|
||||
u->instance_timer.cb = periodic_instance_updater;
|
||||
uloop_timeout_set(&u->instance_timer, u->config.refresh_time);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
free_path_list(&u->old_instances);
|
||||
|
|
@ -1648,9 +1661,10 @@ static void cancel_periodic_timers(struct ubus_context *ctx)
|
|||
}
|
||||
}
|
||||
|
||||
void register_periodic_timers(struct ubus_context *ctx)
|
||||
static void register_instance_refresh_timer(struct ubus_context *ctx, int start_in)
|
||||
{
|
||||
struct bbfdm_context *u;
|
||||
unsigned refresh_time = 0;
|
||||
|
||||
u = container_of(ctx, struct bbfdm_context, ubus_ctx);
|
||||
if (u == NULL) {
|
||||
|
|
@ -1658,10 +1672,16 @@ void register_periodic_timers(struct ubus_context *ctx)
|
|||
return;
|
||||
}
|
||||
|
||||
DEBUG("Register instance_timer %d", u->config.refresh_time);
|
||||
if (start_in <= 0) {
|
||||
refresh_time = u->config.refresh_time;
|
||||
} else {
|
||||
refresh_time = start_in;
|
||||
}
|
||||
|
||||
DEBUG("Register instance refresh timer in %d ms...", refresh_time);
|
||||
if (u->config.refresh_time != 0) {
|
||||
u->instance_timer.cb = periodic_instance_updater;
|
||||
uloop_timeout_set(&u->instance_timer, u->config.refresh_time);
|
||||
uloop_timeout_set(&u->instance_timer, refresh_time);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1791,12 +1811,12 @@ int main(int argc, char **argv)
|
|||
ubus_add_uloop(&bbfdm_ctx.ubus_ctx);
|
||||
ubus_init_done = true;
|
||||
|
||||
periodic_instance_updater(&bbfdm_ctx.instance_timer);
|
||||
err = bbfdm_regiter_ubus(&bbfdm_ctx.ubus_ctx);
|
||||
if (err != UBUS_STATUS_OK)
|
||||
goto exit;
|
||||
|
||||
run_schema_updater(&bbfdm_ctx);
|
||||
register_instance_refresh_timer(&bbfdm_ctx.ubus_ctx, 1000);
|
||||
|
||||
err = register_events_to_ubus(&bbfdm_ctx.ubus_ctx, &bbfdm_ctx.event_handlers);
|
||||
if (err != 0)
|
||||
|
|
|
|||
|
|
@ -67,5 +67,4 @@ typedef struct bbfdm_data {
|
|||
int trans_id;
|
||||
} bbfdm_data_t;
|
||||
|
||||
void register_periodic_timers(struct ubus_context *ctx);
|
||||
#endif /* BBFDMD_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue