resque-alarm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +7 -0
- data/lib/resque/plugins/alarm.rb +30 -0
- data/lib/resque/plugins/alarm_notifier/log_notifier.rb +20 -0
- metadata +50 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) An Vo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
Software), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Resque Alarm
|
2
|
+
===========
|
3
|
+
|
4
|
+
Send out an alarm (at this time, just support email) when queue length reach a threshold.
|
5
|
+
|
6
|
+
To use this gem, config in an initializer
|
7
|
+
|
8
|
+
require 'resque/plugins/alarm'
|
9
|
+
require 'resque/plugins/alarm_notifier/log_notifier'
|
10
|
+
|
11
|
+
Resque::Plugins::Alarm.configure do |config|
|
12
|
+
config.threshold = 10 # Perform notify when queue have more than 10 items
|
13
|
+
config.notifier = Resque::Plugins::AlarmNotifier::LogNotifier.new(Rails.logger, :info) # Notify to rails log
|
14
|
+
end
|
15
|
+
|
16
|
+
Extend in job:
|
17
|
+
|
18
|
+
require 'resque/plugins/alarm'
|
19
|
+
|
20
|
+
class ResqueDoSomethingJob
|
21
|
+
extend Resque::Plugins::Alarm
|
22
|
+
|
23
|
+
@queue = :line1
|
24
|
+
|
25
|
+
def self.perform(params)
|
26
|
+
# magic come here
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
While enqueueing, if any queue has more than 10 items, a log as below will be written to rails log
|
32
|
+
|
33
|
+
{:app=>"app", :source=>"resque", :type=>"queue_too_long", :queues=>{:artwork_file_serve=>11}}
|
34
|
+
|
35
|
+
=========
|
36
|
+
AV
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Resque
|
2
|
+
module Plugins
|
3
|
+
module Alarm
|
4
|
+
class << self
|
5
|
+
attr_accessor :notifier, :threshold
|
6
|
+
def configure
|
7
|
+
yield self
|
8
|
+
end
|
9
|
+
end
|
10
|
+
def after_enqueue_check_alarm(*args)
|
11
|
+
# Dont know which queue to enqueue, so check'em all
|
12
|
+
long_tailer = Resque.queues.inject({}) do|cr,q|
|
13
|
+
size = Resque.size(q)
|
14
|
+
if size > Resque::Plugins::Alarm.threshold
|
15
|
+
cr[q.to_sym] = Resque.size(q)
|
16
|
+
end
|
17
|
+
cr
|
18
|
+
end
|
19
|
+
unless long_tailer.empty?
|
20
|
+
notify(long_tailer)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def notify(params)
|
26
|
+
Resque::Plugins::Alarm.notifier.notify(params)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Resque
|
2
|
+
module Plugins
|
3
|
+
module AlarmNotifier
|
4
|
+
class LogNotifier
|
5
|
+
def initialize(logger, level)
|
6
|
+
@logger = logger
|
7
|
+
@level = level
|
8
|
+
end
|
9
|
+
def notify(params)
|
10
|
+
@logger.info format(params)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def format(params)
|
15
|
+
{ app: "app", source: "resque", type: "queue_too_long", queues: params}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque-alarm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- AnVo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Resque plugin to alarm when queue is too long.
|
15
|
+
email: heosuax@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- Rakefile
|
22
|
+
- LICENSE
|
23
|
+
- lib/resque/plugins/alarm.rb
|
24
|
+
- lib/resque/plugins/alarm_notifier/log_notifier.rb
|
25
|
+
homepage: https://github.com/heosuax/resque-alarm
|
26
|
+
licenses: []
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 1.8.23
|
46
|
+
signing_key:
|
47
|
+
specification_version: 3
|
48
|
+
summary: A Resque plugin to alarm when queue is too long.
|
49
|
+
test_files: []
|
50
|
+
has_rdoc: false
|