Skip to content

Commit

Permalink
Add target_type to start_execution
Browse files Browse the repository at this point in the history
  • Loading branch information
dottorblaster committed Aug 25, 2023
1 parent 4d82d2f commit f76bbf7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/wanda/executions/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ defmodule Wanda.Executions.Server do
If non-existing check IDs are provided inside a target, they will get filtered away.
"""
@impl true
def start_execution(execution_id, group_id, targets, env, config \\ []) do
# TODO: this should be removed when web properly sets the target type in ExecutionRequested event
env = Map.put(env, "target_type", @default_target_type)
def start_execution(execution_id, group_id, targets, target_type, env, config \\ []) do
env = Map.put(env, "target_type", target_type)

checks =
targets
Expand Down
2 changes: 2 additions & 0 deletions lib/wanda/executions/server_behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ defmodule Wanda.Executions.ServerBehaviour do
execution_id :: String.t(),
group_id :: String.t(),
targets :: [Target.t()],
target_type :: String.t(),
env :: %{String.t() => boolean() | number() | String.t()}
) :: :ok | {:error, :no_checks_selected} | {:error, :already_running}

@callback start_execution(
execution_id :: String.t(),
group_id :: String.t(),
targets :: [Target.t()],
target_type :: String.t(),
env :: %{String.t() => boolean() | number() | String.t()},
config :: Keyword.t()
) :: :ok | {:error, any}
Expand Down
3 changes: 3 additions & 0 deletions lib/wanda/messaging/mapper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,21 @@ defmodule Wanda.Messaging.Mapper do
execution_id: String.t(),
group_id: String.t(),
targets: [Target.t()],
target_type: String.t(),
env: %{String.t() => boolean() | number() | String.t() | nil}
}
def from_execution_requested(%ExecutionRequested{
execution_id: execution_id,
group_id: group_id,
targets: targets,
target_type: target_type,
env: env
}) do
%{
execution_id: execution_id,
group_id: group_id,
targets: Target.map_targets(targets),
target_type: target_type,
env: Map.new(env, fn {key, %{kind: value}} -> {key, map_env_entry(value)} end)
}
end
Expand Down
10 changes: 8 additions & 2 deletions lib/wanda/policy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ defmodule Wanda.Policy do
end

defp handle(%ExecutionRequested{} = message) do
%{execution_id: execution_id, group_id: group_id, targets: targets, env: env} =
Mapper.from_execution_requested(message)
%{
execution_id: execution_id,
group_id: group_id,
targets: targets,
env: env,
target_type: target_type
} = Mapper.from_execution_requested(message)

execution_server_impl().start_execution(
execution_id,
group_id,
targets,
target_type,
env
)
end
Expand Down

0 comments on commit f76bbf7

Please sign in to comment.