Skip to content

Commit fdebffd

Browse files
ttt161ttt161
andauthored
fix for woody errors processing (#39)
Co-authored-by: ttt161 <losto@nix>
1 parent ff34315 commit fdebffd

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

config/sys.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@
8787
}
8888
}
8989
]}
90-
]}
90+
]},
91+
92+
%% optional, default true
93+
{migration_enabled, true}
9194
]},
9295

9396
%%

src/prg_namespace_sup.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
-spec start_link({namespace_id(), namespace_opts()}) ->
1818
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}.
1919
start_link({NsId, #{storage := StorageOpts}} = NS) ->
20-
ok = prg_storage:db_init(StorageOpts, NsId),
20+
case application:get_env(progressor, migration_enabled, true) of
21+
true ->
22+
ok = prg_storage:db_init(StorageOpts, NsId);
23+
false ->
24+
ok
25+
end,
2126
RegName = prg_utils:registered_name(NsId, "_namespace_sup"),
2227
supervisor:start_link({local, RegName}, ?MODULE, NS).
2328

src/prg_worker.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,16 @@ extract_task_type({TaskType, _}) ->
570570

571571
check_retryable(TaskHeader, #{last_retry_interval := LastInterval} = Task, RetryPolicy, Error) ->
572572
Now = erlang:system_time(second),
573+
ProcessId = maps:get(process_id, Task),
573574
Timeout =
574575
case LastInterval =:= 0 of
575576
true -> maps:get(initial_timeout, RetryPolicy);
576577
false -> trunc(LastInterval * maps:get(backoff_coefficient, RetryPolicy))
577578
end,
578579
Attempts = maps:get(attempts_count, Task) + 1,
580+
logger:info("check retryable ~p for error: ~p, last retry interval: ~p sec, attempt: ~p", [
581+
ProcessId, Error, LastInterval, Attempts
582+
]),
579583
case is_retryable(Error, TaskHeader, RetryPolicy, Timeout, Attempts) of
580584
true ->
581585
maps:with(
@@ -601,7 +605,7 @@ check_retryable(TaskHeader, #{last_retry_interval := LastInterval} = Task, Retry
601605
end.
602606

603607
%% machinegun legacy
604-
-define(WOODY_ERROR(Class), {exception, _, {woody_error, Class, _}}).
608+
-define(WOODY_ERROR(Class), {exception, _, {woody_error, {_, Class, _}}}).
605609
-define(TEST_POLICY(Error, RetryPolicy, Timeout, Attempts),
606610
(Timeout < maps:get(max_timeout, RetryPolicy, infinity) andalso
607611
Attempts < maps:get(max_attempts, RetryPolicy, infinity) andalso

test/prg_base_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ error_after_max_retries_test(C) ->
578578
4 = expect_steps_counter(4),
579579
timer:sleep(?AWAIT_TIMEOUT(C)),
580580
{ok, #{
581-
detail := <<"retry_this">>,
581+
detail := <<"{exception,error,{woody_error,{external,result_unknown,<<\"closed\">>}}}">>,
582582
history := [],
583583
process_id := Id,
584584
status := <<"error">>
@@ -1220,7 +1220,7 @@ mock_processor(error_after_max_retries_test = TestCase) ->
12201220
({timeout, <<>>, #{history := []} = _Process}, _Opts, _Ctx) ->
12211221
%% must be 3 attempts
12221222
Self ! iterate,
1223-
{error, retry_this}
1223+
erlang:raise(error, {woody_error, {external, result_unknown, <<"closed">>}}, [])
12241224
end,
12251225
mock_processor(TestCase, MockProcessor);
12261226
%%

0 commit comments

Comments
 (0)