Module: Proby

Defined in:
lib/proby.rb,
lib/proby/version.rb,
lib/proby/notifier.rb,
lib/proby/exceptions.rb,
lib/proby/proby_task.rb,
lib/proby/resque_plugin.rb,
lib/proby/proby_http_api.rb

Defined Under Namespace

Modules: ResquePlugin Classes: ApiException, AuthFailedException, InvalidApiKeyException, InvalidParameterException, Notifier, ProbyHttpApi, ProbyTask, ProbyTaskStatus

Constant Summary collapse

VERSION =
"2.2.0"

Class Method Summary collapse

Class Method Details

.api_keyObject

Get the api key.



27
28
29
# File 'lib/proby.rb', line 27

def api_key
  @api_key
end

.api_key=(api_key) ⇒ Object

Set your Proby API key.

Examples:

Proby.api_key = '1234567890abcdefg'

Parameters:

  • api_key (String)

    Your Proby API key



22
23
24
# File 'lib/proby.rb', line 22

def api_key=(api_key)
  @api_key = api_key
end

.loggerObject

Get the logger used by Proby.



43
44
45
# File 'lib/proby.rb', line 43

def logger
  @logger ||= Logger.new("/dev/null")
end

.logger=(logger) ⇒ Object

Set the logger to be used by Proby.

Examples:

Proby.logger = Rails.logger
Proby.logger = Logger.new(STDERR)

Parameters:

  • logger (Logger)

    The logger you would like Proby to use



38
39
40
# File 'lib/proby.rb', line 38

def logger=(logger)
  @logger = logger
end

.monitor(proby_task_id = nil) ⇒ Object

Surround the block of code with Proby start and finish notifications. If an exception is raised in the block of code, then the task will be marked as failed, and the exception’s message and backtrace will be sent to Proby as the task’s error message.

Parameters:

  • proby_task_id (String) (defaults to: nil)

    The id of the task to be notified. If nil, the value of the PROBY_TASK_ID environment variable will be used.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/proby.rb', line 79

def monitor(proby_task_id=nil)
  failed = false
  error_message = nil
  begin
    Proby.send_start_notification(proby_task_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
    Proby.send_finish_notification(proby_task_id, :failed => failed, :error_message => error_message)
  end
end

.send_finish_notification(proby_task_id = nil, options = {}) ⇒ Fixnum

Send a finish notification for this task to Proby

Parameters:

  • proby_task_id (String) (defaults to: nil)

    The id of the task to be notified. If nil, the value of the PROBY_TASK_ID environment variable will be used.

  • options (Hash) (defaults to: {})

    The options for the finish notification

Options Hash (options):

  • :failed (Boolean)

    true if this task run resulted in some sort of failure. Setting this parameter to true will trigger a notification to be sent to the alarms configured for the given task. Defaults to false.

  • :error_message (String)

    A string message describing the failure that occurred. 1,000 character limit.

Returns:

  • (Fixnum)

    The HTTP status code that was returned from Proby.



69
70
71
# File 'lib/proby.rb', line 69

def send_finish_notification(proby_task_id=nil, options={})
  Notifier.send_notification('finish', proby_task_id, options)
end

.send_start_notification(proby_task_id = nil) ⇒ Fixnum

Send a start notification for this task to Proby.

Parameters:

  • proby_task_id (String) (defaults to: nil)

    The id of the task to be notified. If nil, the value of the PROBY_TASK_ID environment variable will be used.

Returns:

  • (Fixnum)

    The HTTP status code that was returned from Proby.



53
54
55
# File 'lib/proby.rb', line 53

def send_start_notification(proby_task_id=nil)
  Notifier.send_notification('start', proby_task_id)
end