feat: per-job timeout, shared job query, config problem report, atomic job deletion; arg parser (M5 part 2)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel SamsonandClaude Sonnet 5.5 committed 2026-10-17 13:39:56 +01:00
1 parent bd4e585ed8
commit 35106d405b
9 files changed
+511 -28

No files matched your search

+9 -19
View File
@@ -17,6 +17,7 @@ const recovery = @import("recovery.zig");
const cleanup = @import("cleanup.zig");
const ipc = @import("ipc.zig");
const jobjson = @import("jobjson.zig");
const query = @import("query.zig");
const jsonpretty = @import("jsonpretty.zig");
const duration = @import("duration.zig");
const timestamp = @import("timestamp.zig");
@@ -256,28 +257,14 @@ pub const Service = struct {
try w.endObject();
}
fn newerFirst(_: void, a: Job, b: Job) bool {
return a.created_at > b.created_at;
}
fn hGetStatus(self: *Service, req: ipc.Request, res: *ipc.Response) !void {
const tag = req.payloadString("tag");
var want: ?state_mod.State = null;
if (req.payloadString("state")) |s| want = state_mod.State.parse(s) orelse
var filter: query.Filter = .{ .tag = req.payloadString("tag") };
if (req.payloadString("state")) |s| filter.state = state_mod.State.parse(s) orelse
return res.failFmt(.INVALID_REQUEST, "Unknown state: {s}", .{s});
var list: std.ArrayList(Job) = .empty;
for (try self.repo.findAll(res.arena)) |j| {
if (tag) |t| if (j.tag == null or !std.mem.eql(u8, t, j.tag.?)) continue;
if (want) |s| if (j.state != s) continue;
try list.append(res.arena, j);
}
std.mem.sort(Job, list.items, {}, newerFirst);
var out: []const Job = list.items;
if (req.payloadInt("limit")) |n| if (n > 0 and out.len > n) {
out = out[0..@intCast(n)];
if (req.payloadInt("limit")) |n| if (n > 0) {
filter.limit = @intCast(n);
};
try jobjson.writeJobs(&res.json, out);
try jobjson.writeJobs(&res.json, try query.selectJobs(res.arena, self.repo, filter));
}
fn hGetJob(self: *Service, req: ipc.Request, res: *ipc.Response) !void {
@@ -320,6 +307,9 @@ pub const Service = struct {
if (req.payloadInt("retryDelaySeconds")) |n| {
create_opts.retry_delay_seconds = std.math.cast(u32, n) orelse return res.fail(.INVALID_REQUEST, "retryDelaySeconds must be non-negative");
}
if (req.payloadInt("timeoutSeconds")) |n| {
create_opts.timeout_seconds = std.math.cast(u32, n) orelse return res.fail(.INVALID_REQUEST, "timeoutSeconds must be non-negative");
}
create_opts.load_level = if (req.payloadString("loadLevel")) |l|
LoadLevel.parse(l) orelse return res.failFmt(.INVALID_REQUEST, "Invalid load level: '{s}'. Valid values are: high, medium, low", .{l})
else