Reset worker errors, retry failed workers

This commit is contained in:
Ulf Wiger 2025-08-21 22:46:54 +02:00
parent d61f103945
commit 196a2d9949
15 changed files with 35 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{application,gmhive_client,
[{description,"Gajumaru Hive Client"},
{vsn,"0.4.7"},
{vsn,"0.4.8"},
{registered,[]},
{applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise,
gmconfig,gmhive_protocol,gmhive_worker]},

View File

@ -1,5 +1,6 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
-module(gmhc_app).
-vsn("0.4.8").
-behaviour(application).

View File

@ -1,4 +1,5 @@
-module(gmhc_config).
-vsn("0.4.8").
-export([ load_config/0
, get_config/1

View File

@ -1,4 +1,5 @@
-module(gmhc_config_schema).
-vsn("0.4.8").
-export([ schema/0
, to_json/0 ]).

View File

@ -1,4 +1,5 @@
-module(gmhc_connector).
-vsn("0.4.8").
-behaviour(gen_server).

View File

@ -1,4 +1,5 @@
-module(gmhc_connectors_sup).
-vsn("0.4.8").
-behavior(supervisor).
-export([ start_link/0

View File

@ -1,4 +1,5 @@
-module(gmhc_counters).
-vsn("0.4.8").
-export([ initialize/0 ]).

View File

@ -1,4 +1,5 @@
-module(gmhc_eureka).
-vsn("0.4.8").
-export([get_pool_address/0]).

View File

@ -1,4 +1,5 @@
-module(gmhc_events).
-vsn("0.4.8").
-export([subscribe/1,
ensure_subscribed/1,

View File

@ -1,4 +1,5 @@
-module(gmhc_handler).
-vsn("0.4.8").
-behavior(gen_server).
-export([ start_link/0

View File

@ -1,4 +1,5 @@
-module(gmhc_server).
-vsn("0.4.8").
-behaviour(gen_server).
@ -44,7 +45,7 @@
-define(CONNECTED(S), map_size(S#st.connected) > 0).
-define(MAX_ERRORS, 5).
-define(MAX_ERRORS, 50).
connected(Id, Type) ->
gen_server:call(?MODULE, {connected, Id, Type}).
@ -154,11 +155,23 @@ handle_info({'EXIT', Pid, Reason}, #st{ workers = Workers
gmhc_events:publish(error, ?ERR_EVT(#{error => worker_error,
data => Reason})),
Ws1 = incr_worker_error(W, Workers),
erlang:start_timer(100, self(), check_workers),
{noreply, S#st{workers = Ws1}};
false ->
%% ?LOG_DEBUG("EXIT apparently not from worker?? (~p)", [Pid]),
{noreply, S}
end;
handle_info({timeout, _, check_workers}, #st{workers = Workers} = S) ->
case [W || #worker{cand = undefined} = W <- Workers] of
[] ->
{noreply, S};
Idle ->
S1 = maybe_request_nonces(S),
S2 = lists:foldl(fun(W, Sx) ->
maybe_restart_worker(W, Sx)
end, S1, Idle),
{noreply, S2}
end;
handle_info(Msg, St) ->
?LOG_DEBUG("Unknown msg: ~p", [Msg]),
{noreply, St}.
@ -226,14 +239,14 @@ handle_worker_result({worker_result, Result}, W, S) ->
case Result of
{solutions, Solutions} ->
{Cont, S1} = report_solutions_(Solutions, W, S),
maybe_continue(Cont, W, S1);
maybe_continue(Cont, reset_errors(W), S1);
{solution, Nonce, Solution} ->
%% report_solution(Nonce, Solution, W, S),
{Cont, S1} = report_solutions_([{Nonce, Solution}], W, S),
maybe_continue(Cont, W, S1);
maybe_continue(Cont, reset_errors(W), S1);
{no_solution, Nonce} ->
report_no_solution(Nonce, W, S),
maybe_restart_worker(W, S);
maybe_restart_worker(reset_errors(W), S);
{error, S} ->
?LOG_DEBUG("Worker ~p reported error as normal", [W#worker.index]),
gmhc_events:publish(error, ?ERR_EVT(#{error => worker_error,
@ -261,6 +274,9 @@ report_solutions_(Solutions, W, S) ->
{error, S}
end.
reset_errors(#worker{} = W) ->
W#worker{errors = 0}.
reset_worker(#worker{index = I} = W, Ws) ->
W1 = reset_worker_(W),
lists:keyreplace(I, #worker.index, Ws, W1).

View File

@ -1,5 +1,6 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
-module(gmhc_sup).
-vsn("0.4.8").
-behaviour(supervisor).

View File

@ -8,6 +8,7 @@
%%%-------------------------------------------------------------------
-module(gmhc_workers).
-vsn("0.4.8").
-export([
get_worker_configs/0

View File

@ -1,4 +1,5 @@
-module(gmhive_client).
-vsn("0.4.8").
-export([ connect/1
, disconnect/1

View File

@ -4,7 +4,7 @@
{prefix,"gmhc"}.
{author,"Ulf Wiger, QPQ AG"}.
{desc,"Gajumaru Hive Client"}.
{package_id,{"uwiger","gmhive_client",{0,4,7}}}.
{package_id,{"uwiger","gmhive_client",{0,4,8}}}.
{deps,[{"uwiger","gmhive_worker",{0,4,0}},
{"uwiger","gmcuckoo",{1,2,3}},
{"otpr","eblake2",{1,0,1}},