Skip to content

Commit

Permalink
Move haxelib_run from exec to spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
l0go committed Jul 1, 2024
1 parent fb6cca8 commit f649614
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Main {
return new promises.Promise((resolve, reject) -> {
if (request.method == http.HttpMethod.Post) {
final body: Request = haxe.Json.parse(request.body);

switch (body.action) {
case Run:
if (body.action != Run) throw "Invalid Action";
Expand All @@ -59,21 +58,27 @@ class Main {
resolve(response);
});
case HaxelibRun:
ChildProcess.exec("haxelib " + body.input, null, (_, stdout, stderr) -> {
var r: Response = if (stderr.trim() == "") {
var process = ChildProcess.spawn("haxelib", body.input.split(" "));
var stdout = "";
process.stdout.on('data', (data) -> {
trace("boo");
stdout += data;
});

process.on("close", (code) -> {
var r: Response = if (code == 0) {
status: Ok,
output: (cast stdout : js.node.Buffer).toString(),
} else {
status: OhNo,
error: (cast stderr : js.node.Buffer).toString(),
error: (cast stdout : js.node.Buffer).toString(),
};
sendResponse(response, r);
resolve(response);
});
default:
throw "Action doesn't exist";
}

} else {
var error = new http.HttpError(405);
error.body = Bytes.ofString("405, method not found");
Expand Down Expand Up @@ -104,7 +109,7 @@ class Main {
ChildProcess.exec('chmod 755 $dir/Main.hx', null, null);
var user = Sys.getEnv("HAXE_USER") ?? Sys.getEnv("USER");

ChildProcess.exec('runuser -l $user -c "haxe params.hxml $hxml -cp $dir"', {timeout: 10000}, (error, stdout, stderr) -> {
ChildProcess.exec('runuser -l $user -c "haxe params.hxml $hxml -cp $dir"', {timeout: 3000}, (error, stdout, stderr) -> {
if (error?.signal == "SIGTERM") onError("Timed out, try again");
if (stderr.trim() != "") onError((cast stderr : js.node.Buffer).toString());
else onOutput((cast stdout : js.node.Buffer).toString());
Expand Down

0 comments on commit f649614

Please sign in to comment.