mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-03-14 13:10:28 +01:00
ubus: add retry mechanism for schema fetching
This commit is contained in:
parent
aa1bfa186b
commit
94e4443801
2 changed files with 19 additions and 8 deletions
|
|
@ -177,7 +177,7 @@ static void bbfdm_ubus_add_event_cb(struct ubus_context *ctx, struct ubus_event_
|
|||
service->is_blacklisted = false;
|
||||
service->consecutive_timeouts = 0;
|
||||
service_found = true;
|
||||
fill_service_schema(ctx, 5000, service->name, &service->dm_schema);
|
||||
fill_service_schema(ctx, 2000, service->name, &service->dm_schema);
|
||||
BBFDM_INFO("Service '%s' found in registry. Resetting blacklist and timeout counters.", path);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ static void receive_schema_result(struct ubus_request *req, int type __attribute
|
|||
void fill_service_schema(struct ubus_context *ubus_ctx, int ubus_timeout, const char *service_name, struct blob_buf **service_schema)
|
||||
{
|
||||
uint32_t ubus_id;
|
||||
int retry;
|
||||
|
||||
if (!ubus_ctx || !service_name || !service_schema)
|
||||
return;
|
||||
|
|
@ -82,7 +83,12 @@ void fill_service_schema(struct ubus_context *ubus_ctx, int ubus_timeout, const
|
|||
BBFDM_FREE(*service_schema);
|
||||
}
|
||||
|
||||
if (!ubus_lookup_id(ubus_ctx, service_name, &ubus_id)) {
|
||||
for (retry = 0; retry < 5; retry++) {
|
||||
if (ubus_lookup_id(ubus_ctx, service_name, &ubus_id)) {
|
||||
BBFDM_WARNING("Failed to lookup UBUS object: %s (attempt %d/5)", service_name, retry + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
struct blob_buf bb = {0};
|
||||
|
||||
*service_schema = (struct blob_buf *)calloc(1, sizeof(struct blob_buf));
|
||||
|
|
@ -104,14 +110,19 @@ void fill_service_schema(struct ubus_context *ubus_ctx, int ubus_timeout, const
|
|||
|
||||
int err = ubus_invoke(ubus_ctx, ubus_id, "schema", bb.head, receive_schema_result, (void *)*service_schema, ubus_timeout);
|
||||
|
||||
if (err != 0) {
|
||||
BBFDM_ERR("UBUS invoke failed [object: %s, method: schema] with error (%d)", service_name, err);
|
||||
}
|
||||
|
||||
blob_buf_free(&bb);
|
||||
} else {
|
||||
BBFDM_WARNING("Failed to lookup UBUS object: %s", service_name);
|
||||
|
||||
if (err == 0)
|
||||
break;
|
||||
|
||||
BBFDM_WARNING("UBUS invoke failed [object: %s, method: schema] with error (%d) (attempt %d/5)", service_name, err, retry + 1);
|
||||
|
||||
blob_buf_free(*service_schema);
|
||||
BBFDM_FREE(*service_schema);
|
||||
}
|
||||
|
||||
if (*service_schema == NULL)
|
||||
BBFDM_WARNING("Failed to fetch schema for service '%s' after 5 attempts", service_name);
|
||||
}
|
||||
|
||||
static int load_service_from_file(struct ubus_context *ubus_ctx, const char *filename, const char *file_path)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue