Module: ProbyNotifier::ResquePlugin

Defined in:
lib/proby_notifier/resque_plugin.rb

Overview

Automatically notifies Proby when this job starts and finishes.

class SomeJob
  extend ProbyNotifier::ResquePlugin

  self.perform
    do_stuff
  end
end

The Proby Task ID can be set in one of two ways. The most common way is to put the ID in an ENV variable that is set in your crontab. This ID will be transparently passed to the Resque job via Redis.

0 0 * * * PROBY_TASK_ID=abc123 ./queue_some_job

Alternatively, if you’re not using cron and therefore don’t want that support, you can just set the @proby_id ivar in the class, like so.

class SomeJob
  extend ProbyNotifier::ResquePlugin
  @proby_id = 'abc123'

  self.perform
    do_stuff
  end
end

Setting the @proby_id variable will take precendence over the ENV variable.

Instance Method Summary collapse

Instance Method Details

#around_perform_proby(*args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/proby_notifier/resque_plugin.rb', line 49

def around_perform_proby(*args)
  failed = false
  error_message = nil
  _proby_id = proby_id(*args)
  ProbyNotifier.send_start_notification(_proby_id)
  yield
rescue Exception => e
  failed = true
  error_message = "#{e.class.name}: #{e.message}"
  error_message << "\n#{e.backtrace.join("\n")}" if e.backtrace
  raise e
ensure
  ProbyNotifier.send_finish_notification(_proby_id, :failed => failed, :error_message => error_message)
end

#before_enqueue_proby(*args) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/proby_notifier/resque_plugin.rb', line 37

def before_enqueue_proby(*args)
  return true if @proby_id

  env_proby_id = ENV['PROBY_TASK_ID']
  Resque.redis.setex(proby_id_bucket(*args), 24.hours, env_proby_id)
  return true
end

#proby_id(*args) ⇒ Object



45
46
47
# File 'lib/proby_notifier/resque_plugin.rb', line 45

def proby_id(*args)
  @proby_id || Resque.redis.get(proby_id_bucket(*args))
end

#proby_id_bucket(*args) ⇒ Object



33
34
35
# File 'lib/proby_notifier/resque_plugin.rb', line 33

def proby_id_bucket(*args)
  "proby_id:#{name}-#{args.to_s}"
end