View Source Runbox.Runtime.Simple.StageBasedEmulator (runbox v13.0.3)
Macro for emulating a StageBased scenario inside a Simple scenario.
This macro provides a simple way to integrate Runbox.Runtime.Stage.Emulator
in a Simple
scenario.
This macro has to be used in a manifest module of a scenario. The manifest must specify the type
of the scenario as Runbox.Scenario.Type.simple/0
. The rest is taken care of by the macro.
It does the following
- use
Runbox.Scenario.Simple
to register the module as the implementation of the scenario - implement all necessary callbacks and use
Runbox.Runtime.Stage.Emulator
in them - auto-discover template modules, see below
Template module auto-discovery
This macro auto-discovers template modules of the emulated scenario. This is designed to easily switch a StageBased scenario into a Simple scenario emulating the original code.
Template modules are discovered as follows:
- list all modules in the scenario release
- take only modules whose name are prefixed by the current module, just like a StageBased templates are discovered
- from these take only modules which are valid templates, basically this means it has to use the
behavior
Runbox.Scenario.Template.StageBased
.
Therefore, to convert existing StageBased scenario to Simple scenario you only have to do the following:
- add
use Runbox.Runtime.Simple.StageBasedEmulator
to the manifest module - change type in the manifest to
Runbox.Scenario.Type.simple/0
Example
defmodule Scenarios.MyScenario do
use Runbox.Scenario.Manifest
use Runbox.Runtime.Simple.StageBasedEmulator
@impl Runbox.Scenario.Manifest
def get_info do
%Runbox.Scenario.Manifest{
id: "my_scenario",
name: "My converted scenario",
description: "This is a scenario I converted from StageBased to Simple",
change_log: %{
1704021223000 => "First version of the scenario",
1731487296000 => "Convert to Simple scenario"
},
type: Runbox.Scenario.Type.simple()
}
end
end