Runtime Builder
The RuntimeBuilder is a builder for reactive_graph_runtime_api.
Read about the use cases of the RuntimeBuilder in System Architecture.
States
The RuntimeBuilder is stateful:
stateDiagram-v2
[*] --> SetConfigLocations
SetConfigLocations --> SetConfigLocations : Set config file locations
SetConfigLocations --> ConfigFilesLoaded : load_config_files()
SetConfigLocations --> ConfigFilesLoaded : ignore_config_files()
ConfigFilesLoaded --> ConfigFilesLoaded : Set / overwrite config options
ConfigFilesLoaded --> Initialized : init
ConfigFilesLoaded --> Shutdown : block_on
Initialized --> Ready : post_init
Ready --> Ready : with_runtime
Ready --> Running : spawn
Ready --> Finished : spawn_blocking
Ready --> Finished : run_for
Ready --> Finished : do_no_run
Running --> Running : with_runtime
Running --> Finished : stop
Running --> Finished : wait_for_stopped
Finished --> Finished : with_runtime
Finished --> PreShutdown : pre_shutdown
PreShutdown --> Shutdown : shutdown
Shutdown --> Shutdown : wait_for
Shutdown --> [*]
SetConfigLocations
In this state it is possible to configure the locations of the config files or to skip loading config files at all.
Methods
instance_config(path)sets the location of the instance configurationgraphql_server_config(path)sets the location of the graphql server configurationplugins_config(path)sets the location of the plugins configuration
Transitions
- Transition
load_config_filesloads the config files and transits to stateConfigFilesLoaded. This is used in the executable. - Transition
ignore_config_filesdoesn't load the config files and transits to stateConfigFilesLoaded. This is useful for integration tests and hard coded initialization.
ConfigFilesLoaded
In this state either the defaults are set or the the config files are loaded. The RuntimeBuilder can
be used to overwrite configurations or defaults.
Methods
instance_name()sets the name of the instance.instance_description()sets the description of the instance.hostname()sets the hostname of the GraphQL server.port()sets the port number of the GraphQL serverpick_free_port()picks a free port instead of a fixed port number. This is useful for integration tests or temporary applicationssecure()sets if the GraphQL server shall use https or httpshutdown_timeout()sets timeout of the shutdown of the GraphQL serverworkers()sets the number of workers of the GraphQL serverdefault_context_path()sets context path of a web resource provider which shall be used as default context pathdisable_all_plugins()disables all plugins. This is useful for integration tests.disabled_plugins()sets which plugins will be disableddisable_hot_deploy()disables hot deployment of pluginshot_deploy_location()sets the directory where plugins can be hot deployedinstall_location()sets the directory where plugins are located. During hot deployment new plugins will be moved into this directory.
Transitions
- Transition
initcalls theinitmethod of the runtime which will run the initialization phase of the services. Transits to stateInitialized. - Transition
block_oninitializes, runs and shutdowns theRuntime. After shutdown transits to stateShutdown.
Initialized
In this state the Runtime has been initialized with the init method. The next step is to run the post_init method.
Transitions
- Transition
post_initcalls thepost_initmethod
Ready
In this state the Runtime has been fully initialized with the post_init method. The Runtime is now ready to be
started.
Methods
getto get theRuntimeand leave the builderwith_runtimeexecutes a closure which can operate with the runtime. Stays in stateReady.
Transitions
- Transition
spawnspawns a new green thread in which the GraphQL server will be run. This operation is non-blocking and results in a state transition to theRunningstate. - Transition
spawn_blockingcalls therunmethod of the runtime which starts the GraphQL server. This operation is blocking and results in a state transition to theFinshedstate after the GraphQL server has been stopped. - Transition
run_forstarts the GraphQL server and spawns a new green thread that shuts down the GraphQL server after a given duration. The operation is blocking and results in a state transition to theFinshedstate after the GraphQL server has been stopped by the timeout. - Transition
do_not_rundoes not start a GraphQL server and transits to the stateFinshed. This is useful for integration tests in combination withwith_runtime.
Running
In this state the GraphQL server of the Runtime is running.
Methods
getto get theRuntimeand leave the builderwith_runtimeexecutes a closure which can operate with the runtime. Stays in stateRunning.
Transitions
stopstops the runtime. It waits for the GraphQL server to be stopped. This operation is blocking until the GraphQL server has been shutdown gracefully and results in a transition to stateFinished.stop_with_timeoutis likestopbut with a timeout. In contrast tostop, it is NOT guaranteed that the GraphQL server has been stopped actually.wait_for_stoppedwaits until the GraphQL server has been stopped. This can happen by using theShutdownManageror by sending SIGINT signal to the process. This operation is blocking and results in a transition to stateFinished.wait_for_stopped_with_timeoutis likewait_for_stoppedbut with a timeout. In contrast tostop, it is NOT guaranteed that the GraphQL server has been stopped actually.
Finished
In this state the GraphQL server of the Runtime is no more running (or has never been started). The services
of the runtime are up und running.
Methods
getto get theRuntimeand leave the builderwith_runtimeexecutes a closure which can operate with the runtime. Stays in stateFinished.
Transitions
- Transition
pre_shutdowncalls thepre_shutdownmethod of theRuntimeand transits to statePreShutdown.
PreShutdown
In this state the services of the Runtime has executed their pre_shutdown methods. The next step is to
call the shutdown method.
Transitions
- Transition
shutdowncalls theshutdownmethod of theRuntimeand transits to stateShutdown.
Shutdown
In this state the services of the Runtime has executed their shutdown methods. This is the end of the lifetime of a
Runtime.
Methods
wait_forto wait for a given duration