Module: TaskWithAirbrake

Defined in:
lib/task_with_airbrake.rb,
lib/task_with_airbrake/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.echo(str) ⇒ Object



24
25
26
27
# File 'lib/task_with_airbrake.rb', line 24

def self.echo(str)
  puts(Rails.logger.info(str))
  Rails.logger.flush
end

.execute_task(*args, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/task_with_airbrake.rb', line 4

def self.execute_task(*args, &block)
  new_block = proc {
    begin
      self.echo "[CRON START] #{args.inspect} (#{Time.now})"

      yield if block_given?

      self.echo "[CRON END] #{args.inspect} (#{Time.now})"
    rescue Exception => e
      self.echo "[CRON ERROR] #{e} (#{Time.now})"
      e.backtrace.each { |l| self.echo l }
      Airbrake.notify(e)
      raise e
    ensure
      Rails.logger.flush
    end
  }
  task(*args, &new_block)
end