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()
|
||||
print('> fetch remote config')
|
||||
local message = { type = 'get-config' }
|
||||
local message = { type = 'register-and-get-config' }
|
||||
|
||||
local lastErrMessage = nil
|
||||
|
||||
|
||||
@ -89,25 +89,49 @@ end
|
||||
|
||||
-- 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
|
||||
print('get-config error: no computerId found')
|
||||
return nil
|
||||
end
|
||||
|
||||
local givenHarvesterId = message and message.payload and message.payload.id
|
||||
local config = getConfigForComputer(computerId)
|
||||
|
||||
local id = givenHarvesterId or computerId
|
||||
local config = getConfigForComputer(id)
|
||||
|
||||
if not givenHarvesterId and not config then
|
||||
if not config then
|
||||
print('new harvester detected: ' .. tostring(computerId))
|
||||
saveConfigForComputer(computerId, defaultConfig)
|
||||
config = defaultConfig
|
||||
end
|
||||
|
||||
return {
|
||||
type = "get-config/response",
|
||||
type = "register-and-get-config/response",
|
||||
payload = getConfigWithLength(config)
|
||||
}
|
||||
end
|
||||
@ -182,6 +206,7 @@ local function upgradeServer()
|
||||
end
|
||||
|
||||
local ROUTES = {
|
||||
['register-and-get-config'] = registerAndGetConfig,
|
||||
['get-config'] = getConfig,
|
||||
['set-config'] = setConfig,
|
||||
['delete-config'] = deleteConfig,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user