bail out after 20 unexpected connect failures (takes overnight)
This commit is contained in:
parent
74d9440bec
commit
96f5ddfca6
3 changed files with 17 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
.zig-cache/
|
.zig-cache/
|
||||||
zig-out/
|
zig-out/
|
||||||
|
.direnv
|
||||||
|
|
|
@ -81,6 +81,10 @@ pub fn main() !u8 {
|
||||||
std.log.err("Maximum retries exceeded - exiting", .{});
|
std.log.err("Maximum retries exceeded - exiting", .{});
|
||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
|
error.MaximumUnexpectedConnectionFailureRetriesExceeded => {
|
||||||
|
std.log.err("Maximum unexpected connection failure retries exceeded - exiting", .{});
|
||||||
|
return 100; // This feels like a system issue of some sort
|
||||||
|
},
|
||||||
else => {
|
else => {
|
||||||
std.log.err("Error polling events: {s}", .{@errorName(err)});
|
std.log.err("Error polling events: {s}", .{@errorName(err)});
|
||||||
continue;
|
continue;
|
||||||
|
|
13
src/root.zig
13
src/root.zig
|
@ -95,6 +95,8 @@ pub const EventPoller = struct {
|
||||||
var auth_buf: [1024]u8 = undefined;
|
var auth_buf: [1024]u8 = undefined;
|
||||||
const auth = try std.fmt.bufPrint(&auth_buf, "Bearer {s}", .{self.api_key});
|
const auth = try std.fmt.bufPrint(&auth_buf, "Bearer {s}", .{self.api_key});
|
||||||
|
|
||||||
|
var ucf_retries: usize = 0;
|
||||||
|
const MAX_UCF_RETRIES: usize = 20;
|
||||||
var retry_count: usize = 0;
|
var retry_count: usize = 0;
|
||||||
const first_run = self.last_id == null;
|
const first_run = self.last_id == null;
|
||||||
while (retry_count < self.config.max_retries) : (retry_count += 1) {
|
while (retry_count < self.config.max_retries) : (retry_count += 1) {
|
||||||
|
@ -118,13 +120,22 @@ pub const EventPoller = struct {
|
||||||
.authorization = .{ .override = auth },
|
.authorization = .{ .override = auth },
|
||||||
},
|
},
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
std.log.err("HTTP request failed: {s}", .{@errorName(err)});
|
if (err == error.UnexpectedConnectFailure) {
|
||||||
|
ucf_retries += 1;
|
||||||
|
std.log.err(
|
||||||
|
"Unexpected connection failure - may not be recoverable. Retry {d}/{d}",
|
||||||
|
.{ ucf_retries, MAX_UCF_RETRIES },
|
||||||
|
);
|
||||||
|
if (ucf_retries >= MAX_UCF_RETRIES) return error.MaximumUnexpectedConnectionFailureRetriesExceeded;
|
||||||
|
continue;
|
||||||
|
} else std.log.err("HTTP request failed: {s}", .{@errorName(err)});
|
||||||
if (retry_count + 1 < self.config.max_retries) {
|
if (retry_count + 1 < self.config.max_retries) {
|
||||||
std.time.sleep(self.config.retry_delay_ms * std.time.ns_per_ms);
|
std.time.sleep(self.config.retry_delay_ms * std.time.ns_per_ms);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
ucf_retries = 0;
|
||||||
|
|
||||||
if (response.status == .forbidden) return error.Unauthorized;
|
if (response.status == .forbidden) return error.Unauthorized;
|
||||||
if (response.status != .ok) {
|
if (response.status != .ok) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue