resque-queue-stats 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.6.4"
11
+ gem 'resque'
12
+ gem 'ruby-debug19'
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ archive-tar-minitar (0.5.2)
5
+ columnize (0.3.4)
6
+ git (1.2.5)
7
+ jeweler (1.6.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ json (1.5.3)
12
+ linecache19 (0.5.12)
13
+ ruby_core_source (>= 0.1.4)
14
+ rack (1.3.0)
15
+ rake (0.9.2)
16
+ redis (2.2.1)
17
+ redis-namespace (1.0.3)
18
+ redis (< 3.0.0)
19
+ resque (1.17.1)
20
+ json (>= 1.4.6, < 1.6)
21
+ redis-namespace (~> 1.0.2)
22
+ sinatra (>= 0.9.2)
23
+ vegas (~> 0.1.2)
24
+ ruby-debug-base19 (0.11.25)
25
+ columnize (>= 0.3.1)
26
+ linecache19 (>= 0.5.11)
27
+ ruby_core_source (>= 0.1.4)
28
+ ruby-debug19 (0.11.6)
29
+ columnize (>= 0.3.1)
30
+ linecache19 (>= 0.5.11)
31
+ ruby-debug-base19 (>= 0.11.19)
32
+ ruby_core_source (0.1.5)
33
+ archive-tar-minitar (>= 0.5.2)
34
+ sinatra (1.2.6)
35
+ rack (~> 1.1)
36
+ tilt (>= 1.2.2, < 2.0)
37
+ tilt (1.3.2)
38
+ vegas (0.1.8)
39
+ rack (>= 1.0.0)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.0.0)
46
+ jeweler (~> 1.6.4)
47
+ resque
48
+ ruby-debug19
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alan Peabody
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = resque-queue-stats
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to resque-queue-stats
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 alanpeabody. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "resque-queue-stats"
18
+ gem.homepage = "http://github.com/alanpeabody/resque-queue-stats"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Track jobs processed by queue, longest queue time}
21
+ gem.description = %Q{Track jobs processed by queue, longest queue time}
22
+ gem.email = "gapeabody@gmail.com"
23
+ gem.authors = ["alanpeabody"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ #require 'rake/rdoctask'
38
+ #Rake::RDocTask.new do |rdoc|
39
+ #version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ #rdoc.rdoc_dir = 'rdoc'
42
+ #rdoc.title = "resque-queue-stats #{version}"
43
+ #rdoc.rdoc_files.include('README*')
44
+ #rdoc.rdoc_files.include('lib/**/*.rb')
45
+ #end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,44 @@
1
+ require 'resque'
2
+ require 'ruby-debug'
3
+
4
+ module Resque
5
+ module Plugins
6
+ module QueueStats
7
+
8
+ def performed_count
9
+ Resque.redis.get("stat:queue:#{@queue}:performed").to_i
10
+ end
11
+
12
+ def reset_performed_count
13
+ Resque.redis.set("stat:queue:#{@queue}:performed",0)
14
+ end
15
+
16
+ def reset_longest_job
17
+ Resque.redis.set("stat:queue:#{@queue}:longest_job",0.0)
18
+ end
19
+
20
+ def longest_job
21
+ Resque.redis.get("stat:queue:#{@queue}:longest_job").to_f
22
+ end
23
+
24
+ def after_perform_queue_stats(*payload)
25
+ Resque.redis.incr("stat:queue:#{@queue}:performed")
26
+ end
27
+
28
+ def around_perform_queue_stats(*payload)
29
+ start = Time.now
30
+
31
+ yield
32
+
33
+ total_time = Time.now - start
34
+
35
+ Resque.redis.multi do
36
+ if longest_job.to_f < total_time.to_f
37
+ Resque.redis.set("stat:queue:#{@queue}:longest_job",total_time)
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1 @@
1
+ require 'resque/plugins/queue_stats'
data/test/helper.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'resque'
12
+
13
+ Resque.redis = 'localhost:6379'
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+ require 'resque-queue-stats'
18
+
19
+
20
+ class Test::Unit::TestCase
21
+ end
@@ -0,0 +1,49 @@
1
+ require 'helper'
2
+
3
+ class Job
4
+ extend Resque::Plugins::QueueStats
5
+ @queue = :test
6
+
7
+ def self.perform(sleep_time = 0.1)
8
+ sleep sleep_time
9
+ end
10
+ end
11
+
12
+ class TestResqueQueueStats < Test::Unit::TestCase
13
+ def setup
14
+ @worker = Resque::Worker.new(:test)
15
+ end
16
+
17
+ def test_lint
18
+ assert_nothing_raised do
19
+ Resque::Plugin.lint(Resque::Plugins::QueueStats)
20
+ end
21
+ end
22
+
23
+ def test_performed_count
24
+
25
+ Job.reset_performed_count
26
+
27
+ assert_equal 0, Job.performed_count
28
+
29
+ 3.times { Resque.enqueue(Job) }
30
+ 3.times { @worker.work(0) }
31
+
32
+ assert_equal 3, Job.performed_count
33
+
34
+ end
35
+
36
+ def test_longest_job
37
+
38
+ Job.reset_longest_job
39
+
40
+ assert_equal 0, Job.longest_job
41
+
42
+ 2.times { Resque.enqueue(Job) }
43
+ Resque.enqueue(Job,0.5)
44
+
45
+ 3.times { @worker.work(0) }
46
+
47
+ assert Job.longest_job > 0.4
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-queue-stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - alanpeabody
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-07 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: &8443900 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *8443900
26
+ - !ruby/object:Gem::Dependency
27
+ name: jeweler
28
+ requirement: &8442280 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *8442280
37
+ - !ruby/object:Gem::Dependency
38
+ name: resque
39
+ requirement: &8440900 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *8440900
48
+ - !ruby/object:Gem::Dependency
49
+ name: ruby-debug19
50
+ requirement: &8438540 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *8438540
59
+ description: Track jobs processed by queue, longest queue time
60
+ email: gapeabody@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.rdoc
66
+ files:
67
+ - .document
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ - Rakefile
73
+ - VERSION
74
+ - lib/resque-queue-stats.rb
75
+ - lib/resque/plugins/queue_stats.rb
76
+ - test/helper.rb
77
+ - test/test_queue_stats.rb
78
+ has_rdoc: true
79
+ homepage: http://github.com/alanpeabody/resque-queue-stats
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: 1131021091895903081
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.6.2
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Track jobs processed by queue, longest queue time
107
+ test_files: []