Skip to content
Snippets Groups Projects
Commit cac50493 authored by Mergen Imeev's avatar Mergen Imeev Committed by Alexander Turenko
Browse files

config: add current status broadcasting

This patch implements broadcastion of the current statusi.

NO_DOC=will be added later
NO_CHANGELOG=will be added later
parent 18ed6b6f
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,10 @@ local function selfcheck(self, method_name)
end
end
local function broadcast(self)
box.broadcast('config.info', self:info())
end
function methods._alert(self, alert)
assert(alert.type == 'error' or alert.type == 'warn')
if alert.type == 'error' then
......@@ -233,11 +237,13 @@ function methods._startup(self, instance_name, config_file)
self._status = 'startup_in_progress'
self._instance_name = instance_name
self._config_file = config_file
broadcast(self)
self:_initialize()
self:_collect({sync_source = 'all'})
self:_apply()
self._status = 'ready'
broadcast(self)
end
function methods.get(self, path)
......@@ -260,6 +266,7 @@ function methods._reload_noexc(self, opts)
'progress'
end
self._status = 'reload_in_progress'
broadcast(self)
self._alerts = {}
local ok, err = pcall(self._collect, self, opts)
......@@ -282,6 +289,7 @@ function methods._reload_noexc(self, opts)
status = 'check_warnings'
end
self._status = status
broadcast(self)
return ok, err
end
......
......@@ -195,3 +195,59 @@ g.test_config_general = function()
"not be set until the instance is restarted"
t.assert_equals(info.new[1].message, exp)
end
g.test_config_broadcast = function()
local dir = treegen.prepare_directory(g, {}, {})
local file_config = [[
app:
file: 'script.lua'
groups:
group-001:
replicasets:
replicaset-001:
instances:
instance-001:
database:
rw: true
]]
treegen.write_script(dir, 'config.yaml', file_config)
local main = [[
local fiber = require('fiber')
local config = require('config')
local status = ''
box.watch('config.info', function(_, v) status = v.status end)
config:_startup('instance-001', 'config.yaml')
while status ~= 'ready' do
fiber.sleep(0.1)
end
print(status)
config:reload()
while status ~= 'ready' do
fiber.sleep(0.1)
end
print(status)
os.exit(0)
]]
treegen.write_script(dir, 'main.lua', main)
local script = [[
local fiber = require('fiber')
local status = ''
box.watch('config.info', function(_, v) status = v.status end)
while status ~= 'startup_in_progress' and
status ~= 'reload_in_progress' do
fiber.sleep(0.1)
end
print(status)
]]
treegen.write_script(dir, 'script.lua', script)
local opts = {nojson = true, stderr = false}
local args = {'main.lua'}
local res = justrun.tarantool(dir, {}, args, opts)
t.assert_equals(res.exit_code, 0)
local exp = {'startup_in_progress', 'ready', 'reload_in_progress', 'ready'}
t.assert_equals(res.stdout, table.concat(exp, "\n"))
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment