Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
replacing run by Proc::Async as recommended in irc, to takle with buf…
…fering issues
  • Loading branch information
melezhik committed Aug 7, 2019
1 parent fc007e4 commit 460073a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/tasks/bash-hello-world/task.bash
@@ -0,0 +1 @@
echo "hello world from Bash"
6 changes: 3 additions & 3 deletions lib/Sparrow6/Task/Runner/Helpers/Bash.pm6
Expand Up @@ -79,11 +79,11 @@ role Role {

self!log("bash task cmd deployed", $cmd);

my $bash-cmd = self!bash-command($cmd);
my $proc = self!bash-command-async($cmd);

self!capture-cmd-output($bash-cmd);
#self!capture-cmd-output($bash-cmd);

self!handle-task-status($bash-cmd);
#self!handle-task-status($bash-cmd);

}

Expand Down
67 changes: 67 additions & 0 deletions lib/Sparrow6/Task/Runner/Helpers/Common.pm6
Expand Up @@ -85,6 +85,73 @@ role Role {

}

method !bash-command-async ($cmd) {

self!log("effective command", "bash $cmd");

my $proc = Proc::Async.new("bash",$cmd );


react {

whenever $proc.stdout.lines { # split input on \r\n, \n, and \r

my $line = $_;

my $stdout-lines = 0;

self.console($line) unless self.silent;
push self.stdout-data, $line;

#say ‘line: ’, $_

}

whenever $proc.stderr { # chunks

my $line = $_;

push self.stderr-data, $line;
self.console("stderr: $line") unless self.silent;

# say ‘stderr: ’, $_

}

whenever $proc.ready {
#say ‘PID: ’, $_ # Only in Rakudo 2018.04 and newer, otherwise Nil
}

whenever $proc.start {

#say ‘Proc finished: exitcode=’, .exitcode, ‘ signal=’, .signal;

unless self.silent {
self.console("<empty stdout>") if self.stdout-data.elems == 0;
}


my $exit-code = .exitcode;

if $exit-code != 0 and ! $.ignore-task-error {
self.console("task exit status: $exit-code");
self.console("task {self.name} FAILED");
exit($exit-code);
}


# reset ignore-task-error
self.ignore-task-error = False;

done # gracefully jump from the react block

}
}

return

}


method !handle-task-status ($cmd) {

Expand Down

0 comments on commit 460073a

Please sign in to comment.