-
Notifications
You must be signed in to change notification settings - Fork 43
Adds description of the on_event callback to custom application roles #5232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
821385d
Adds description of the on_event callback to custom application roles
AArdeev e1b6d32
Fixes syntax
AArdeev f6586c4
Fixes syntax
AArdeev 37b4937
Fixes syntax
AArdeev 6b88463
Fixes syntax
AArdeev 823b33e
Fix lines
AArdeev bf6017e
fix lines
AArdeev baf94cc
Fix lines
AArdeev b093a53
syntax
AArdeev 75c4c33
syntax
AArdeev e09daeb
syntax
AArdeev 1a7b088
syntax
AArdeev 6743a6c
syntax
AArdeev 1507451
syntax
AArdeev 7b0a985
syntax
AArdeev ad4dcfa
Updates by comments
AArdeev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,13 +64,42 @@ 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 </release/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. | ||
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 returns 3 arguments, when it is called: | ||
|
||
- ``config``, which contains the configuration of the role; | ||
|
||
- ``key``, which reflects the trigger event and is set to: | ||
|
||
- ``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 the ``error`` level and the series execution continues. | ||
|
||
Creating a custom role includes the following steps: | ||
|
||
#. (Optional) Define the role configuration schema. | ||
#. Define a function that validates a role configuration. | ||
#. 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 +110,12 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to indent the function contents: 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, |
||
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. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.