add connection pool to hopefully eliminate unexpected connection failures
This commit is contained in:
parent
96f5ddfca6
commit
771d7d7b4c
2 changed files with 11 additions and 3 deletions
|
@ -64,12 +64,18 @@ pub fn main() !u8 {
|
|||
try stdout.print("Monitoring Syncthing events at {s}\n", .{config.syncthing_url});
|
||||
|
||||
var last_id: ?i64 = null;
|
||||
const connection_pool = std.http.Client.ConnectionPool{};
|
||||
while (true) {
|
||||
var arena_alloc = std.heap.ArenaAllocator.init(allocator);
|
||||
defer arena_alloc.deinit();
|
||||
const arena = arena_alloc.allocator();
|
||||
|
||||
var poller = try EventPoller.init(arena, api_key, config);
|
||||
var poller = try EventPoller.init(
|
||||
arena,
|
||||
api_key,
|
||||
config,
|
||||
connection_pool,
|
||||
);
|
||||
defer last_id = poller.last_id;
|
||||
poller.last_id = last_id;
|
||||
const events = poller.poll() catch |err| switch (err) {
|
||||
|
|
|
@ -75,18 +75,20 @@ pub const EventPoller = struct {
|
|||
config: Config,
|
||||
last_id: ?i64,
|
||||
api_key: []u8,
|
||||
connection_pool: std.http.Client.ConnectionPool,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, api_key: []u8, config: Config) !EventPoller {
|
||||
pub fn init(allocator: std.mem.Allocator, api_key: []u8, config: Config, connection_pool: ?std.http.Client.ConnectionPool) !EventPoller {
|
||||
return .{
|
||||
.allocator = allocator,
|
||||
.config = config,
|
||||
.last_id = null,
|
||||
.api_key = api_key,
|
||||
.connection_pool = connection_pool orelse .{},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn poll(self: *EventPoller) ![]SyncthingEvent {
|
||||
var client = std.http.Client{ .allocator = self.allocator };
|
||||
var client = std.http.Client{ .allocator = self.allocator, .connection_pool = self.connection_pool };
|
||||
var arena = std.heap.ArenaAllocator.init(self.allocator);
|
||||
defer arena.deinit();
|
||||
const aa = arena.allocator();
|
||||
|
|
Loading…
Add table
Reference in a new issue