resque-multi-step 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -13,7 +13,8 @@ begin
13
13
 
14
14
  gem.add_development_dependency "rspec", ">= 1.2.9"
15
15
 
16
- gem.add_dependency 'redis-namespace', '~> 0.8.0'
16
+ gem.add_dependency 'redis-namespace', '>= 0.8.0', '<= 0.10.0'
17
+ gem.add_dependency 'yajl-ruby'
17
18
  gem.add_dependency 'resque', '~> 1.10'
18
19
  gem.add_dependency 'resque-fairly', '~> 1.0'
19
20
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -4,18 +4,19 @@ require 'resque/plugins/multi_step_task/assure_finalization'
4
4
  require 'resque/plugins/multi_step_task/finalization_job'
5
5
  require 'resque/plugins/multi_step_task/constantization'
6
6
  require 'resque/plugins/multi_step_task/atomic_counters'
7
+ require 'logger'
8
+ require 'yajl'
7
9
 
8
10
  module Resque
9
11
  module Plugins
12
+ # @attr_reader normal_job_count
13
+ # @attr_reader finalize_job_count
14
+ # @attr_reader completed_count
15
+ # @attr_reader failed_count
10
16
  class MultiStepTask
11
17
  class NoSuchMultiStepTask < StandardError; end
12
18
  class NotReadyForFinalization < StandardError; end
13
19
  class FinalizationAlreadyBegun < StandardError; end
14
- class StdOutLogger
15
- def warn(*args); puts args; end
16
- def info(*args); puts args; end
17
- def debug(*args); puts args; end
18
- end
19
20
 
20
21
  class << self
21
22
  include Constantization
@@ -62,7 +63,7 @@ module Resque
62
63
  redis.sadd("active-tasks", task_id)
63
64
  redis.sismember("active-tasks", task_id)
64
65
  if block_given?
65
- yield pjg
66
+ yield mst
66
67
  mst.finalizable!
67
68
  end
68
69
 
@@ -94,14 +95,13 @@ module Resque
94
95
  def perform_without_maybe_finalize(task_id, job_module_name, *args)
95
96
  task = MultiStepTask.find(task_id)
96
97
  begin
97
- job_start_key = "#{task_id}_#{job_module_name}_#{args}-start-time-#{nonce}"
98
- task.redis.set(job_start_key, Time.now.to_i)
99
- logger.debug("[Resque Multi-Step-Task] Executing #{job_module_name} job for #{task_id} at #{Time.now} (args: #{args})")
98
+ start_time = Time.now
99
+ logger.debug("[Resque Multi-Step-Task] Executing #{job_module_name} job for #{task_id} at #{start_time} (args: #{args})")
100
100
 
101
101
  # perform the task
102
102
  constantize(job_module_name).perform(*args)
103
103
 
104
- logger.debug("[Resque Multi-Step-Task] Finished executing #{job_module_name} job for #{task_id} at #{Time.now}, taking #{(Time.now - task.redis.get(job_start_key).to_i).to_i} seconds.")
104
+ logger.debug("[Resque Multi-Step-Task] Finished executing #{job_module_name} job for #{task_id} at #{Time.now}, taking #{(Time.now - start_time)} seconds.")
105
105
  rescue Exception => e
106
106
  logger.error("[Resque Multi-Step-Task] #{job_module_name} job failed for #{task_id} at #{Time.now} (args: #{args})")
107
107
  task.increment_failed_count
@@ -120,7 +120,7 @@ module Resque
120
120
  end
121
121
 
122
122
  def logger
123
- @@logger ||= RAILS_DEFAULT_LOGGER || StdOutLogger.new
123
+ @@logger ||= Logger.new(STDERR)
124
124
  end
125
125
 
126
126
  # Normally jobs that are part of a multi-step task are run
@@ -154,9 +154,11 @@ module Resque
154
154
  extend AtomicCounters
155
155
 
156
156
  counter :normal_job_count
157
+
157
158
  counter :finalize_job_count
158
159
 
159
160
  counter :completed_count
161
+
160
162
  counter :failed_count
161
163
 
162
164
 
@@ -9,7 +9,6 @@ module Resque
9
9
 
10
10
  # Handle job invocation
11
11
  def self.perform(task_id, job_module_name, *args)
12
- # puts "finalizationjob#perform(#{task_id.inspect}, #{job_module_name.inspect}, #{args.inspect})"
13
12
  task = MultiStepTask.find(task_id)
14
13
 
15
14
  begin
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{resque-multi-step}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
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-02-18}
12
+ s.date = %q{2011-02-28}
13
13
  s.description = %q{Provides multi-step tasks with finalization and progress tracking}
14
14
  s.email = %q{pezra@barelyenough.org}
15
15
  s.extra_rdoc_files = [
@@ -59,18 +59,21 @@ Gem::Specification.new do |s|
59
59
 
60
60
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
61
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
62
- s.add_runtime_dependency(%q<redis-namespace>, ["~> 0.8.0"])
62
+ s.add_runtime_dependency(%q<redis-namespace>, [">= 0.8.0", "<= 0.10.0"])
63
+ s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
63
64
  s.add_runtime_dependency(%q<resque>, ["~> 1.10"])
64
65
  s.add_runtime_dependency(%q<resque-fairly>, ["~> 1.0"])
65
66
  else
66
67
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
67
- s.add_dependency(%q<redis-namespace>, ["~> 0.8.0"])
68
+ s.add_dependency(%q<redis-namespace>, [">= 0.8.0", "<= 0.10.0"])
69
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
68
70
  s.add_dependency(%q<resque>, ["~> 1.10"])
69
71
  s.add_dependency(%q<resque-fairly>, ["~> 1.0"])
70
72
  end
71
73
  else
72
74
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
73
- s.add_dependency(%q<redis-namespace>, ["~> 0.8.0"])
75
+ s.add_dependency(%q<redis-namespace>, [">= 0.8.0", "<= 0.10.0"])
76
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
74
77
  s.add_dependency(%q<resque>, ["~> 1.10"])
75
78
  s.add_dependency(%q<resque-fairly>, ["~> 1.0"])
76
79
  end
@@ -89,22 +89,24 @@ end
89
89
 
90
90
  describe "Acceptance: Task with retried finalization failure" do
91
91
  let(:task) {
92
- Resque.redis.del "testing counter"
92
+ @counter_key = "testing-counter-#{Time.now.to_i}"
93
+ @fin_key = "fin-key-#{Time.now.to_i}"
94
+ Resque.redis.del @counter_key
95
+ Resque.redis.del @fin_key
93
96
  Resque::Plugins::MultiStepTask.create("testing") do |task|
94
- task.add_finalization_job MultiStepAcceptance::FailOnceJob, "fin-job"
95
- task.add_finalization_job MultiStepAcceptance::CounterJob,"testing counter"
97
+ task.add_finalization_job MultiStepAcceptance::FailOnceJob, @fin_key
98
+ task.add_finalization_job MultiStepAcceptance::CounterJob, @counter_key
96
99
  end
97
100
  }
98
101
 
99
102
  before do
100
103
  Resque::Failure.clear
101
- Resque.redis.del "testing counter"
102
-
104
+
103
105
  task
104
- sleep 1
105
-
106
+ sleep 5
107
+
106
108
  Resque::Failure.requeue 0
107
- sleep 1
109
+ sleep 5
108
110
  end
109
111
 
110
112
  it "completes task" do
@@ -115,7 +117,7 @@ describe "Acceptance: Task with retried finalization failure" do
115
117
 
116
118
 
117
119
  it "runs following finalization jobs" do
118
- Resque.redis.get("testing counter").to_i.should == 1
120
+ Resque.redis.get(@counter_key).should == "1"
119
121
  end
120
122
 
121
123
  end
@@ -123,7 +123,8 @@ module Resque::Plugins
123
123
  task.add_finalization_job(MyFinalJob, "final", "args")
124
124
  task.add_job(TestJob, "my", "args") rescue nil
125
125
  task.finalizable!
126
- task.should be_incomplete_because_of_errors
126
+
127
+ task.should be_incomplete_because_of_error
127
128
  end
128
129
 
129
130
  it "knows it has failed if a finalized job raises an exception" do
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-multi-step
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 1
9
- - 0
10
- version: 1.1.0
8
+ - 1
9
+ version: 1.1.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Peter Williams
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2011-02-18 00:00:00 -07:00
18
+ date: 2011-02-28 00:00:00 -07:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -27,7 +26,6 @@ dependencies:
27
26
  requirements:
28
27
  - - ">="
29
28
  - !ruby/object:Gem::Version
30
- hash: 13
31
29
  segments:
32
30
  - 1
33
31
  - 2
@@ -41,46 +39,63 @@ dependencies:
41
39
  requirement: &id002 !ruby/object:Gem::Requirement
42
40
  none: false
43
41
  requirements:
44
- - - ~>
42
+ - - ">="
45
43
  - !ruby/object:Gem::Version
46
- hash: 63
47
44
  segments:
48
45
  - 0
49
46
  - 8
50
47
  - 0
51
48
  version: 0.8.0
49
+ - - <=
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ - 10
54
+ - 0
55
+ version: 0.10.0
52
56
  type: :runtime
53
57
  version_requirements: *id002
54
58
  - !ruby/object:Gem::Dependency
55
- name: resque
59
+ name: yajl-ruby
56
60
  prerelease: false
57
61
  requirement: &id003 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ type: :runtime
70
+ version_requirements: *id003
71
+ - !ruby/object:Gem::Dependency
72
+ name: resque
73
+ prerelease: false
74
+ requirement: &id004 !ruby/object:Gem::Requirement
58
75
  none: false
59
76
  requirements:
60
77
  - - ~>
61
78
  - !ruby/object:Gem::Version
62
- hash: 27
63
79
  segments:
64
80
  - 1
65
81
  - 10
66
82
  version: "1.10"
67
83
  type: :runtime
68
- version_requirements: *id003
84
+ version_requirements: *id004
69
85
  - !ruby/object:Gem::Dependency
70
86
  name: resque-fairly
71
87
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
88
+ requirement: &id005 !ruby/object:Gem::Requirement
73
89
  none: false
74
90
  requirements:
75
91
  - - ~>
76
92
  - !ruby/object:Gem::Version
77
- hash: 15
78
93
  segments:
79
94
  - 1
80
95
  - 0
81
96
  version: "1.0"
82
97
  type: :runtime
83
- version_requirements: *id004
98
+ version_requirements: *id005
84
99
  description: Provides multi-step tasks with finalization and progress tracking
85
100
  email: pezra@barelyenough.org
86
101
  executables: []
@@ -126,7 +141,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
141
  requirements:
127
142
  - - ">="
128
143
  - !ruby/object:Gem::Version
129
- hash: 3
130
144
  segments:
131
145
  - 0
132
146
  version: "0"
@@ -135,7 +149,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
- hash: 3
139
152
  segments:
140
153
  - 0
141
154
  version: "0"