From 58813cbd2772f6a4e05159517537881bff7c4ad2 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Sun, 30 Jun 2024 15:23:16 -0300 Subject: [PATCH] Refactor --- src/daemon.cr | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/daemon.cr b/src/daemon.cr index aff5481..6ea45ba 100644 --- a/src/daemon.cr +++ b/src/daemon.cr @@ -69,22 +69,29 @@ post "/funko/build/" do |env| end # Build the thing + response = run_faaso(["build", tmp_dir.to_s]) + + if response["exit_code"] != 0 + halt env, status_code: 500, response: response.to_json + else + response.to_json + end +end + +def run_faaso(args : Array(String)) stderr = IO::Memory.new stdout = IO::Memory.new status = Process.run( command: "faaso", - args: ["build", "-l", tmp_dir.to_s], + args: args + ["-l"], # Always local in the server output: stdout, error: stderr, ) - response = { + { "exit_code" => status.exit_code, "stdout" => stdout.to_s, "stderr" => stderr.to_s, - }.to_json - - halt env, status_code: 500, response: response if status.exit_code != 0 - response + } end Kemal.run