jetzig/demo/src/app/views/background_jobs.zig
Bob Farrell 789f123926 Improve test App requestJob
Detect if provided params are a subset of actual params, provide
informative errors if not.
2025-05-05 13:30:42 +01:00

26 lines
821 B
Zig

const std = @import("std");
const jetzig = @import("jetzig");
/// This example demonstrates usage of Jetzig's background jobs.
pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
// Prepare a job using `src/app/jobs/example.zig`.
var job = try request.job("example");
// Add a param `foo` to the job.
try job.params.put("foo", data.string("bar"));
try job.params.put("id", data.integer(std.crypto.random.int(u32)));
// Schedule the job for background processing.
try job.schedule();
return request.render(.ok);
}
test "index" {
var app = try jetzig.testing.app(std.testing.allocator, @import("routes"));
defer app.deinit();
const response = try app.request(.GET, "/background_jobs", .{});
try response.expectJob("example", .{ .foo = "bar" });
}