Hello everyone, I`m starting to learn Elixir and I have one first big challenge to solve. Hope someone can help me !
Okay, first of all, I have a list of alertConfigs(stored in an external database), that looks like this:
[
{
code: "A",
comparison: ">=",
message: "A is greater or equal 50",
value: 50
},
{
code: "B",
comparison: "<=",
message: "B is less or equal 100",
value: 100
},
{
code: "C",
comparison: "=",
message: "C is equal 20!",
value: 20
},
...
]
My first task is to create one process foreach item of the list (dynamic supervisioned, because one new alert may be created while the application is running). The process must be restarted(with the initial state) in case of failure.
Then comes the hard part(or the not clear part for me).
I have a websocket server that sends a infosList every minute, the list looks something like this:
[
{
code: "A",
value: 15
},
{
code: "B",
value: 150
},
{
code: "C",
value: 21
}
]
The codes and values of the list can change(usually, only the value will change, but more codes can be added every minute). My challenge is to be able to split the list into chunks and only send relevant data to the workers.
For example, supposing I already have all alertWorkers up and running, and one of them has
state = %{
code: "A",
comparison: ">=",
message: "A is greater or equal 50",
value: 50
}
When a new list comes from my websocket, I have to be able to send it only the item which “code” == “A” for it, and for the other workers, their respective “code”-based info.
Now my question is: What’s the best way to achieve this with Elixir?
I though about using a DynamicSupervisor to manage all alert-processes.
But I don`t know how to broadcast the infosList to every process, and make them validate it.
I need that the inner(or child) process to print the message when value hits its expectation.