class Resque::Failure::SlackNotifier

Constants

DEFAULT_CONFIG_OPTIONS

Attributes

client[RW]
config[RW]

Public Class Methods

config_path=(path) click to toggle source
# File lib/resque/failure/slack_notifier.rb, line 26
def config_path=(path)
  configure YAML.load_file(path).symbolize_keys
end
configure(**options) click to toggle source
# File lib/resque/failure/slack_notifier.rb, line 16
def configure(**options)
  valid_keys      = %i(webhook_url channel display_name notify_channel)
  config_options  = options.select { |key| valid_keys.include? key }

  self.config = DEFAULT_CONFIG_OPTIONS.merge config_options
  self.client = Slack::Notifier.new config[:webhook_url],
    channel:  config[:channel],
    username: config[:display_name]
end
count() click to toggle source
# File lib/resque/failure/slack_notifier.rb, line 30
def count
  Stat[:failed]
end

Public Instance Methods

client() click to toggle source
# File lib/resque/failure/slack_notifier.rb, line 35
def client
  self.class.client
end
config() click to toggle source
# File lib/resque/failure/slack_notifier.rb, line 39
def config
  self.class.config
end
save() click to toggle source
# File lib/resque/failure/slack_notifier.rb, line 43
def save
  raise "Client not configured" unless client && config

  message = [
    "#{"<!channel> " if config[:notify_channel]}Resque worker failure!",
    "Worker: #{worker}",
    "Queue:  #{queue}",
    "Job:    #{payload['class']}",
    "Args:   #{payload['args']}"
  ].join "\n"

  client.ping message
end