refactor and simplify if-chain in freezer_main
INTRODUCTION
At the moment freezer_main() uses an "if" chain to select the code
to execute according to the provided "action" option.
PROBLEM
There are some features upcoming which could result in
a longer chain and more indentation:
- configuration file
- windows support
Configuration file will bring the possibility to specify a sequence
of different actions.
This would result in multiple configuration dictionaries, one for each action,
and an increased level to allow multiple iterations upon the current "if" chain.
POSSIBLE SOLUTION
An alternative approach is to move the actual code into various "job" objects,
each of which encapsulates the code to execute their respective action.
Every job object would know what to do, how to do it and present
a coherent interface: the execute() method.
These objects would be created by a factory after the configuration file
has been parsed an split into the various job configuration sections.
The main loop would simply iterate over the list of jobs and execute() them.
The advantages would be:
- clean separation of code relative to different actions
- extensibility and flexibility: easier to
- add new type of actions
- maintain relevant state information during individual action execution
- implement scheduling of jobs for future execution
- add the possibility to have execution of jobs contitional
to success/failure of other jobs
Blueprint information
- Status:
- Complete
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- Fabrizio Vanni
- Direction:
- Needs approval
- Assignee:
- Fabrizio Vanni
- Definition:
- New
- Series goal:
- None
- Implementation:
- Implemented
- Milestone target:
- None
- Started by
- Fabrizio Vanni
- Completed by
- Fabrizio Vanni
Related branches
Related bugs
Sprints
Whiteboard
Gerrit topic: https:/
Addressed by: https:/
Main loop refactor