-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.zig
More file actions
36 lines (26 loc) · 1.01 KB
/
Copy pathmain.zig
File metadata and controls
36 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const std = @import("std");
const Cronz = @import("cronz");
var allocator: std.mem.Allocator = undefined;
pub fn main() !void {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena_instance.deinit();
allocator = arena_instance.allocator();
const cronz = try Cronz.create(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);
//execute tasks on every 2 second
try cronz.AddCronJob("*/2 * * * * *", "task-2", task2);
cronz.Run();
}
fn task1() !void {
var msg: []u8 = undefined;
msg = try allocator.alloc(u8, 100);
msg = try std.fmt.bufPrint(msg, "Task 1 performed", .{});
std.log.debug("{d} {s}", .{ std.time.microTimestamp(), msg });
}
fn task2() !void {
var msg: []u8 = undefined;
msg = try allocator.alloc(u8, 100);
msg = try std.fmt.bufPrint(msg, "Task 2 performed", .{});
std.log.debug("{s}", .{msg});
}