classy_boot ¶This module controls the boot sequence of business applications managed by classy. It is based on a concept of run levels and barriers.
Run level is an integer corresponding to the “readiness state” of the system. See Run level.
Barriers can be set to temporarily limit the progression of the run level.
When a barrier is set at run level N,
the system drops level to N
(if it was at level M > N, then it will do so by going through M, M - 1, ..., N sequence)
and stays there until the barrier is removed.
If there are multiple barriers,
system waits for the one set at the lowest run level.
The general idea is that initialization of the business logic can be represented
as a directed acyclic dependency graph,
and each topological level of the DAG can be mapped to a certain run level.
Business applications can hook initialization and de-initialization logic to each level using classy:on_run_level/2 function.
Initialization hooks can set up barriers that are removed asynchronously
(when some subsystem becomes ready).
This approach allows to avoid blocking calls that wait for the readiness condition,
which can be problematic when the system has to stop or restart before fully ready.
WARNING: classy doesn’t check that the boot dependency graph is acyclic and that mapping to run levels is valid,
leaving this responsibility to the system designer.
There are no safety checks for the barrier levels:
setting them improperly can lead to hung boot.
The developer can use classy_boot:diagnostics/1 function to troubleshoot the boot state.