You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/platform/app/app_roles.rst
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,13 +64,38 @@ Creating a custom role
64
64
Overview
65
65
~~~~~~~~
66
66
67
+
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.
68
+
For example, a logging role can be created to add logging functionality on top of the built-in one.
69
+
70
+
Since version :doc:`3.4.0 </release/3.4.0>`, you can define an ``on_event`` callback for custom roles. The ``on_event`` callback is called
71
+
every time a ``box.status`` system event is broadcasted, or after the ``apply`` action of the configuration update is finished.
72
+
If multiple custom roles have the ``on_event`` callback defined, these callbacks are called one after another in the order
73
+
defined by roles dependencies.
74
+
The ``on_event`` callback provides 3 arguments, when it is called:
75
+
76
+
- ``config``, which is the configuration of the role;
77
+
- ``key``, which reflects the trigger event:
78
+
- ``config.apply`` if the callback was triggered by a configuration update;
79
+
- ``box.status`` if it was triggered by the ``box.status`` system event.
80
+
- ``value``, which shows and logs the information about the instance status as in the trigger ``box.status`` system event.
81
+
If the callback is triggered by a configuration update, the ``value`` shows the information of the most recent ``box.status`` system event.
82
+
83
+
.. NOTE::
84
+
85
+
- All ``on_event`` callbacks with the ``config.apply`` key are executed as a part of the configuration
86
+
process. Process statuses ``ready`` or ``check_warnings`` are reached only after all such ``on_event`` callbacks are done.
87
+
- All ``on_event`` callbacks are executed inside of a ``pcall``. If an error is raised for a callback, it is logged with ``error`` level
88
+
and the series execution continues.
89
+
90
+
67
91
Creating a custom role includes the following steps:
68
92
69
93
#. (Optional) Define the role configuration schema.
70
94
#. Define a function that validates a role configuration.
71
95
#. Define a function that applies a validated configuration.
72
96
#. Define a function that stops a role.
73
97
#. (Optional) Define roles from which this custom role depends on.
98
+
#. (Optional) Define the ``on_event`` callback function.
74
99
75
100
As a result, a role module should return an object that has corresponding functions and fields specified:
76
101
@@ -81,6 +106,13 @@ As a result, a role module should return an object that has corresponding functi
0 commit comments