ooyeku/vigil
A process supervision and management library for Zig, inspired by Erlang/OTP's supervisor model.
A process supervision and inter-process communication library for Zig, designed for building reliable distributed systems and concurrent applications.
Version: 0.3.0 - Now with a simplified, intuitive high-level API!
Fetch latest release:
zig fetch --save "git+https://github.com/ooyeku/vigil/#v0.3.0"
Add as a dependency in your build.zig.zon:
const vigil = b.dependency("vigil", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("vigil", vigil.module("vigil"));
b.installArtifact(exe);
const vigil = @import("vigil");
// Create a simple message
var msg = try vigil.msg("Hello World")
.from("sender")
.priority(.high)
.ttl(5000)
.build(allocator);
defer msg.deinit();
fn worker() void {
std.debug.print("Worker running\n", .{});
std.Thread.sleep(100 * std.time.ns_per_ms);
}
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var app = try vigil.app(allocator)
.worker("task1", worker)
.workerPool("pool", worker, 4)
.build();
defer app.shutdown();
try app.start();
}
var inbox = try vigil.inbox(allocator);
defer inbox.close();
try inbox.send("message 1");
try inbox.send("message 2");
if (try inbox.recvTimeout(1000)) |msg_opt| {
if (msg_opt) |msg| {
std.debug.print("Received: {s?}\n", .{msg.payload});
msg.deinit();
}
}
var supervisor = vigil.supervisor(allocator);
try supervisor.child("worker_1", workerFn);
try supervisor.child("worker_2", workerFn);
supervisor.build();
// Production preset: conservative restarts, monitoring enabled
var app = try vigil.appWithPreset(allocator, .production);
// Development preset: verbose logging, quick restarts
var dev_app = try vigil.appWithPreset(allocator, .development);
// High availability mode: intensive health checks
var ha_app = try vigil.appWithPreset(allocator, .high_availability);
inbox() for easy message passingFor advanced use cases, the full low-level API remains available:
const vigil_legacy = @import("vigil/legacy");
// Access all 0.2.x functionality
const supervisor = try vigil_legacy.Supervisor.init(allocator, .{
.strategy = .one_for_all,
.max_restarts = 5,
.max_seconds = 30,
});
See docs/api.md for comprehensive documentation.
See examples/vigilant_server for a complete server implementation using the high-level API.
zig build example-server
zig build test
All 0.2.x code continues to work without changes. To use the new simplified API, see the examples above and the migration guide in docs/api.md.
MIT - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.