Sha256: bd094eea5dac37b51a2de69ae448e8e594052e1957a33db2ade430c088792d41

Contents?: true

Size: 829 Bytes

Versions: 2

Compression:

Stored size: 829 Bytes

Contents

# encoding: utf-8
require 'sidekiq'

module Mutx
  module Workers
    class AlertsWorker
      include Sidekiq::Worker

      sidekiq_options retry: false
      
      def perform(args)
        stringio = StringIO.new
        @alert = Alert.find(name: args['name'])
        status = nil
        begin
          PTY.spawn("ruby #{args['path']}") do |stdout, stdin, pid|
            begin
              stdout.each do |line|
                stringio.puts line
              end
            rescue Errno::EIO
            ensure
              Process.wait pid
              status = $?.exitstatus
            end
          end
        rescue => e
          puts e.message
          puts e.backtrace
          raise e
        ensure
          @alert.update_status(status, info: stringio.string)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mutx-0.2.9 lib/mutx/background_jobs/workers/alerts_worker.rb
mutx-0.2.8 lib/mutx/background_jobs/workers/alerts_worker.rb