refactor(inferium)!: replace get-config by register-and-get-config
This commit is contained in:
parent
9b9b312a2e
commit
88d7b6dcc8
@ -321,7 +321,7 @@ end
|
|||||||
|
|
||||||
local function fetchRemoteConfig()
|
local function fetchRemoteConfig()
|
||||||
print('> fetch remote config')
|
print('> fetch remote config')
|
||||||
local message = { type = 'get-config' }
|
local message = { type = 'register-and-get-config' }
|
||||||
|
|
||||||
local lastErrMessage = nil
|
local lastErrMessage = nil
|
||||||
|
|
||||||
|
|||||||
@ -89,25 +89,49 @@ end
|
|||||||
|
|
||||||
-- Routes
|
-- Routes
|
||||||
|
|
||||||
local function getConfig(message, computerId)
|
local function getConfig(message)
|
||||||
|
local id = message and message.payload and message.payload.id
|
||||||
|
|
||||||
|
if not id then
|
||||||
|
return {
|
||||||
|
type = "get-config/error",
|
||||||
|
payload = nil,
|
||||||
|
errorMessage = "no id provided in message payload"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local config = getConfigForComputer(id)
|
||||||
|
|
||||||
|
if not config then
|
||||||
|
return {
|
||||||
|
type = "get-config/error",
|
||||||
|
payload = nil,
|
||||||
|
errorMessage = "cannot retrieve configuration for given id"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
type = "get-config/response",
|
||||||
|
payload = getConfigWithLength(config)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function registerAndGetConfig(_, computerId)
|
||||||
if not computerId == nil then
|
if not computerId == nil then
|
||||||
print('get-config error: no computerId found')
|
print('get-config error: no computerId found')
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local givenHarvesterId = message and message.payload and message.payload.id
|
local config = getConfigForComputer(computerId)
|
||||||
|
|
||||||
local id = givenHarvesterId or computerId
|
if not config then
|
||||||
local config = getConfigForComputer(id)
|
|
||||||
|
|
||||||
if not givenHarvesterId and not config then
|
|
||||||
print('new harvester detected: ' .. tostring(computerId))
|
print('new harvester detected: ' .. tostring(computerId))
|
||||||
saveConfigForComputer(computerId, defaultConfig)
|
saveConfigForComputer(computerId, defaultConfig)
|
||||||
config = defaultConfig
|
config = defaultConfig
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type = "get-config/response",
|
type = "register-and-get-config/response",
|
||||||
payload = getConfigWithLength(config)
|
payload = getConfigWithLength(config)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -182,6 +206,7 @@ local function upgradeServer()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local ROUTES = {
|
local ROUTES = {
|
||||||
|
['register-and-get-config'] = registerAndGetConfig,
|
||||||
['get-config'] = getConfig,
|
['get-config'] = getConfig,
|
||||||
['set-config'] = setConfig,
|
['set-config'] = setConfig,
|
||||||
['delete-config'] = deleteConfig,
|
['delete-config'] = deleteConfig,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user