From a7c72d5ad220ec24a94164e70ae7c1dbec55fcc9 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 28 Aug 2024 10:27:29 -0700 Subject: [PATCH] add wait loop in invoke to make sure the update has been processed --- lambdabuild/Invoke.zig | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lambdabuild/Invoke.zig b/lambdabuild/Invoke.zig index 53504d0..775d630 100644 --- a/lambdabuild/Invoke.zig +++ b/lambdabuild/Invoke.zig @@ -52,6 +52,33 @@ fn make(step: *std.Build.Step, node: std.Progress.Node) anyerror!void { .client = client, .region = try self.options.region.region(), }; + var inx: usize = 10; // 200ms * 10 + while (inx > 0) : (inx -= 1) { + var diagnostics = aws.Diagnostics{ + .http_code = undefined, + .response_body = undefined, + .allocator = self.step.owner.allocator, + }; + const call = aws.Request(services.lambda.get_function).call(.{ + .function_name = self.options.name, + }, options) catch |e| { + // There seems an issue here, but realistically, we have an arena + // so there's no leak leaving this out + defer diagnostics.deinit(); + if (diagnostics.http_code == 404) continue; // function was just created...it's ok + return step.fail( + "Unknown error {} from Lambda GetFunction. HTTP code {}, message: {s}", + .{ e, diagnostics.http_code, diagnostics.response_body }, + ); + }; + defer call.deinit(); + if (!std.mem.eql(u8, "InProgress", call.response.configuration.?.last_update_status.?)) + break; // We're ready to invoke! + const ms: usize = if (inx == 5) 500 else 50; + std.time.sleep(ms * std.time.ns_per_ms); + } + if (inx == 0) + return step.fail("Timed out waiting for lambda to update function", .{}); const call = try aws.Request(services.lambda.invoke).call(.{ .function_name = self.options.name, .payload = self.options.payload,