From 6681db87b609a50cdbf18b690c4b6d2398b22a01 Mon Sep 17 00:00:00 2001 From: Lozko1991 Date: Sun, 30 Nov 2025 20:44:08 +0000 Subject: [PATCH] 0.16.0 adaptation, JetBrains settings --- .idea/.gitignore | 10 + .idea/cronz16.iml | 8 + .idea/editor.xml | 249 +++++++++++++++++++++ .idea/modules.xml | 8 + .idea/runConfigurations/Build.xml | 13 ++ .idea/vcs.xml | 7 + .idea/zigbrains.xml | 358 ++++++++++++++++++++++++++++++ examples/basic/main.zig | 9 +- examples/thread_mode/main.zig | 10 +- src/cronz.zig | 10 +- 10 files changed, 674 insertions(+), 8 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/cronz16.iml create mode 100644 .idea/editor.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations/Build.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/zigbrains.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/cronz16.iml b/.idea/cronz16.iml new file mode 100644 index 0000000..bc2cd87 --- /dev/null +++ b/.idea/cronz16.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..fef3201 --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,249 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..df93ce9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Build.xml b/.idea/runConfigurations/Build.xml new file mode 100644 index 0000000..5fb5962 --- /dev/null +++ b/.idea/runConfigurations/Build.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/zigbrains.xml b/.idea/zigbrains.xml new file mode 100644 index 0000000..b40371b --- /dev/null +++ b/.idea/zigbrains.xml @@ -0,0 +1,358 @@ + + + + + + + \ No newline at end of file diff --git a/examples/basic/main.zig b/examples/basic/main.zig index cbd5ee8..feb2b9a 100644 --- a/examples/basic/main.zig +++ b/examples/basic/main.zig @@ -8,7 +8,9 @@ pub fn main() !void { defer arena_instance.deinit(); allocator = arena_instance.allocator(); - const cronz = try Cronz.create(allocator); + var threaded : std.Io.Threaded = .init(allocator); + defer threaded.deinit(); + const cronz = try Cronz.create(threaded.io(), allocator); // executes tasks on every 0th, 5th, 10th, 20th, 30th and 40th second of each minute try cronz.AddCronJob("0,5,10,20,30,40 * * * * *", "task-1", task1); @@ -24,7 +26,10 @@ fn task1() !void { msg = try allocator.alloc(u8, 100); msg = try std.fmt.bufPrint(msg, "Task 1 performed", .{}); - std.log.debug("{d} {s}", .{ std.time.microTimestamp(), msg }); + var threaded : std.Io.Threaded = .init(allocator); + defer threaded.deinit(); + const io = threaded.io(); + std.log.debug("{d} {s}", .{ (try std.Io.Clock.Timestamp.now(io, .real)).raw.nanoseconds, msg }); } fn task2() !void { diff --git a/examples/thread_mode/main.zig b/examples/thread_mode/main.zig index d5e64f9..2b6f736 100644 --- a/examples/thread_mode/main.zig +++ b/examples/thread_mode/main.zig @@ -13,7 +13,10 @@ pub fn main() !void { // allocator = gpa.allocator(); // defer _ = gpa.detectLeaks(); - const cronz = try Cronz.create(allocator); + var threaded : std.Io.Threaded = .init(allocator); + defer threaded.deinit(); + const io = threaded.io(); + const cronz = try Cronz.create(io, allocator); // executes tasks on every 0th, 10th, 20th, 30th and 40th second of each minute try cronz.AddCronJob("0,10,20,30,40 * * * * *", "task-1", task1); @@ -36,7 +39,10 @@ fn task1() !void { msg = try allocator.alloc(u8, 100); msg = try std.fmt.bufPrint(msg, "Task 1 performed", .{}); - std.log.debug("{d} {s}", .{ std.time.microTimestamp(), msg }); + var threaded : std.Io.Threaded = .init(allocator); + defer threaded.deinit(); + const io = threaded.io(); + std.log.debug("{d} {s}", .{ (try std.Io.Clock.Timestamp.now(io, .real)).raw.nanoseconds, msg }); } fn task2() !void { diff --git a/src/cronz.zig b/src/cronz.zig index 7de5f50..b92aa24 100644 --- a/src/cronz.zig +++ b/src/cronz.zig @@ -29,8 +29,9 @@ thread: std.Thread = undefined, jobs: std.array_list.Managed(*job) = undefined, mutex: std.Thread.Mutex = undefined, signal: Atomic(bool) = undefined, +io: std.Io = undefined, -pub fn create(allocator: std.mem.Allocator) !*Cronz { +pub fn create(io: std.Io, allocator: std.mem.Allocator) !*Cronz { const c = try allocator.create(Cronz); errdefer allocator.destroy(c); @@ -39,6 +40,7 @@ pub fn create(allocator: std.mem.Allocator) !*Cronz { c.signal = Atomic(bool).init(true); c.jobs = std.array_list.Managed(*job).init(allocator); c.thread = try Thread.spawn(.{}, Cronz.runSchedules, .{c}); + c.io = io; _cronz = c; @@ -63,7 +65,7 @@ fn registerInterruption() void { }, null); } -fn shutdown(_: c_int) callconv(.c) void { +fn shutdown(_: std.posix.SIG) callconv(.c) void { _cronz.signal.store(false, .release); } @@ -109,9 +111,9 @@ pub fn destroy(self: *Self) void { self.thread.join(); } -fn runSchedules(self: *Self) void { +fn runSchedules(self: *Self) !void { while (self.signal.load(.monotonic)) { - std.Thread.sleep(std.time.ns_per_s); + try std.Io.Clock.Duration.sleep(.{ .clock = .real, .raw = .fromSeconds(1) }, self.io); const now = Datetime.nowUTC(); for (self.jobs.items) |j| { if (j.compare(now)) {