refactor: merge action handling blocks in play() functions

Merge the two separate if blocks for handling actions into a single block
since they both use the same logic for getting the name parameter with
get_default('name', 'default').

Changes:
- Combine destroy/install/build and start/stop/restart/lifecycle blocks
- All actions now use consistent name parameter handling
- Reduces code duplication in play() functions

Updated files:
- All 5 horus installer factory files
- Generator template objname_factory_.vtemplate
This commit is contained in:
Timur Gordon
2025-11-19 15:44:50 +01:00
parent 856a6202ee
commit a5c4b8f6f8
6 changed files with 14 additions and 47 deletions

View File

@@ -169,7 +169,11 @@ pub fn play(mut plbook PlayBook) ! {
@if args.cat == .installer
mut other_actions := plbook.find(filter: '${args.name}.')!
for mut other_action in other_actions {
@if args.startupmanager
if other_action.name in ["destroy","install","build","start","stop","restart","start_pre","start_post","stop_pre","stop_post"]{
@else
if other_action.name in ["destroy","install","build"]{
@end
mut p := other_action.params
name := p.get_default('name', 'default')!
reset:=p.get_default_false("reset")
@@ -188,13 +192,7 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug("install action ${args.name}.build")
${args.name}_obj.build()!
}
}
@if args.startupmanager
if other_action.name in ["start","stop","restart","start_pre","start_post","stop_pre","stop_post"]{
mut p := other_action.params
name := p.get('name')!
mut ${args.name}_obj:=get(name:name)!
console.print_debug("action object:\n??{${args.name}_obj}")
@if args.startupmanager
if other_action.name == "start"{
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.start()!
@@ -223,8 +221,8 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.stop_post()!
}
@end
}
@end
other_action.done = true
}
@end

View File

@@ -38,13 +38,13 @@ pub fn new(args ArgsGet) !&Coordinator {
log_level: args.log_level
repo_path: args.repo_path
}
// Try to set in Redis, if it fails (Redis not available), use in-memory config
set(obj) or {
console.print_debug('Redis not available, using in-memory configuration')
set_in_mem(obj)!
}
return get(name: args.name)!
}
@@ -154,13 +154,13 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'coordinator.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')
mut coordinator_obj := get(name: name)!
console.print_debug('action object:\n${coordinator_obj}')
if other_action.name == 'destroy' || reset {
console.print_debug('install action coordinator.destroy')
coordinator_obj.destroy()!
@@ -173,12 +173,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action coordinator.build')
coordinator_obj.build()!
}
}
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get('name')!
mut coordinator_obj := get(name: name)!
console.print_debug('action object:\n${coordinator_obj}')
if other_action.name == 'start' {
console.print_debug('install action coordinator.${other_action.name}')
coordinator_obj.start()!

View File

@@ -142,7 +142,7 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'herorunner.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')
@@ -161,12 +161,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action herorunner.build')
herorunner_obj.build()!
}
}
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get('name')!
mut herorunner_obj := get(name: name)!
console.print_debug('action object:\n${herorunner_obj}')
if other_action.name == 'start' {
console.print_debug('install action herorunner.${other_action.name}')
herorunner_obj.start()!

View File

@@ -144,7 +144,7 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'osirisrunner.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')
@@ -163,12 +163,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action osirisrunner.build')
osirisrunner_obj.build()!
}
}
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get('name')!
mut osirisrunner_obj := get(name: name)!
console.print_debug('action object:\n${osirisrunner_obj}')
if other_action.name == 'start' {
console.print_debug('install action osirisrunner.${other_action.name}')
osirisrunner_obj.start()!

View File

@@ -144,7 +144,7 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'salrunner.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')
@@ -163,12 +163,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action salrunner.build')
salrunner_obj.build()!
}
}
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get('name')!
mut salrunner_obj := get(name: name)!
console.print_debug('action object:\n${salrunner_obj}')
if other_action.name == 'start' {
console.print_debug('install action salrunner.${other_action.name}')
salrunner_obj.start()!

View File

@@ -148,7 +148,7 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'supervisor.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')
@@ -167,12 +167,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action supervisor.build')
supervisor_obj.build()!
}
}
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get('name')!
mut supervisor_obj := get(name: name)!
console.print_debug('action object:\n${supervisor_obj}')
if other_action.name == 'start' {
console.print_debug('install action supervisor.${other_action.name}')
supervisor_obj.start()!
@@ -319,7 +313,6 @@ pub fn (mut self Supervisor) running() !bool {
return self.running_check()!
}
// switch instance to be used for supervisor
pub fn switch(name string) {
supervisor_default = name