load levels: remove load levels from model, config, CLI, IPC, tests, docs
CI / test (pull_request) Successful in 3m20s
CI / test (pull_request) Successful in 3m20s
Completes issue #2 on top of the phase-1 strict single-job FIFO scheduler. Removed: - Job.load_level / Manifest.load_level / CreateOptions.load_level and the manifest.json loadLevel field (old manifests still parse: unknown fields are ignored) - loadLevel in job JSON and <load_level> in XML output (field order shifts; old JSON still parses) - the [load_levels] config section, service.max_concurrent_jobs, ZAG_LOAD_LEVELS_*/ZAG_LOADLEVELS_*/ZAG_SERVICE_MAX_CONCURRENT_JOBS env vars, loadlevel.zig / loadclass.zig and the default .load files Friendly deprecation: old configs and environments still load fine. config validate and config show report the removed settings as non-fatal warnings (validate exit 1 stays reserved for real errors) and the CLI/daemon logs them once at startup. --load-level is gone from zag run; old IPC clients sending loadLevel are simply ignored. e2e: wait_state is now portable to macOS bash 3.2 (it silently skipped three checks before) and a serial-execution check asserts the second job stays QUEUED while the first runs and both finish in FIFO order. README and AGENTS.md document the deviation from barn.
This commit is contained in:
20 files changed
+250
-543
No files matched your search
+51
-45
@@ -21,7 +21,6 @@ const proc = @import("proc.zig");
|
||||
const timestamp = @import("timestamp.zig");
|
||||
const Repository = @import("repository.zig").Repository;
|
||||
const state_mod = @import("state.zig");
|
||||
const Classifier = @import("loadclass.zig").Classifier;
|
||||
const jsonpretty = @import("jsonpretty.zig");
|
||||
const servicemgr = @import("servicemgr.zig");
|
||||
|
||||
@@ -57,7 +56,7 @@ const ReloadState = struct {
|
||||
|
||||
fn reloadConfig(ctx_ptr: ?*anyopaque, arena: Allocator) anyerror!config.Config {
|
||||
const st: *const ReloadState = @ptrCast(@alignCast(ctx_ptr.?));
|
||||
return config.load(arena, st.io, st.env, .{ .explicit_path = st.explicit_path }, null);
|
||||
return config.load(arena, st.io, st.env, .{ .explicit_path = st.explicit_path }, null, null);
|
||||
}
|
||||
|
||||
fn startBackground(ctx: *Context) !u8 {
|
||||
@@ -125,14 +124,11 @@ pub fn cmdServiceStart(ctx: *Context) !u8 {
|
||||
}
|
||||
|
||||
logging.setFromConfig(cfg.service.log_level);
|
||||
const sys_dir = try config.systemConfigDir(ctx.arena, ctx.env);
|
||||
const classifier = try Classifier.loadOrDefaults(ctx.arena, ctx.io, sys_dir);
|
||||
const reload_state = try ctx.arena.create(ReloadState);
|
||||
reload_state.* = .{ .io = ctx.io, .env = ctx.env, .explicit_path = ctx.value("config") };
|
||||
|
||||
var svc = service_mod.Service.init(ctx.gpa, ctx.io, &dirs, .{
|
||||
.config = cfg,
|
||||
.classifier = classifier,
|
||||
.reload_fn = reloadConfig,
|
||||
.reload_ctx = reload_state,
|
||||
});
|
||||
@@ -554,11 +550,10 @@ pub const config_show_usage =
|
||||
\\
|
||||
;
|
||||
|
||||
fn configNode(arena: Allocator, cfg: config.Config, socket: []const u8) !Node {
|
||||
fn configNode(arena: Allocator, cfg: config.Config, socket: []const u8, warnings: []const []const u8) !Node {
|
||||
var root = MapBuilder.init(arena);
|
||||
var s = MapBuilder.init(arena);
|
||||
try s.put("log_level", Node.str(@tagName(cfg.service.log_level)));
|
||||
try s.put("max_concurrent_jobs", Node.num(cfg.service.max_concurrent_jobs));
|
||||
try s.put("heartbeat_interval_seconds", Node.num(cfg.service.heartbeat_interval_seconds));
|
||||
try s.put("ipc_socket", Node.str(socket));
|
||||
try s.put("stale_heartbeat_threshold_seconds", Node.num(cfg.service.stale_heartbeat_threshold_seconds));
|
||||
@@ -588,11 +583,11 @@ fn configNode(arena: Allocator, cfg: config.Config, socket: []const u8) !Node {
|
||||
try st.put("preserve_work_dir", .{ .boolean = cfg.storage.preserve_work_dir });
|
||||
try root.put("storage", try st.done());
|
||||
|
||||
var l = MapBuilder.init(arena);
|
||||
try l.put("max_high_jobs", Node.num(cfg.load_levels.max_high_jobs));
|
||||
try l.put("max_medium_jobs", Node.num(cfg.load_levels.max_medium_jobs));
|
||||
try l.put("max_low_jobs", Node.num(cfg.load_levels.max_low_jobs));
|
||||
try root.put("load_levels", try l.done());
|
||||
if (warnings.len > 0) {
|
||||
const wn = try arena.alloc(Node, warnings.len);
|
||||
for (warnings, wn) |msg, *n| n.* = Node.str(msg);
|
||||
try root.put("warnings", .{ .list = wn });
|
||||
}
|
||||
return root.done();
|
||||
}
|
||||
|
||||
@@ -602,7 +597,7 @@ pub fn cmdConfigShow(ctx: *Context) !u8 {
|
||||
const socket = if (show_defaults) try (config.Config{}).ipcSocketPath(ctx.arena) else try cfg.ipcSocketPath(ctx.arena);
|
||||
|
||||
if (ctx.format != .human) {
|
||||
try ctx.emit(try configNode(ctx.arena, cfg, socket));
|
||||
try ctx.emit(try configNode(ctx.arena, cfg, socket, ctx.config_deprecations.items));
|
||||
return exit_ok;
|
||||
}
|
||||
|
||||
@@ -621,8 +616,8 @@ pub fn cmdConfigShow(ctx: *Context) !u8 {
|
||||
try w.print("Config file: {s}\n", .{try std.mem.join(ctx.arena, ", ", found.items)});
|
||||
}
|
||||
}
|
||||
try w.print("\n[service]\nlog_level = {s}\nmax_concurrent_jobs = {d}\nheartbeat_interval_seconds = {d}\nipc_socket = {s}\nstale_heartbeat_threshold_seconds = {d}\n", .{
|
||||
@tagName(cfg.service.log_level), cfg.service.max_concurrent_jobs, cfg.service.heartbeat_interval_seconds, socket, cfg.service.stale_heartbeat_threshold_seconds,
|
||||
try w.print("\n[service]\nlog_level = {s}\nheartbeat_interval_seconds = {d}\nipc_socket = {s}\nstale_heartbeat_threshold_seconds = {d}\n", .{
|
||||
@tagName(cfg.service.log_level), cfg.service.heartbeat_interval_seconds, socket, cfg.service.stale_heartbeat_threshold_seconds,
|
||||
});
|
||||
try w.print("\n[jobs]\ndefault_timeout_seconds = {d}\nmax_retries = {d}\nretry_delay_seconds = {d}\nretry_backoff_multiplier = {d:.1}\nretry_on_exit_codes = [", .{
|
||||
cfg.jobs.default_timeout_seconds, cfg.jobs.max_retries, cfg.jobs.retry_delay_seconds, cfg.jobs.retry_backoff_multiplier,
|
||||
@@ -635,9 +630,6 @@ pub fn cmdConfigShow(ctx: *Context) !u8 {
|
||||
try w.print("\n[storage]\nbase_dir = {s}\nmax_disk_usage_gb = {d}\npreserve_work_dir = {any}\n", .{
|
||||
cfg.storage.base_dir, cfg.storage.max_disk_usage_gb, cfg.storage.preserve_work_dir,
|
||||
});
|
||||
try w.print("\n[load_levels]\nmax_high_jobs = {d}\nmax_medium_jobs = {d}\nmax_low_jobs = {d}\n", .{
|
||||
cfg.load_levels.max_high_jobs, cfg.load_levels.max_medium_jobs, cfg.load_levels.max_low_jobs,
|
||||
});
|
||||
return exit_ok;
|
||||
}
|
||||
|
||||
@@ -647,6 +639,7 @@ pub const config_validate_usage =
|
||||
\\Usage: zag config validate --file <path>
|
||||
\\
|
||||
\\Check a configuration file for syntax errors, unknown sections or keys, and bad values.
|
||||
\\Deprecated settings are reported as warnings and do not affect the exit code.
|
||||
\\Exits 1 if anything is wrong.
|
||||
\\
|
||||
\\Options:
|
||||
@@ -676,38 +669,53 @@ pub fn cmdConfigValidate(ctx: *Context) !u8 {
|
||||
try list.append(a, .{ .section = "", .key = "", .message = try std.fmt.allocPrint(a, "Parse error at line {d}: {s}", .{ td.line, what }) });
|
||||
}
|
||||
|
||||
if (list.items.len == 0) {
|
||||
if (ctx.format == .human) {
|
||||
try ctx.stdout.print("Configuration is valid: {s}\n", .{path});
|
||||
} else {
|
||||
var m = MapBuilder.init(a);
|
||||
try m.put("valid", .{ .boolean = true });
|
||||
try m.put("file", Node.str(path));
|
||||
try ctx.emit(try m.done());
|
||||
}
|
||||
return exit_ok;
|
||||
var error_count: usize = 0;
|
||||
for (list.items) |p| {
|
||||
if (!p.is_warning) error_count += 1;
|
||||
}
|
||||
const warnings = try problemNodes(a, list.items, true);
|
||||
const errors = try problemNodes(a, list.items, false);
|
||||
|
||||
if (ctx.format == .human) {
|
||||
try ctx.stdout.print("Configuration errors in {s}:\n\n", .{path});
|
||||
for (list.items) |p| {
|
||||
if (p.key.len > 0) try ctx.stdout.print(" Key '{s}': {s}\n", .{ p.key, p.message }) else try ctx.stdout.print(" {s}\n", .{p.message});
|
||||
for (list.items) |p| if (p.is_warning) try ctx.stdout.print(" Warning: {s}\n", .{p.message});
|
||||
if (error_count == 0) {
|
||||
try ctx.stdout.print("Configuration is valid: {s}\n", .{path});
|
||||
} else {
|
||||
try ctx.stdout.print("\nConfiguration errors in {s}:\n\n", .{path});
|
||||
for (list.items) |p| {
|
||||
if (p.is_warning) continue;
|
||||
if (p.key.len > 0) try ctx.stdout.print(" Key '{s}': {s}\n", .{ p.key, p.message }) else try ctx.stdout.print(" {s}\n", .{p.message});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const nodes = try a.alloc(Node, list.items.len);
|
||||
for (list.items, nodes) |p, *n| {
|
||||
var em = MapBuilder.init(a);
|
||||
if (p.key.len > 0) try em.put("key", Node.str(p.key));
|
||||
try em.put("message", Node.str(p.message));
|
||||
n.* = try em.done();
|
||||
}
|
||||
var m = MapBuilder.init(a);
|
||||
try m.put("valid", .{ .boolean = false });
|
||||
try m.put("valid", .{ .boolean = error_count == 0 });
|
||||
try m.put("file", Node.str(path));
|
||||
try m.put("errors", .{ .list = nodes });
|
||||
if (warnings.len > 0) try m.put("warnings", .{ .list = warnings });
|
||||
if (error_count > 0) try m.put("errors", .{ .list = errors });
|
||||
try ctx.emit(try m.done());
|
||||
}
|
||||
return exit_error;
|
||||
return if (error_count == 0) exit_ok else exit_error;
|
||||
}
|
||||
|
||||
/// The JSON node list for the warnings or the errors of a problem list.
|
||||
fn problemNodes(a: Allocator, list: []const config.Problem, warnings_only: bool) ![]Node {
|
||||
var count: usize = 0;
|
||||
for (list) |p| {
|
||||
if (p.is_warning == warnings_only) count += 1;
|
||||
}
|
||||
if (count == 0) return a.alloc(Node, 0);
|
||||
const nodes = try a.alloc(Node, count);
|
||||
var i: usize = 0;
|
||||
for (list) |p| {
|
||||
if (p.is_warning != warnings_only) continue;
|
||||
var em = MapBuilder.init(a);
|
||||
if (p.key.len > 0) try em.put("key", Node.str(p.key));
|
||||
try em.put("message", Node.str(p.message));
|
||||
nodes[i] = try em.done();
|
||||
i += 1;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
fn writeFileCreatingParents(ctx: *Context, path: []const u8, data: []const u8) !void {
|
||||
@@ -756,8 +764,7 @@ pub const config_install_opts = [_]args_mod.Opt{
|
||||
pub const config_install_usage =
|
||||
\\Usage: zag config install [options]
|
||||
\\
|
||||
\\Install the default configuration files (zag.conf and the high/medium/low .load
|
||||
\\whitelists) into the system config directory.
|
||||
\\Install the default configuration file (zag.conf) into the system config directory.
|
||||
\\
|
||||
\\Options:
|
||||
\\ -d, --directory <dir> Target directory (default: /etc/zag)
|
||||
@@ -824,7 +831,6 @@ const bash_completion =
|
||||
\\ case "$prev" in
|
||||
\\ -o|--output) COMPREPLY=( $(compgen -W "human json xml" -- "$cur") ); return ;;
|
||||
\\ -s|--state) COMPREPLY=( $(compgen -W "queued running succeeded failed canceled killed" -- "$cur") ); return ;;
|
||||
\\ -l|--load-level) COMPREPLY=( $(compgen -W "high medium low" -- "$cur") ); return ;;
|
||||
\\ --config|--barn-dir|-d|--directory|-p|--path|-f|--file) COMPREPLY=( $(compgen -f -- "$cur") ); return ;;
|
||||
\\ esac
|
||||
\\ if [[ -z "$cmd" ]]; then
|
||||
@@ -832,7 +838,7 @@ const bash_completion =
|
||||
\\ fi
|
||||
\\ local opts="$global"
|
||||
\\ case "$cmd" in
|
||||
\\ run) opts="$opts -t --tag -l --load-level --max-retries --retry-delay --timeout" ;;
|
||||
\\ run) opts="$opts -t --tag --max-retries --retry-delay --timeout" ;;
|
||||
\\ status) opts="$opts -t --tag -s --state -n --limit" ;;
|
||||
\\ describe) opts="$opts --logs --manifest" ;;
|
||||
\\ usage) opts="$opts -n --limit --csv --summary" ;;
|
||||
|
||||
Reference in new issue
Block a user