feat: extend main with MetricCounter and incr

This commit is contained in:
dualfroz committed 2026-09-07 17:45:49 +02:00
1 parent ad58b3f05c
commit 95c1bed183
2 files changed
+200

No files matched your search

+38
View File
@@ -3598,6 +3598,44 @@ fn runServe(allocator: std.mem.Allocator, stdout: anytype, db: *cobalt.Db, bind:
}
sessionStore = cobalt.SessionStore.init(allocator);
const ttlNanos: i128 = @intFromFloat(seconds * @as(f64, @floatFromInt(std.time.ns_per_s)));
server.enableSessions(&sessionStore, ttlNanos);
try stdout.print("sessions enabled: AUTH issues a token valid for {d}s\n", .{seconds});
if (sessionSweepSeconds) |sweepSeconds| {
if (sweepSeconds <= 0) {
try stdout.writeAll("error: --session-sweep-interval must be a positive number of seconds\n");
std.process.exit(2);
}
const sweepNanos: u64 = @intFromFloat(sweepSeconds * @as(f64, @floatFromInt(std.time.ns_per_s)));
server.enableSessionSweep(sweepNanos);
try stdout.print("session sweeper enabled: expired sessions dropped every {d}s\n", .{sweepSeconds});
}
}
defer if (sessionTtlSeconds != null) sessionStore.deinit();
if (ttlSweepSeconds) |seconds| {
if (seconds <= 0) {
try stdout.writeAll("error: --ttl-sweep-interval must be a positive number of seconds\n");
std.process.exit(2);
}
const nanos: u64 = @intFromFloat(seconds * @as(f64, @floatFromInt(std.time.ns_per_s)));
server.enableTtlSweep(nanos);
try stdout.print("ttl sweeper enabled: due keys reaped every {d}s\n", .{seconds});
}
if (collTtlSweepSeconds) |seconds| {
if (seconds <= 0) {
try stdout.writeAll("error: --coll-ttl-sweep-interval must be a positive number of seconds\n");
std.process.exit(2);
}
const nanos: u64 = @intFromFloat(seconds * @as(f64, @floatFromInt(std.time.ns_per_s)));
server.enableCollTtlSweep(nanos);
try stdout.print("collection ttl sweeper enabled: due collections reaped every {d}s\n", .{seconds});
}
try stdout.print("cobalt server listening on {}\n", .{server.boundAddress()});
try server.start();
server.wait();
}
fn runVerify(allocator: std.mem.Allocator, stdout: anytype, dir: []const u8, count: usize) !void {