Skip to content

Commit 8761d27

Browse files
kasvithclaude
andcommitted
fix: resolve credo strict mode violations
- Extract helper functions to reduce cyclomatic complexity in executor - Replace length/1 checks with empty list comparisons in tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d8fe720 commit 8761d27

File tree

2 files changed

+54
-30
lines changed

2 files changed

+54
-30
lines changed

lib/durable/executor.ex

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -283,42 +283,66 @@ defmodule Durable.Executor do
283283
execute_steps_recursive(remaining_steps, exec, step_index, workflow_def, config)
284284

285285
{:decision, target_step} ->
286-
# Decision step wants to jump - find target in remaining steps
287-
{:ok, exec} = save_context(repo, exec)
288-
289-
case find_jump_target(target_step, remaining_steps, step.name, step_index) do
290-
{:ok, target_steps} ->
291-
execute_steps_recursive(target_steps, exec, step_index, workflow_def, config)
292-
293-
{:error, reason} ->
294-
handle_step_failure(
295-
exec,
296-
decision_error(step.name, target_step, reason),
297-
workflow_def,
298-
config
299-
)
300-
end
301-
302-
{:sleep, opts} ->
303-
{:waiting, handle_sleep(repo, exec, opts) |> elem(1)}
286+
handle_decision_result(
287+
exec,
288+
target_step,
289+
remaining_steps,
290+
step,
291+
step_index,
292+
workflow_def,
293+
config
294+
)
304295

305-
{:wait_for_event, opts} ->
306-
{:waiting, handle_wait_for_event(repo, exec, opts) |> elem(1)}
296+
{wait_type, opts}
297+
when wait_type in [:sleep, :wait_for_event, :wait_for_input, :wait_for_any, :wait_for_all] ->
298+
handle_wait_result(repo, exec, wait_type, opts)
307299

308-
{:wait_for_input, opts} ->
309-
{:waiting, handle_wait_for_input(repo, exec, opts) |> elem(1)}
300+
{:error, error} ->
301+
handle_step_failure(exec, error, workflow_def, config)
302+
end
303+
end
310304

311-
{:wait_for_any, opts} ->
312-
{:waiting, handle_wait_for_any(repo, exec, opts) |> elem(1)}
305+
defp handle_decision_result(
306+
exec,
307+
target_step,
308+
remaining_steps,
309+
step,
310+
step_index,
311+
workflow_def,
312+
config
313+
) do
314+
repo = config.repo
315+
{:ok, exec} = save_context(repo, exec)
313316

314-
{:wait_for_all, opts} ->
315-
{:waiting, handle_wait_for_all(repo, exec, opts) |> elem(1)}
317+
case find_jump_target(target_step, remaining_steps, step.name, step_index) do
318+
{:ok, target_steps} ->
319+
execute_steps_recursive(target_steps, exec, step_index, workflow_def, config)
316320

317-
{:error, error} ->
318-
handle_step_failure(exec, error, workflow_def, config)
321+
{:error, reason} ->
322+
handle_step_failure(
323+
exec,
324+
decision_error(step.name, target_step, reason),
325+
workflow_def,
326+
config
327+
)
319328
end
320329
end
321330

331+
defp handle_wait_result(repo, exec, :sleep, opts),
332+
do: {:waiting, handle_sleep(repo, exec, opts) |> elem(1)}
333+
334+
defp handle_wait_result(repo, exec, :wait_for_event, opts),
335+
do: {:waiting, handle_wait_for_event(repo, exec, opts) |> elem(1)}
336+
337+
defp handle_wait_result(repo, exec, :wait_for_input, opts),
338+
do: {:waiting, handle_wait_for_input(repo, exec, opts) |> elem(1)}
339+
340+
defp handle_wait_result(repo, exec, :wait_for_any, opts),
341+
do: {:waiting, handle_wait_for_any(repo, exec, opts) |> elem(1)}
342+
343+
defp handle_wait_result(repo, exec, :wait_for_all, opts),
344+
do: {:waiting, handle_wait_for_all(repo, exec, opts) |> elem(1)}
345+
322346
defp execute_branch(branch_step, remaining_steps, execution, step_index, workflow_def, config) do
323347
repo = config.repo
324348
{:ok, exec} = update_current_step(repo, execution, branch_step.name)

test/durable/wait_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ defmodule Durable.WaitTest do
560560

561561
inputs = Wait.list_pending_inputs()
562562

563-
assert length(inputs) >= 1
563+
assert inputs != []
564564
assert Enum.any?(inputs, fn i -> i.workflow_id == execution.id end)
565565
end
566566

@@ -593,7 +593,7 @@ defmodule Durable.WaitTest do
593593

594594
events = Wait.list_pending_events()
595595

596-
assert length(events) >= 1
596+
assert events != []
597597
assert Enum.any?(events, fn e -> e.workflow_id == execution.id end)
598598
end
599599

0 commit comments

Comments
 (0)