resque-multi-step 1.1.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ Version 2.0.0
2
+ =====
3
+
4
+ Add support to reference the original multi-step-task job from within the job classes.
5
+
1
6
  Version 1.1.3
2
7
  =====
3
8
 
data/README.md CHANGED
@@ -57,6 +57,28 @@ Then you can look it up using the `.find` method on `MultiStepTask`.
57
57
  redirect_to blog_url(blog)
58
58
  end
59
59
 
60
+ As of version 2.0.0, you can also get a handle on the original multi-step
61
+ task. This is useful if you need to add another job on the fly, that needs
62
+ to happen before the finalization.
63
+
64
+ class ConvertPostToPirateTalk
65
+ def self.perform(post_id)
66
+ p = Post.find(post_id)
67
+ p.convert_to_pirate_talk
68
+ p.save
69
+
70
+ if p.has_comments?
71
+ p.comments.each do |c|
72
+ # #multi_step_task is a class method defined on the class
73
+ # before invoking #perform as a convenience. you can also
74
+ # use #multi_step_task_id to just get the resque key.
75
+ multi_step_task.add_job ConvertCommentToPirateTalk, c.id
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+
60
82
  Finalization
61
83
  ----
62
84
 
@@ -91,7 +113,7 @@ Details
91
113
  MultiStepTask creates a queue in resque for each task. To process
92
114
  multi-step jobs you will need at least one Resque worker with
93
115
  `QUEUES=*`. This combined with [resque-fairly][] provides fair
94
- scheduling of the constituent jobs.
116
+ scheduling of the constituent jobs.
95
117
 
96
118
  Having a queue per multi-step task means that is easy to determine to
97
119
  what task a particular job belongs. It also provides a nice way to see
@@ -99,6 +121,8 @@ what is going on in the system at any given time. Just got to
99
121
  resque-web and look the queue list. Use meaningful slugs for your
100
122
  tasks and you get a quick birds-eye view of what is going on.
101
123
 
124
+ As of version 2.0.0 MultiStepTask requires ruby 1.9 or higher.
125
+
102
126
  Note on Patches/Pull Requests
103
127
  ----
104
128
 
@@ -106,9 +130,8 @@ Note on Patches/Pull Requests
106
130
  * Make your feature addition or bug fix.
107
131
  * Add tests for it. This is important so I don't break it in a
108
132
  future version unintentionally.
109
- * Update history to reflect the change.
110
- * Commit, do not mess with rakefile, version.
111
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
133
+ * Update history to reflect the change, increment the version properly as described at <http://semver.org/>.
134
+ * Commit
112
135
  * Send me a pull request. Bonus points for topic branches.
113
136
 
114
137
  Mailing List
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- require 'rcov'
4
3
 
5
4
  begin
6
5
  require 'jeweler'
@@ -25,13 +24,12 @@ begin
25
24
  rescue LoadError
26
25
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
27
26
  end
28
-
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |t|
31
- t.libs << 'lib' << 'spec'
32
- t.pattern = 'spec/**/*_spec.rb'
33
- t.verbose = true
34
- end
27
+
28
+ require 'rspec/core/rake_task'
29
+
30
+ RSpec::Core::RakeTask.new(:spec)
31
+
32
+ task :default => :spec
35
33
 
36
34
  require 'rake/rdoctask'
37
35
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3
1
+ 2.0.0
@@ -104,7 +104,11 @@ module Resque
104
104
  logger.debug("[Resque Multi-Step-Task] Executing #{job_module_name} job for #{task_id} at #{start_time} (args: #{args})")
105
105
 
106
106
  # perform the task
107
- constantize(job_module_name).perform(*args)
107
+ klass = constantize(job_module_name)
108
+ klass.singleton_class.class_eval "def multi_step_task; @@task ||= MultiStepTask.find('#{task_id}'); end"
109
+ klass.singleton_class.class_eval "def multi_step_task_id; @@task_id ||= '#{task_id}'; end"
110
+
111
+ klass.perform(*args)
108
112
 
109
113
  logger.debug("[Resque Multi-Step-Task] Finished executing #{job_module_name} job for #{task_id} at #{Time.now}, taking #{(Time.now - start_time)} seconds.")
110
114
  rescue Exception => e
@@ -12,7 +12,10 @@ module Resque
12
12
  task = MultiStepTask.find(task_id)
13
13
 
14
14
  begin
15
- constantize(job_module_name).perform(*args)
15
+ klass = constantize(job_module_name)
16
+ klass.singleton_class.class_eval "def multi_step_task; @@task ||= MultiStepTask.find('#{task_id}'); end"
17
+ klass.singleton_class.class_eval "def multi_step_task_id; @@task_id ||= '#{task_id}'; end"
18
+ klass.perform(*args)
16
19
  rescue Exception
17
20
  task.increment_failed_count
18
21
  raise
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{resque-multi-step}
8
- s.version = "1.1.3"
7
+ s.name = "resque-multi-step"
8
+ s.version = "2.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Williams", "Morgan Whitney"]
12
- s.date = %q{2011-05-23}
13
- s.description = %q{Provides multi-step tasks with finalization and progress tracking}
14
- s.email = %q{pezra@barelyenough.org}
12
+ s.date = "2012-06-14"
13
+ s.description = "Provides multi-step tasks with finalization and progress tracking"
14
+ s.email = "pezra@barelyenough.org"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.md"
@@ -40,22 +40,12 @@ Gem::Specification.new do |s|
40
40
  "spec/spec.opts",
41
41
  "spec/spec_helper.rb"
42
42
  ]
43
- s.homepage = %q{http://github.com/pezra/resque-multi-step}
43
+ s.homepage = "http://github.com/pezra/resque-multi-step"
44
44
  s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.7}
46
- s.summary = %q{Provides multi-step tasks with finalization and progress tracking}
47
- s.test_files = [
48
- "spec/acceptance/acceptance_jobs.rb",
49
- "spec/acceptance/job_handling_spec.rb",
50
- "spec/acceptance/spec_helper.rb",
51
- "spec/resque-multi-step_spec.rb",
52
- "spec/resque/plugins/multi_step_task/finalization_job_spec.rb",
53
- "spec/resque/plugins/multi_step_task_spec.rb",
54
- "spec/spec_helper.rb"
55
- ]
45
+ s.rubygems_version = "1.8.16"
46
+ s.summary = "Provides multi-step tasks with finalization and progress tracking"
56
47
 
57
48
  if s.respond_to? :specification_version then
58
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
49
  s.specification_version = 3
60
50
 
61
51
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -27,5 +27,12 @@ module MultiStepAcceptance
27
27
  end
28
28
  end
29
29
  end
30
+
31
+ class BackRefJob
32
+ def self.perform
33
+ str = multi_step_task_id
34
+ mst = multi_step_task
35
+ end
36
+ end
30
37
 
31
38
  end
@@ -121,3 +121,28 @@ describe "Acceptance: Task with retried finalization failure" do
121
121
  end
122
122
 
123
123
  end
124
+
125
+ describe "Acceptance: Task needing to reference the original Multi-Step-Task" do
126
+ let(:task) do
127
+ Resque::Plugins::MultiStepTask.create("testing") do |task|
128
+ task.add_job MultiStepAcceptance::BackRefJob
129
+ task.add_finalization_job MultiStepAcceptance::BackRefJob
130
+ end
131
+ end
132
+
133
+ before do
134
+ Resque.redis.del "testing"
135
+ task
136
+ sleep 1
137
+ end
138
+
139
+ it "does not fail" do
140
+ 5.times {sleep 1 if Resque::Failure.count < 1}
141
+
142
+ Resque::Failure.count.should == 0
143
+ end
144
+
145
+ it "completes successfully and removes the queue" do
146
+ Resque.queues.should_not include(task.queue_name)
147
+ end
148
+ end
metadata CHANGED
@@ -1,98 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: resque-multi-step
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 1
8
- - 3
9
- version: 1.1.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Peter Williams
13
9
  - Morgan Whitney
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2011-05-23 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-06-14 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2169769520 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 0
31
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
32
23
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: redis-namespace
36
24
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2169769520
26
+ - !ruby/object:Gem::Dependency
27
+ name: redis-namespace
28
+ requirement: &2169768960 !ruby/object:Gem::Requirement
38
29
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
45
34
  type: :runtime
46
- version_requirements: *id002
47
- - !ruby/object:Gem::Dependency
48
- name: yajl-ruby
49
35
  prerelease: false
50
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *2169768960
37
+ - !ruby/object:Gem::Dependency
38
+ name: yajl-ruby
39
+ requirement: &2169768480 !ruby/object:Gem::Requirement
51
40
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
58
45
  type: :runtime
59
- version_requirements: *id003
60
- - !ruby/object:Gem::Dependency
61
- name: resque
62
46
  prerelease: false
63
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *2169768480
48
+ - !ruby/object:Gem::Dependency
49
+ name: resque
50
+ requirement: &2169768000 !ruby/object:Gem::Requirement
64
51
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- segments:
69
- - 0
70
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
71
56
  type: :runtime
72
- version_requirements: *id004
73
- - !ruby/object:Gem::Dependency
74
- name: resque-fairly
75
57
  prerelease: false
76
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *2169768000
59
+ - !ruby/object:Gem::Dependency
60
+ name: resque-fairly
61
+ requirement: &2169767520 !ruby/object:Gem::Requirement
77
62
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- segments:
82
- - 0
83
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
84
67
  type: :runtime
85
- version_requirements: *id005
68
+ prerelease: false
69
+ version_requirements: *2169767520
86
70
  description: Provides multi-step tasks with finalization and progress tracking
87
71
  email: pezra@barelyenough.org
88
72
  executables: []
89
-
90
73
  extensions: []
91
-
92
- extra_rdoc_files:
74
+ extra_rdoc_files:
93
75
  - LICENSE
94
76
  - README.md
95
- files:
77
+ files:
96
78
  - .document
97
79
  - History.txt
98
80
  - LICENSE
@@ -115,43 +97,28 @@ files:
115
97
  - spec/resque/plugins/multi_step_task_spec.rb
116
98
  - spec/spec.opts
117
99
  - spec/spec_helper.rb
118
- has_rdoc: true
119
100
  homepage: http://github.com/pezra/resque-multi-step
120
101
  licenses: []
121
-
122
102
  post_install_message:
123
103
  rdoc_options: []
124
-
125
- require_paths:
104
+ require_paths:
126
105
  - lib
127
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
128
107
  none: false
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- segments:
133
- - 0
134
- version: "0"
135
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
113
  none: false
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- segments:
141
- - 0
142
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
143
118
  requirements: []
144
-
145
119
  rubyforge_project:
146
- rubygems_version: 1.3.7
120
+ rubygems_version: 1.8.16
147
121
  signing_key:
148
122
  specification_version: 3
149
123
  summary: Provides multi-step tasks with finalization and progress tracking
150
- test_files:
151
- - spec/acceptance/acceptance_jobs.rb
152
- - spec/acceptance/job_handling_spec.rb
153
- - spec/acceptance/spec_helper.rb
154
- - spec/resque-multi-step_spec.rb
155
- - spec/resque/plugins/multi_step_task/finalization_job_spec.rb
156
- - spec/resque/plugins/multi_step_task_spec.rb
157
- - spec/spec_helper.rb
124
+ test_files: []