resque-progress 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Idris Mokhtarzada
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ resque-progress
2
+ ===============
3
+ Depends on [Resque](http://github.com/defunkt/resque/) 1.8 and
4
+ [resque-meta](http://github.com/lmarlow/resque-meta/) 1.0.0
5
+
6
+
7
+ About
8
+ -----
9
+ Inspired by [resque-status](http://github.com/quirkey/resque-status/).
10
+ Unfortunately, resque-status seems incompatible with resque-meta, so this
11
+ plugin uses resque-meta to provide a similar functionality. This plugin
12
+ differs a bit because it's mainly focused on progress. The resque-meta plugin
13
+ already includes methods for `finished?`, `working?`, `succeeded?`, etc.
14
+
15
+
16
+ Examples
17
+ --------
18
+ class MyJob
19
+ extend Resque::Plugins::Progress
20
+
21
+ def self.perform(meta_id, *args)
22
+ (0..9).each do |i|
23
+ at(i, 10, "Lifted \#{num} heavy things. \#{10-num} more to go!")
24
+ heavy_lifting(i)
25
+ end
26
+ at(10, 10, "Finished lifting everything. Kthxbai!")
27
+ end
28
+ end
29
+
30
+ meta0 = MyJob.enqueue('stuff')
31
+ meta0.progress.num_complete # => 0
32
+ meta0.progress.total # => 10
33
+ meta0.progress.percent # => 100
34
+ meta0.progress.message # => nil
35
+
36
+ # later
37
+ meta1 = MyJob.get_meta('03c9e1a045ad012dd20500264a19273c')
38
+ meta1.finished? # => false
39
+ meta1.progress.num_complete # => 4
40
+ meta1.progress.total # => 10
41
+ meta1.progress.percent # => 40
42
+ meta1.progress.message # => 'Lifted 4 heavy things. 6 more to go!'
43
+
44
+
45
+ Requirements
46
+ ------------
47
+ * [resque](http://github.com/defunkt/resque/) 1.8
48
+ * [resque-meta](http://github.com/lmarlow/resque-meta/) 1.0.0
@@ -0,0 +1,37 @@
1
+ require 'rake/testtask'
2
+
3
+ def command?(command)
4
+ system("type #{command} > /dev/null")
5
+ end
6
+
7
+ #
8
+ # Tests
9
+ #
10
+
11
+ task :default => :test
12
+
13
+ if command? :turn
14
+ desc 'Run tests'
15
+ task :test do
16
+ suffix = "-n #{ENV['TEST']}" if ENV['TEST']
17
+ sh "turn test/*_test.rb #{suffix}"
18
+ end
19
+ else
20
+ Rake::TestTask.new do |t|
21
+ t.libs << 'lib'
22
+ t.pattern = 'test/**/*_test.rb'
23
+ t.verbose = false
24
+ end
25
+ end
26
+
27
+ #
28
+ # Gems
29
+ #
30
+
31
+ begin
32
+ require 'mg'
33
+ MG.new('resque-progress.gemspec')
34
+ rescue LoadError
35
+ warn 'mg not available.'
36
+ warn 'Install it with: gem i mg'
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'resque/plugins/meta'
2
+
3
+ module Resque
4
+ module Plugins
5
+ module Progress
6
+ def self.extended(mod)
7
+ mod.extend(Resque::Plugins::Meta)
8
+ Resque::Plugins::Meta::Metadata.send(:include, Resque::Plugins::Progress::Metadata)
9
+ end
10
+
11
+ def at(num, total, message)
12
+ meta = get_meta(meta_id)
13
+ meta.progress = [num, total, message]
14
+ meta.save
15
+ end
16
+
17
+ module Metadata
18
+ def progress
19
+ p = self['progress'] || [0, 1, nil]
20
+ { :num => p[0].to_i, :total => p[1].to_i, :percent => 100*(p[0].to_f / p[1].to_i), :message => p[2] }
21
+ end
22
+
23
+ def progress=(p)
24
+ self['progress'] = p
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module Resque
2
+ module Plugins
3
+ module Progress
4
+ Version = '1.0.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,70 @@
1
+ require 'resque'
2
+ require 'resque/plugins/progress'
3
+ require 'resque/plugins/progress/version'
4
+
5
+ class ProgressJob
6
+ extend Resque::Plugins::Progress
7
+ @queue = :test
8
+
9
+ def self.expire_meta_in
10
+ 10
11
+ end
12
+
13
+ def self.perform(meta_id)
14
+ (0..4).each do |i|
15
+ at(i, 5, 'working')
16
+ end
17
+ at(5, 5, 'complete')
18
+ end
19
+ end
20
+ class ProgressTest < Test::Unit::TestCase
21
+ def setup
22
+ Resque.redis.flushall
23
+ end
24
+
25
+ def test_progress_version
26
+ assert_equal('1.0.0', Resque::Plugins::Progress::Version)
27
+ end
28
+
29
+ def test_resque_version
30
+ major, minor, patch = Resque::Version.split('.')
31
+ assert_equal 1, major.to_i
32
+ assert minor.to_i >= 8
33
+ end
34
+
35
+ def test_meta_version
36
+ major, minor, patch = Resque::Plugins::Meta::Version.split('.')
37
+ assert_equal 1, major.to_i
38
+ end
39
+
40
+ def test_lint
41
+ assert_nothing_raised do
42
+ Resque::Plugin.lint(Resque::Plugins::Progress)
43
+ end
44
+ end
45
+
46
+ def test_initial_progress
47
+ meta = ProgressJob.enqueue
48
+ assert_not_nil(meta)
49
+ assert_not_nil(meta.progress)
50
+ assert_equal(0, meta.progress[:num])
51
+ assert_equal(1, meta.progress[:total])
52
+ assert_equal(0, meta.progress[:percent])
53
+ assert_nil(meta.progress[:message])
54
+ end
55
+
56
+ def test_final_progress
57
+ meta = ProgressJob.enqueue
58
+ worker = Resque::Worker.new(:test)
59
+ worker.work(0)
60
+
61
+ meta = ProgressJob.get_meta(meta.meta_id)
62
+ assert_not_nil(meta)
63
+ assert(meta.finished?)
64
+ assert_not_nil(meta.progress)
65
+ assert_equal(5, meta.progress[:num])
66
+ assert_equal(5, meta.progress[:total])
67
+ assert_equal(100, meta.progress[:percent])
68
+ assert_equal('complete', meta.progress[:message])
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-progress
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Idris Mokhtarzada
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-24 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: resque
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 55
30
+ segments:
31
+ - 1
32
+ - 8
33
+ - 0
34
+ version: 1.8.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: resque-meta
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: |
54
+ A Resque plugin that provides helpers for progress updates from within your
55
+ jobs.
56
+
57
+ For example:
58
+
59
+ class MyJob
60
+ extend Resque::Plugins::Progress
61
+
62
+ def self.perform(meta_id, *args)
63
+ (0..10).each do |i|
64
+ at(i, 10, "Lifted #{num} heavy things. #{10-num} more to go!")
65
+ heavy_lifting(i)
66
+ end
67
+ end
68
+ end
69
+
70
+ meta0 = MyJob.enqueue('stuff')
71
+ meta0.progress.num_complete # => 0
72
+ meta0.progress.total # => 10
73
+ meta0.progress.percent # => 100
74
+ meta0.progress.message # => nil
75
+
76
+ # later
77
+ meta1 = MyJob.get_meta('03c9e1a045ad012dd20500264a19273c')
78
+ meta1.progress.num_complete # => 4
79
+ meta1.progress.total # => 10
80
+ meta1.progress.percent # => 40
81
+ meta1.progress.message # => 'Lifted 4 heavy things. 6 more to go!'
82
+
83
+ email: idris@umd.edu
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - README.markdown
92
+ - Rakefile
93
+ - LICENSE
94
+ - lib/resque/plugins/progress/version.rb
95
+ - lib/resque/plugins/progress.rb
96
+ - test/progress_test.rb
97
+ has_rdoc: true
98
+ homepage: http://github.com/idris/resque-progress
99
+ licenses: []
100
+
101
+ post_install_message:
102
+ rdoc_options: []
103
+
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project:
127
+ rubygems_version: 1.3.7
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: A Resque plugin for progress updates on jobs.
131
+ test_files: []
132
+