mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Deffered schema/instance updater for transaction
This commit is contained in:
parent
aa8af74249
commit
c4e1784be6
1 changed files with 56 additions and 11 deletions
|
|
@ -42,6 +42,9 @@ extern struct list_head json_memhead;
|
|||
|
||||
LIST_HEAD(head_registered_service);
|
||||
|
||||
static void register_periodic_timers(struct ubus_context *ctx);
|
||||
static void cancel_periodic_timers(struct ubus_context *ctx);
|
||||
|
||||
// Global variables
|
||||
static unsigned int g_refresh_time = BBF_INSTANCES_UPDATE_TIMEOUT;
|
||||
static int g_subprocess_level = BBF_SUBPROCESS_DEPTH;
|
||||
|
|
@ -882,6 +885,7 @@ static int bbfdm_transaction_handler(struct ubus_context *ctx, struct ubus_objec
|
|||
blob_buf_init(&data.bb, 0);
|
||||
|
||||
if (is_str_eq(trans_cmd, "start")) {
|
||||
cancel_periodic_timers(ctx);
|
||||
ret = transaction_start("API", max_timeout);
|
||||
if (ret) {
|
||||
blobmsg_add_u8(&data.bb, "status", true);
|
||||
|
|
@ -891,9 +895,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);
|
||||
ret = transaction_commit(data.trans_id, &data.bb, is_service_restart);
|
||||
blobmsg_add_u8(&data.bb, "status", (ret == 0));
|
||||
} else if (is_str_eq(trans_cmd, "abort")) {
|
||||
register_periodic_timers(ctx);
|
||||
ret = transaction_abort(data.trans_id, &data.bb);
|
||||
blobmsg_add_u8(&data.bb, "status", (ret == 0));
|
||||
} else if (is_str_eq(trans_cmd, "status")) {
|
||||
|
|
@ -1175,8 +1181,10 @@ static void instance_fork_done(struct uloop_process *p, int ret)
|
|||
INFO("Instance updater(%d) completed, starting a new instance timer", r->process.pid);
|
||||
struct bbfdm_context *u = (struct bbfdm_context *)r->result;
|
||||
|
||||
if (g_refresh_time != 0) {
|
||||
u->instance_timer.cb = periodic_instance_updater;
|
||||
uloop_timeout_set(&u->instance_timer, g_refresh_time);
|
||||
}
|
||||
free_path_list(&u->old_instances);
|
||||
async_req_free(r);
|
||||
}
|
||||
|
|
@ -1215,8 +1223,10 @@ static int fork_instance_checker(struct bbfdm_context *u)
|
|||
r = async_req_new();
|
||||
if (r == NULL) {
|
||||
ERR("Error allocating instance req");
|
||||
if (g_refresh_time != 0) {
|
||||
u->instance_timer.cb = periodic_instance_updater;
|
||||
uloop_timeout_set(&u->instance_timer, g_refresh_time);
|
||||
}
|
||||
free_path_list(&u->old_instances);
|
||||
goto err_out;
|
||||
}
|
||||
|
|
@ -1260,6 +1270,10 @@ static void periodic_instance_updater(struct uloop_timeout *t)
|
|||
{
|
||||
struct bbfdm_context *u;
|
||||
|
||||
if (g_refresh_time == 0) {
|
||||
return; // periodic refresh disabled
|
||||
}
|
||||
|
||||
u = container_of(t, struct bbfdm_context, instance_timer);
|
||||
if (u == NULL) {
|
||||
ERR("Failed to get the bbfdm context");
|
||||
|
|
@ -1441,6 +1455,43 @@ static void lookup_event_cb(struct ubus_context *ctx,
|
|||
}
|
||||
}
|
||||
|
||||
static void cancel_periodic_timers(struct ubus_context *ctx)
|
||||
{
|
||||
struct bbfdm_context *u;
|
||||
|
||||
u = container_of(ctx, struct bbfdm_context, ubus_ctx);
|
||||
if (u == NULL) {
|
||||
ERR("Failed to get the bbfdm context");
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG("Cancelling schema_timer and instance_timer");
|
||||
uloop_timeout_cancel(&u->schema_timer);
|
||||
if (g_refresh_time != 0) {
|
||||
uloop_timeout_cancel(&u->instance_timer);
|
||||
}
|
||||
}
|
||||
|
||||
static void register_periodic_timers(struct ubus_context *ctx)
|
||||
{
|
||||
struct bbfdm_context *u;
|
||||
|
||||
u = container_of(ctx, struct bbfdm_context, ubus_ctx);
|
||||
if (u == NULL) {
|
||||
ERR("Failed to get the bbfdm context");
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG("Register schema_timer %d and instance_timer %d", BBF_SCHEMA_UPDATE_TIMEOUT, g_refresh_time);
|
||||
u->schema_timer.cb = periodic_schema_updater;
|
||||
uloop_timeout_set(&u->schema_timer, BBF_SCHEMA_UPDATE_TIMEOUT);
|
||||
|
||||
if (g_refresh_time != 0) {
|
||||
u->instance_timer.cb = periodic_instance_updater;
|
||||
uloop_timeout_set(&u->instance_timer, g_refresh_time);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct bbfdm_context bbfdm_ctx;
|
||||
|
|
@ -1504,13 +1555,7 @@ int main(int argc, char **argv)
|
|||
if (err != 0)
|
||||
goto exit;
|
||||
|
||||
bbfdm_ctx.schema_timer.cb = periodic_schema_updater;
|
||||
uloop_timeout_set(&bbfdm_ctx.schema_timer, BBF_SCHEMA_UPDATE_TIMEOUT);
|
||||
|
||||
// initial timer should be bigger to give more space to other applications to initialize
|
||||
bbfdm_ctx.instance_timer.cb = periodic_instance_updater;
|
||||
uloop_timeout_set(&bbfdm_ctx.instance_timer, 3 * g_refresh_time);
|
||||
|
||||
register_periodic_timers(&bbfdm_ctx.ubus_ctx);
|
||||
} else { // It's a micro-service instance
|
||||
|
||||
err = bbfdm_init(&bbfdm_ctx.ubus_ctx);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue