Skip to content

Commit

Permalink
add onerr callback for leader elector (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
tg123 authored Sep 13, 2023
1 parent 8e19c03 commit 7454f04
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/KubernetesClient/LeaderElection/LeaderElector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class LeaderElector : IDisposable
/// </summary>
public event Action<string> OnNewLeader;

/// <summary>
/// OnError is called when there is an error trying to determine leadership.
/// </summary>
public event Action<Exception> OnError;

private volatile LeaderElectionRecord observedRecord;
private DateTimeOffset observedTime = DateTimeOffset.MinValue;
private string reportedLeader;
Expand Down Expand Up @@ -69,8 +74,9 @@ public async Task RunAsync(CancellationToken cancellationToken = default)
MaybeReportTransition();
}
}
catch
catch (Exception e)
{
OnError?.Invoke(e);
// ignore
return false;
}
Expand Down Expand Up @@ -129,6 +135,8 @@ private async Task<bool> TryAcquireOrRenew(CancellationToken cancellationToken)
{
return false;
}

OnError?.Invoke(e);
}

if (oldLeaderElectionRecord?.AcquireTime == null ||
Expand Down

0 comments on commit 7454f04

Please sign in to comment.