aboutsummaryrefslogtreecommitdiff
path: root/app/jobs/govuk_guix/job.rb
blob: 0161cb1b13dd69ba25626d89b887a5d4a40f75a0 (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
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