Sha256: c374e92ffa55314858235f7c307537e2f8fe64008db73de8816ea12db2c9a5fb

Contents?: true

Size: 930 Bytes

Versions: 3

Compression:

Stored size: 930 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 => e
              stringio.puts e.message
              stringio.puts e.backtrace
            ensure
              Process.wait pid
              status = $?.exitstatus
            end
          end
        rescue => e
          stringio.puts e.message
          stringio.puts e.backtrace
          raise e
        ensure
          @alert.update_status(status, info: stringio.string)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mutx-0.2.7 lib/mutx/background_jobs/workers/alerts_worker.rb
mutx-0.2.6 lib/mutx/background_jobs/workers/alerts_worker.rb
mutx-0.2.5 lib/mutx/background_jobs/workers/alerts_worker.rb