aboutsummaryrefslogtreecommitdiff
path: root/app/jobs/govuk_guix/job.rb
blob: 295f77d00c0690e6d7e59497083ff5d0df1da7f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'open3'

class GovukGuix::Job < Que::Job
  def run_command(command)
    logger.debug("#{self.class}: Running command #{command.join(' ')}")

    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