From 0c379f9c2dd643f8d3040ab14cbb670456243803 Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Fri, 4 Jul 2025 17:00:02 +0300 Subject: [PATCH 01/16] Adds description of the on_event callback to custom application roles Added general info about custom roles as an intro to the section' Fixes #4666 --- doc/platform/app/app_roles.rst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 4d60a298c..5700908f5 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -64,6 +64,30 @@ Creating a custom role Overview ~~~~~~~~ +A custom application role is an object which implements custom functions or logic adding to Tarantool's built-in roles and roles provided by third-party Lua modules. +For example, a logging role can be created to add logging functionality on top of the built-in one. + +Since version :doc:`3.4.0 `, you can define an ``on_event`` callback for custom roles. The ``on_event`` callback is called +every time a ``box.status`` system event is broadcasted, or after the ``apply`` action of the configuration update is finished. +If multiple custom roles have the ``on_event`` callback defined, these callbacks are called one after another in the order +defined by roles dependencies. +The ``on_event`` callback provides 3 arguments, when it is called: + +- ``config``, which is the configuration of the role; +- ``key``, which reflects the trigger event: + - ``config.apply`` if the callback was triggered by a configuration update; + - ``box.status`` if it was triggered by the ``box.status`` system event. +- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. + If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. + +.. NOTE:: + + - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration + process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. + - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with ``error`` level + and the series execution continues. + + Creating a custom role includes the following steps: #. (Optional) Define the role configuration schema. @@ -71,6 +95,7 @@ Creating a custom role includes the following steps: #. Define a function that applies a validated configuration. #. Define a function that stops a role. #. (Optional) Define roles from which this custom role depends on. +#. (Optional) Define the ``on_event`` callback function. As a result, a role module should return an object that has corresponding functions and fields specified: @@ -81,6 +106,13 @@ As a result, a role module should return an object that has corresponding functi apply = function() -- ... -- end, stop = function() -- ... -- end, dependencies = { -- ... -- }, + on_event = function(config, key, value) + local log = require('log') + + log.info('roles_cfg.my_role.foo: ' .. config.foo) + log.info('on_event is triggered by ' .. key) + log.info('is_ro: ' .. value.is_ro) + end, } The examples below show how to do this. From 89972c3748211f7bff2900caa396167600b099cb Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Fri, 4 Jul 2025 17:13:05 +0300 Subject: [PATCH 02/16] Fixes syntax --- doc/platform/app/app_roles.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 5700908f5..3a19cd3ee 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -74,16 +74,17 @@ defined by roles dependencies. The ``on_event`` callback provides 3 arguments, when it is called: - ``config``, which is the configuration of the role; -- ``key``, which reflects the trigger event: +- ``key``, which reflects the trigger event: - ``config.apply`` if the callback was triggered by a configuration update; - ``box.status`` if it was triggered by the ``box.status`` system event. -- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. +- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. .. NOTE:: - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. + - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with ``error`` level and the series execution continues. From 7e80aaf157345c11c85b6e9da44e2bd697a8688d Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Fri, 4 Jul 2025 17:22:03 +0300 Subject: [PATCH 03/16] Fixes syntax --- doc/platform/app/app_roles.rst | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 3a19cd3ee..12da94033 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -73,11 +73,13 @@ If multiple custom roles have the ``on_event`` callback defined, these callbacks defined by roles dependencies. The ``on_event`` callback provides 3 arguments, when it is called: -- ``config``, which is the configuration of the role; -- ``key``, which reflects the trigger event: - - ``config.apply`` if the callback was triggered by a configuration update; - - ``box.status`` if it was triggered by the ``box.status`` system event. -- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. + - ``config``, which is the configuration of the role; + + - ``key``, which reflects the trigger event: + + - ``config.apply`` if the callback was triggered by a configuration update; + - ``box.status`` if it was triggered by the ``box.status`` system event. + - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. .. NOTE:: @@ -110,10 +112,10 @@ As a result, a role module should return an object that has corresponding functi on_event = function(config, key, value) local log = require('log') - log.info('roles_cfg.my_role.foo: ' .. config.foo) - log.info('on_event is triggered by ' .. key) - log.info('is_ro: ' .. value.is_ro) - end, + log.info('roles_cfg.my_role.foo: ' .. config.foo) + log.info('on_event is triggered by ' .. key) + log.info('is_ro: ' .. value.is_ro) + end, } The examples below show how to do this. From 0e94e65346328f2e2ee2ef2cf4c0e0ed635d461d Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Fri, 4 Jul 2025 17:24:28 +0300 Subject: [PATCH 04/16] Fixes syntax --- doc/platform/app/app_roles.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 12da94033..5764771a6 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -90,7 +90,6 @@ The ``on_event`` callback provides 3 arguments, when it is called: - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with ``error`` level and the series execution continues. - Creating a custom role includes the following steps: #. (Optional) Define the role configuration schema. From 0a1eddb48a881c58f47d80c2c49b9cc0f946ad6f Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Fri, 4 Jul 2025 17:34:44 +0300 Subject: [PATCH 05/16] Fixes syntax --- doc/platform/app/app_roles.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 5764771a6..71bf54004 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -84,8 +84,8 @@ The ``on_event`` callback provides 3 arguments, when it is called: .. NOTE:: - - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration - process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. + - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. + Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with ``error`` level and the series execution continues. From 286405edd17b6d5b2ae3589562bfb25bc9b305a7 Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Fri, 4 Jul 2025 17:46:13 +0300 Subject: [PATCH 06/16] Fix lines --- doc/platform/app/app_roles.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 71bf54004..958092b94 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -79,16 +79,16 @@ The ``on_event`` callback provides 3 arguments, when it is called: - ``config.apply`` if the callback was triggered by a configuration update; - ``box.status`` if it was triggered by the ``box.status`` system event. - - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. + - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. .. NOTE:: - - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. + - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. - - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with ``error`` level - and the series execution continues. + - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with + the ``error`` level and the series execution continues. Creating a custom role includes the following steps: From 4bcac746536fd38b3ca9a07cf7a0a6ba0b3725f8 Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Fri, 4 Jul 2025 18:44:53 +0300 Subject: [PATCH 07/16] fix lines --- doc/platform/app/app_roles.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 958092b94..2502f5c19 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -71,6 +71,7 @@ Since version :doc:`3.4.0 `, you can define an ``on_event`` call every time a ``box.status`` system event is broadcasted, or after the ``apply`` action of the configuration update is finished. If multiple custom roles have the ``on_event`` callback defined, these callbacks are called one after another in the order defined by roles dependencies. + The ``on_event`` callback provides 3 arguments, when it is called: - ``config``, which is the configuration of the role; From 5c143de33435c0523669e9242d6c027358a37cec Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Fri, 4 Jul 2025 18:59:16 +0300 Subject: [PATCH 08/16] Fix lines --- doc/platform/app/app_roles.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 2502f5c19..625223da0 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -74,12 +74,12 @@ defined by roles dependencies. The ``on_event`` callback provides 3 arguments, when it is called: - - ``config``, which is the configuration of the role; + - ``config``, which contains the configuration of the role; - ``key``, which reflects the trigger event: - - - ``config.apply`` if the callback was triggered by a configuration update; + - ``config.apply`` if the callback was triggered by a configuration update; - ``box.status`` if it was triggered by the ``box.status`` system event. + - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. From d353797d991145968201e69576329c4912aff9eb Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Mon, 7 Jul 2025 08:18:12 +0300 Subject: [PATCH 09/16] syntax --- doc/platform/app/app_roles.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 625223da0..6fae3636a 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -80,16 +80,13 @@ The ``on_event`` callback provides 3 arguments, when it is called: - ``config.apply`` if the callback was triggered by a configuration update; - ``box.status`` if it was triggered by the ``box.status`` system event. - - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. - If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. + - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. .. NOTE:: - - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. - Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. + - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. - - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with - the ``error`` level and the series execution continues. + - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with the ``error`` level and the series execution continues. Creating a custom role includes the following steps: From 44ac245593fa792a1181bb56f421bfd2c5457dd9 Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Mon, 7 Jul 2025 09:16:07 +0300 Subject: [PATCH 10/16] syntax --- doc/platform/app/app_roles.rst | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 6fae3636a..950959d21 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -74,19 +74,21 @@ defined by roles dependencies. The ``on_event`` callback provides 3 arguments, when it is called: - - ``config``, which contains the configuration of the role; +- ``config``, which contains the configuration of the role; - - ``key``, which reflects the trigger event: - - ``config.apply`` if the callback was triggered by a configuration update; - - ``box.status`` if it was triggered by the ``box.status`` system event. - - - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. +- ``key``, which reflects the trigger event: + - ``config.apply`` if the callback was triggered by a configuration update; + - ``box.status`` if it was triggered by the ``box.status`` system event. +- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. +If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. .. NOTE:: - - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. + - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. + Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. - - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with the ``error`` level and the series execution continues. + - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged + with the ``error`` level and the series execution continues. Creating a custom role includes the following steps: From bc3060f5cd261799786be87ec0c2c92ccb2cc147 Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Mon, 7 Jul 2025 09:37:17 +0300 Subject: [PATCH 11/16] syntax --- doc/platform/app/app_roles.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 950959d21..1e1141f07 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -77,8 +77,11 @@ The ``on_event`` callback provides 3 arguments, when it is called: - ``config``, which contains the configuration of the role; - ``key``, which reflects the trigger event: + - ``config.apply`` if the callback was triggered by a configuration update; + - ``box.status`` if it was triggered by the ``box.status`` system event. + - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. From 6ec6a0964beffac56588b3df5cc6c62943c41cc3 Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Mon, 7 Jul 2025 10:30:32 +0300 Subject: [PATCH 12/16] syntax --- doc/platform/app/app_roles.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 1e1141f07..a9f121845 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -72,11 +72,11 @@ every time a ``box.status`` system event is broadcasted, or after the ``apply`` If multiple custom roles have the ``on_event`` callback defined, these callbacks are called one after another in the order defined by roles dependencies. -The ``on_event`` callback provides 3 arguments, when it is called: +The ``on_event`` callback returns 3 arguments, when it is called: - ``config``, which contains the configuration of the role; -- ``key``, which reflects the trigger event: +- ``key``, which reflects the trigger event and is set to: - ``config.apply`` if the callback was triggered by a configuration update; @@ -87,11 +87,11 @@ If the callback is triggered by a configuration update, the ``value`` shows the .. NOTE:: - - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. - Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. + - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. + Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. - - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged - with the ``error`` level and the series execution continues. + - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, + it is logged with the ``error`` level and the series execution continues. Creating a custom role includes the following steps: From e58e6268e2287096a646bd5ea39203eb7d2940ac Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Mon, 7 Jul 2025 10:49:28 +0300 Subject: [PATCH 13/16] syntax --- doc/platform/app/app_roles.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index a9f121845..db21400f5 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -81,17 +81,16 @@ The ``on_event`` callback returns 3 arguments, when it is called: - ``config.apply`` if the callback was triggered by a configuration update; - ``box.status`` if it was triggered by the ``box.status`` system event. - - ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. .. NOTE:: - - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. - Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. +- All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. +Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. - - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, - it is logged with the ``error`` level and the series execution continues. +- All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, +it is logged with the ``error`` level and the series execution continues. Creating a custom role includes the following steps: From 6e8bd11ce6c304b9eb342443e44a1711af68b10f Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Mon, 7 Jul 2025 12:29:59 +0300 Subject: [PATCH 14/16] syntax --- doc/platform/app/app_roles.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index db21400f5..8e6033314 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -81,16 +81,13 @@ The ``on_event`` callback returns 3 arguments, when it is called: - ``config.apply`` if the callback was triggered by a configuration update; - ``box.status`` if it was triggered by the ``box.status`` system event. -- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. -If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. +- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. .. NOTE:: -- All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. -Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. + - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. -- All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, -it is logged with the ``error`` level and the series execution continues. + - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with the ``error`` level and the series execution continues. Creating a custom role includes the following steps: From 43644754f244e7617bd62875fcd840304b2cf8f6 Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Mon, 7 Jul 2025 13:36:44 +0300 Subject: [PATCH 15/16] syntax --- doc/platform/app/app_roles.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index 8e6033314..f6757cb94 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -81,13 +81,16 @@ The ``on_event`` callback returns 3 arguments, when it is called: - ``config.apply`` if the callback was triggered by a configuration update; - ``box.status`` if it was triggered by the ``box.status`` system event. -- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. +- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event. + If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event. .. NOTE:: - - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. + - All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration process. + Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done. - - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with the ``error`` level and the series execution continues. + - All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged + with the ``error`` level and the series execution continues. Creating a custom role includes the following steps: From d4cba2f0a51a511dd4e3bef845b914ca32e8520f Mon Sep 17 00:00:00 2001 From: "a.ardeev" Date: Tue, 8 Jul 2025 16:01:10 +0300 Subject: [PATCH 16/16] Updates by comments --- doc/platform/app/app_roles.rst | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/doc/platform/app/app_roles.rst b/doc/platform/app/app_roles.rst index f6757cb94..03956cb73 100644 --- a/doc/platform/app/app_roles.rst +++ b/doc/platform/app/app_roles.rst @@ -68,7 +68,7 @@ A custom application role is an object which implements custom functions or logi For example, a logging role can be created to add logging functionality on top of the built-in one. Since version :doc:`3.4.0 `, you can define an ``on_event`` callback for custom roles. The ``on_event`` callback is called -every time a ``box.status`` system event is broadcasted, or after the ``apply`` action of the configuration update is finished. +every time a ``box.status`` system event is broadcasted. If multiple custom roles have the ``on_event`` callback defined, these callbacks are called one after another in the order defined by roles dependencies. @@ -111,11 +111,10 @@ As a result, a role module should return an object that has corresponding functi stop = function() -- ... -- end, dependencies = { -- ... -- }, on_event = function(config, key, value) - local log = require('log') - - log.info('roles_cfg.my_role.foo: ' .. config.foo) - log.info('on_event is triggered by ' .. key) - log.info('is_ro: ' .. value.is_ro) + local log = require('log') + log.info('roles_cfg.my_role.foo: ' .. config.foo) + log.info('on_event is triggered by ' .. key) + log.info('is_ro: ' .. value.is_ro) end, }