Skip to content

Commit

Permalink
style: fix credo issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fahchen committed Jun 16, 2023
1 parent a140777 commit a7e93e1
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 218 deletions.
3 changes: 2 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
import_deps: [:typed_struct]
import_deps: [:typed_struct],
plugins: [Styler]
]
16 changes: 11 additions & 5 deletions lib/workflow_metal/application/config.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
defmodule WorkflowMetal.Application.Config do
@moduledoc false

@type t :: map()
@type application :: WorkflowMetal.Application.t()
@type t() :: map()
@type application() :: WorkflowMetal.Application.t()

@typep key() :: atom()
@typep value() :: term()
# credo:disable-for-previous-line JetCredo.Checks.ExplicitAnyType

@doc false
@spec start_link(application, t) :: Agent.on_start()
@spec start_link(application(), t()) :: Agent.on_start()
def start_link(application, initial_value) do
Agent.start_link(fn -> initial_value end, name: config_name(application))
end

@doc """
Store settings of an application.
"""
@spec set(application, atom, term) :: :ok
@spec set(application(), key(), value()) :: :ok
def set(application, key, value) when is_atom(application) do
Agent.update(config_name(application), fn state ->
Keyword.put(state, key, value)
Expand All @@ -23,7 +27,7 @@ defmodule WorkflowMetal.Application.Config do
@doc """
Retrieve settings of an application.
"""
@spec get(application, atom) :: term
@spec get(application(), key()) :: value()
def get(application, key) when is_atom(application) and is_atom(key) do
Agent.get(config_name(application), fn state ->
Keyword.get(state, key)
Expand All @@ -33,11 +37,13 @@ defmodule WorkflowMetal.Application.Config do
@doc """
Retrieves the compile time configuration.
"""
@spec compile_config(application(), Keyword.t()) :: Keyword.t()
def compile_config(_application, config) do
Keyword.take(config, [:name, :registry, :storage])
end

defp config_name(application) do
# credo:disable-for-next-line Credo.Check.Warning.UnsafeToAtom
Module.concat(application, Config)
end
end
14 changes: 6 additions & 8 deletions lib/workflow_metal/application/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ defmodule WorkflowMetal.Application.Supervisor do

config_child_spec = config_child_spec(application, config)

children =
[
config_child_spec,
registry_child_spec,
storage_child_spec,
{WorkflowMetal.Application.WorkflowsSupervisor, application}
]
|> Enum.filter(& &1)
children = [
config_child_spec,
registry_child_spec,
storage_child_spec,
{WorkflowMetal.Application.WorkflowsSupervisor, application}
]

Supervisor.init(children, strategy: :one_for_one)
end
Expand Down
4 changes: 1 addition & 3 deletions lib/workflow_metal/application/workflows_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ defmodule WorkflowMetal.Application.WorkflowsSupervisor do
WorkflowMetal.Registration.Adapter.on_start_child()
| {:error, :workflow_not_found}
def open_workflow(application, workflow_id) do
with(
{:ok, workflow_schema} <- WorkflowMetal.Storage.fetch_workflow(application, workflow_id)
) do
with({:ok, workflow_schema} <- WorkflowMetal.Storage.fetch_workflow(application, workflow_id)) do
workflows_supervisor = supervisor_name(application)
workflow_supervisor = {WorkflowMetal.Workflow.Supervisor, workflow_id: workflow_schema.id}

Expand Down
5 changes: 4 additions & 1 deletion lib/workflow_metal/case/case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,10 @@ defmodule WorkflowMetal.Case.Case do
state: [:started, :allocated, :executing]
)

Enum.each(tasks, fn task -> WorkflowMetal.Task.Supervisor.force_abandon_task(application, task.id) end)
Enum.each(tasks, fn task ->
WorkflowMetal.Task.Supervisor.force_abandon_task(application, task.id)
end)

data
end

Expand Down
4 changes: 2 additions & 2 deletions lib/workflow_metal/controller/join/and.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ defmodule WorkflowMetal.Controller.Join.And do
All incoming branch are active.
"""

alias WorkflowMetal.Storage.Schema

@behaviour WorkflowMetal.Controller.Join

alias WorkflowMetal.Storage.Schema

@impl WorkflowMetal.Controller.Join
def task_enablement(task_data) do
case get_tokens(task_data) do
Expand Down
9 changes: 4 additions & 5 deletions lib/workflow_metal/controller/join/none.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ defmodule WorkflowMetal.Controller.Join.None do
There is only one branch of the transition.
"""

alias WorkflowMetal.Storage.Schema

@behaviour WorkflowMetal.Controller.Join

alias WorkflowMetal.Storage.Schema

@impl WorkflowMetal.Controller.Join
def task_enablement(task_data) do
case get_token(task_data) do
Expand All @@ -29,8 +29,7 @@ defmodule WorkflowMetal.Controller.Join.None do
token_table: token_table
} = task_data

{:ok, [%Schema.Place{id: place_id}]} =
WorkflowMetal.Storage.fetch_places(application, transition_schema.id, :in)
{:ok, [%Schema.Place{id: place_id}]} = WorkflowMetal.Storage.fetch_places(application, transition_schema.id, :in)

match_spec = [
{
Expand All @@ -44,7 +43,7 @@ defmodule WorkflowMetal.Controller.Join.None do
[token_id | _rest] ->
{:ok, [token_id]}

_ ->
_other ->
{:error, :task_not_enabled}
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/workflow_metal/controller/split/and.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule WorkflowMetal.Controller.Split.And do
@moduledoc false

alias WorkflowMetal.Storage.Schema

@behaviour WorkflowMetal.Controller.Split

alias WorkflowMetal.Storage.Schema

@impl true
def issue_tokens(task_data, token_payload) do
%{
Expand Down
4 changes: 2 additions & 2 deletions lib/workflow_metal/controller/split/none.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule WorkflowMetal.Controller.Split.None do
@moduledoc false

alias WorkflowMetal.Storage.Schema

@behaviour WorkflowMetal.Controller.Split

alias WorkflowMetal.Storage.Schema

@impl true
def issue_tokens(task_data, token_payload) do
%{
Expand Down
4 changes: 2 additions & 2 deletions lib/workflow_metal/executor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ defmodule WorkflowMetal.Executor do
application = Keyword.get(opts, :application)

quote do
@behaviour WorkflowMetal.Executor

alias WorkflowMetal.Storage.Schema

@application unquote(application)

@behaviour WorkflowMetal.Executor

@before_compile unquote(__MODULE__)

@impl WorkflowMetal.Executor
Expand Down
6 changes: 3 additions & 3 deletions lib/workflow_metal/storage.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
defmodule WorkflowMetal.Storage do
alias WorkflowMetal.Application
alias WorkflowMetal.Storage.Adapter

@moduledoc """
Use the storage configured for a WorkflowMetal application.
"""

alias WorkflowMetal.Application
alias WorkflowMetal.Storage.Adapter

@type application :: WorkflowMetal.Application.t()
@type workflow_id :: WorkflowMetal.Storage.Schema.Workflow.id()

Expand Down
Loading

0 comments on commit a7e93e1

Please sign in to comment.