Packages
altworx_runbox
21.1.0
25.0.0
24.0.0
23.1.0
23.0.0
22.2.0
22.1.0
22.0.0
21.2.0
21.1.2
21.1.1
21.1.0
21.0.0
20.0.0
19.0.0
18.0.0
17.2.0
17.1.0
17.0.1
17.0.0
16.2.0
16.1.0
16.0.0
15.0.0
14.1.0
14.0.1
14.0.0
13.0.3
13.0.2
13.0.1
13.0.0
12.1.0
12.0.0
11.0.1
11.0.0
10.0.0
9.0.0
8.0.0
7.0.1
7.0.0
6.0.0
5.0.0
4.0.0
3.0.0
2.1.0
2.0.0
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0
0.1.3
0.1.2
0.1.1
0.1.0
Runbox is a library for running Altworx scenarios.
Current section
Files
Jump to
Current section
Files
lib/runbox/runtime/simple/component_network.ex
defmodule Runbox.Runtime.Simple.ComponentNetwork do
@moduledoc group: :internal
@moduledoc """
Component network builds and validates template dependency network for Simple scenario runtime.
The component network for Simple scenarios is quite simple.
* first you have input topics, usually followed by tick timezip for each of them
* following is a timezip zipping all input topics into a single stream
* the stream is processed by the template which is the heart of the scenario, it produces a stream of output actions
* finally there's an output sink executing the output actions
"""
@behaviour Runbox.Runtime.ComponentNetwork
@type timezip :: {:timezip, to_zip :: [component()]}
@type template :: {:template, module()}
@type tick_timezip :: {:tick_timezip, topic :: String.t()}
@type input :: {:input_topic | :load_topic, topic :: String.t()}
@type output_sink() :: :output_sink
@type component :: template() | input() | tick_timezip() | output_sink() | timezip()
@type t :: [component()]
@impl true
def convert_to_network([template]) do
template
end
@impl true
def create([template], _opts) do
network =
List.flatten([
inputs(template.info.topics),
[{:template, template.module}, :output_sink]
])
{:ok, network}
end
def create([], _) do
{:error, :no_template_found}
end
def create(_, _) do
{:error, :multiple_templates_not_supported}
end
@impl true
def input_topics(network) do
network
|> Enum.filter(fn
{:input_topic, _} -> true
{:load_topic, _} -> true
_ -> false
end)
|> Enum.map(fn {_, topic} -> topic end)
end
# generate topics, optionally with tick timezips and a single timezip at the end, if needed
defp inputs([topic]), do: input_with_tick_timezip(topic)
defp inputs(topics) do
topic_components = Enum.map(topics, &input_with_tick_timezip/1)
timezip = [{:timezip, Enum.map(topic_components, &List.last/1)}]
List.flatten(topic_components) ++ timezip
end
defp input_with_tick_timezip({_, logical_topic} = topic),
do: [topic, {:tick_timezip, logical_topic}]
end