Skip to content

Commit

Permalink
Improved handling of failing heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan Unger committed Apr 28, 2022
1 parent 4b3d322 commit 18bd8aa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions prolog/k8s_client.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)]),
Expand All @@ -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, _).
Expand Down

0 comments on commit 18bd8aa

Please sign in to comment.