resque-alarm 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,10 +7,18 @@ To use this gem, config in an initializer
7
7
 
8
8
  require 'resque/plugins/alarm'
9
9
  require 'resque/plugins/alarm_notifier/log_notifier'
10
+ require 'resque/plugins/alarm_notifier/mail_notifier'
10
11
 
11
12
  Resque::Plugins::Alarm.configure do |config|
12
13
  config.threshold = 10 # Perform notify when queue have more than 10 items
13
14
  config.notifier = Resque::Plugins::AlarmNotifier::LogNotifier.new(Rails.logger, :info) # Notify to rails log
15
+ # OR using mail notifier
16
+ config.notifier = Resque::Plugins::AlarmNotifier::MailNotifier.new(
17
+ "ops@saleshood.com",
18
+ "ops@saleshood.com",
19
+ "alarm",
20
+ "Queue length reached alarm",
21
+ ["Saleshood",Settings.mailer.host_app,"Resque"] )
14
22
  end
15
23
 
16
24
  Extend in job:
@@ -0,0 +1,12 @@
1
+ <p>
2
+ Slow queues:
3
+ </p>
4
+ <p>
5
+ <ul>
6
+ <% @params.each do |queue, size| %>
7
+ <li>
8
+ <span>Queue: <span><strong><%= queue %></strong> has <%= size %> items
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ </p>
@@ -2,12 +2,13 @@ module Resque
2
2
  module Plugins
3
3
  module AlarmNotifier
4
4
  class LogNotifier
5
- def initialize(logger, level)
5
+ def initialize(logger = nil, level = :info)
6
6
  @logger = logger
7
- @level = level
7
+ @level = level.to_sym
8
8
  end
9
9
  def notify(params)
10
- @logger.info format(params)
10
+ return unless @logger.respond_to?(@level)
11
+ @logger.send(@level, format(params))
11
12
  end
12
13
 
13
14
  private
@@ -0,0 +1,29 @@
1
+ module Resque
2
+ module Plugins
3
+ module AlarmNotifier
4
+ class MailNotifier
5
+ def initialize(from, to, subject = "Queue length reached alarm", tags = ["Resque"], template = "alarm")
6
+ @from = from
7
+ @to = to
8
+ @template = template
9
+ @subject = subject
10
+ @tags = tags
11
+ end
12
+ def notify(params)
13
+ @params = params
14
+ text = ERB.new(File.read(File.dirname(__FILE__) + "/#{@template}.html.erb")).result(binding)
15
+ subject = "[#{@tags.join('][')}] #{@subject}"
16
+ MailNotifierMailer.mail_notifier_mailer(@from, @to, subject, text).deliver!
17
+ end
18
+ end
19
+
20
+ class MailNotifierMailer < ::ActionMailer::Base
21
+ def mail_notifier_mailer(from, to, subject, body)
22
+ mail :from => from, :to => to, :subject => subject do |format|
23
+ format.html { render :text => body }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-alarm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,7 +21,9 @@ files:
21
21
  - Rakefile
22
22
  - LICENSE
23
23
  - lib/resque/plugins/alarm.rb
24
+ - lib/resque/plugins/alarm_notifier/alarm.html.erb
24
25
  - lib/resque/plugins/alarm_notifier/log_notifier.rb
26
+ - lib/resque/plugins/alarm_notifier/mail_notifier.rb
25
27
  homepage: https://github.com/heosuax/resque-alarm
26
28
  licenses: []
27
29
  post_install_message: