chore(growth): load is independent from task
Some checks failed
continuous-integration/drone/pr Build is failing

Ensure that `Growth.Indicators.Load.all/0` can be run independently from
the task.

So, the `ets` table is create based on the filename processed.
This commit is contained in:
João Paulo Dubas 2024-06-10 12:56:50 +00:00
parent 04fff60541
commit 4234b2e917
Signed by: joao.dubas
SSH Key Fingerprint: SHA256:V1mixgOGRc/YMhGx/DNkOSmJxgA2vHNrDZEk3wt/kOA

View File

@ -63,7 +63,7 @@ defmodule Growth.Indicators.Load do
def all do
"priv/growth/indicators/*.csv"
|> Path.wildcard()
|> Enum.map(&create_ets/1)
|> Enum.map(&create_ets_from_filename/1)
|> Enum.map(&Task.async(__MODULE__, :load_measure, [&1]))
|> Task.await_many()
end
@ -85,17 +85,18 @@ defmodule Growth.Indicators.Load do
measure
end
@spec filename_to_measure(String.t()) :: {atom(), String.t()}
@spec create_ets_from_filename(String.t()) :: {atom(), String.t()}
@doc """
Translate the given filename to the related module and return both in a tuple.
Create ets table based on filename and return a tuple with the ets table name and filename.
"""
def filename_to_measure(filename) do
def create_ets_from_filename(filename) do
measure =
filename
|> Path.basename()
|> Path.rootname()
|> String.to_atom()
|> then(&Keyword.get(@measure_to_score, &1, &1))
|> create_ets()
{measure, filename}
end