diff options
Diffstat (limited to 'app/jobs/govuk_guix/job.rb')
-rw-r--r-- | app/jobs/govuk_guix/job.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/jobs/govuk_guix/job.rb b/app/jobs/govuk_guix/job.rb new file mode 100644 index 0000000..0161cb1 --- /dev/null +++ b/app/jobs/govuk_guix/job.rb @@ -0,0 +1,24 @@ +class GovukGuix::Job < Que::Job + def run_command(command) + logger.debug("#{self.class}: Running command #{command}") + + Open3.popen2e(*command) do |stdin, stdout_and_stderr, wait_thr| + logger.info("#{self.class}: commmand running, pid #{wait_thr.pid}") + + output = [] + stdout_and_stderr.each_line do |line| + logger.debug("#{self.class}: #{line}") + output << line + end + + exit_status = wait_thr.value + unless exit_status == 0 + logger.error("#{self.class}: failed, exit status #{exit_status}") + + raise "#{output.join}\n" + end + + yield(output) + end + end +end |