From 18bd8aa2d7e799c663944b56e0e5f93ec91bb9dc Mon Sep 17 00:00:00 2001 From: Milan Unger Date: Thu, 28 Apr 2022 15:54:16 +0200 Subject: [PATCH] Improved handling of failing heartbeat --- prolog/k8s_client.pl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/prolog/k8s_client.pl b/prolog/k8s_client.pl index d516639..5855bce 100644 --- a/prolog/k8s_client.pl +++ b/prolog/k8s_client.pl @@ -526,6 +526,8 @@ prolog:message(kubernetes(watch_modification, Change)) --> { atom_json_dict(Json, Change, [as(atom), width(0)]) }, ['Kubernetes: Modification of resources detected: ~p' - [Json] ]. +prolog:message(kubernetes(watcher_heartbeat_callback_failure, HeartCallback, Id)) --> + ['Kubernetes: The heartbeat callback `~w` of the watcher thread `~w` failed' - [HeartCallback, Id] ]. resource_uri(ApiGroup, Version, ResourceTypeName, Uri, Options) :- option(k8s_namespace(all), Options, all), @@ -622,7 +624,10 @@ watcher_status(Id, exit_request), !. watch_stream(Goal, HeartCallback, Stream, Id, StateIn, StateOut) :- - HeartCallback, + ( call(HeartCallback) + -> true + ; print_message(error, kubernetes(watcher_heartbeat_callback_failure, HeartCallback, Id)) + ), catch( ( peek_string(Stream, 4, _), json_read_dict(Stream, Change, [end_of_file(end_of_file)]), @@ -633,8 +638,8 @@ ), watch_modification_call(Goal, Id, Change, StateIn, State0), !, - watch_stream(Goal, HeartCallback, Stream, Id, State0, StateOut). - + watch_stream(Goal, HeartCallback, Stream, Id, State0, StateOut), + !. watcher_exit(Id) :- watcher_exit(Id, _).