forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: allow to call config:get() from app script
It is convenient to access configuration using `config:get()` from the application script (`app.file` or `app.module`). However, before this commit, it was not possible, because the configuration was not considered as applied before the application script is loaded. Now, the script loading is moved into the post-apply phase. The resulting sequence of steps on startup/reload is the following. * collect configuration information (from all the sources) * <if the previous step is failed, set `check_errors` status and break> * apply the configuration (call all the appliers) * <if the previous step is failed, set `check_errors` status and break> * <set the new successful status: `ready` or `check_warnings`> * call post-apply hooks (including application script loading) * <if the previous step is failed, set `check_errors` status and break> * <set the new successful status: `ready` or `check_warnings`> I would like to briefly comment the changes in the tests. * `app_test.lua`: added the check for the new behavior (call config:get() from the app script) * `appliers_test.lua`: fixed the applier call (`.apply` -> `.post_apply`) * `config_test.lua`: fixed status observed in the app script (`*_in_progress` -> `ready`) Part of tarantool#8862 NO_DOC=reflected in tarantool/doc#3544
- Loading branch information
1 parent
06ca83c
commit 0cb9101
Showing
6 changed files
with
57 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## feature/config | ||
|
||
* It is now possible to access configuration from the application script using | ||
the `config:get()` method (gh-8862). |
This file contains 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 |
---|---|---|
@@ -1,21 +1,26 @@ | ||
local log = require('internal.config.utils.log') | ||
|
||
local function apply(config) | ||
local function apply(_config) | ||
log.verbose('app.apply: do nothing') | ||
end | ||
|
||
local function post_apply(config) | ||
local configdata = config._configdata | ||
local file = configdata:get('app.file', {use_default = true}) | ||
local module = configdata:get('app.module', {use_default = true}) | ||
if file ~= nil then | ||
assert(module == nil) | ||
local fn = assert(loadfile(file)) | ||
log.verbose('app.apply: loading '..file) | ||
log.verbose('app.post_apply: loading '..file) | ||
fn(file) | ||
elseif module ~= nil then | ||
log.verbose('app.apply: loading '..module) | ||
log.verbose('app.post_apply: loading '..module) | ||
require(module) | ||
end | ||
end | ||
|
||
return { | ||
name = 'app', | ||
apply = apply, | ||
post_apply = post_apply, | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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