dalliance 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a4602c362e675dce64388b7b9366ffe48f24030
4
- data.tar.gz: c2a034af3788a4c600f93c3125b0a1ba193f5526
3
+ metadata.gz: 413b181998e6b583f6ecf882cafde4c16a47de1f
4
+ data.tar.gz: 42cdf7593a1f5075f527e8276d4414f0822c2a58
5
5
  SHA512:
6
- metadata.gz: 53633a3663c48cb77ab1dbc163c163ed3bfba20d0eeee7d29e60cffcbb9a66fa749fb6f387d66e059306f8415e94d4ee075457ded1f9c5c78778def4d1366d17
7
- data.tar.gz: 11dd4c5759cdf43e4106185c18a90ba7feea066ec1713f3dc9012ccfef988e6f0ca9e0946c39f1b421ceb50f047b7cf19f2f17bb8aa2e610fa343ee1db6a6311
6
+ metadata.gz: c79a0d24fbb2866986b96fb1f800b7093fc1b2ff836cff2a9dd6169b91af707e397a07ea0bf2e2d869c294cc970b37a428d05fd63712141b83845116ca7c67df
7
+ data.tar.gz: 7c80667448c0e00990774c2938f1f7862d830194e491281dca65dfdeeaa6bd8e460e708f706f6c5011d2cac51e48ff809c9033060df8059065d61e8545ddab7c
@@ -1,6 +1,8 @@
1
1
  require 'state_machine'
2
2
  require 'benchmark'
3
3
 
4
+ require 'dalliance/state_machine'
5
+
4
6
  require 'dalliance/version'
5
7
  require 'dalliance/workers'
6
8
  require 'dalliance/progress_meter'
@@ -137,6 +139,12 @@ module Dalliance
137
139
  end
138
140
  end
139
141
 
142
+ def dalliance_log(message)
143
+ if self.class.dalliance_options[:logger]
144
+ self.class.dalliance_options[:logger].info(message)
145
+ end
146
+ end
147
+
140
148
  def store_dalliance_validation_error!
141
149
  self.dalliance_error_hash = {}
142
150
 
@@ -145,7 +153,20 @@ module Dalliance
145
153
  self.dalliance_error_hash[attribute] << error
146
154
  end
147
155
 
148
- validation_error_dalliance!
156
+ begin
157
+ validation_error_dalliance!
158
+ rescue
159
+ begin
160
+ self.dalliance_status = 'validation_error'
161
+
162
+ dalliance_log("[dalliance] #{self.class.name}(#{id}) - #{dalliance_status} #{self.dalliance_error_hash}")
163
+
164
+ self.dalliance_error_hash = { error: 'Persistance Failure: See Logs' }
165
+
166
+ self.class.where(id: self.id).update_all(dalliance_status: dalliance_status, dalliance_error_hash: dalliance_error_hash )
167
+ rescue
168
+ end
169
+ end
149
170
  end
150
171
 
151
172
  def error_or_completed?
@@ -192,7 +213,20 @@ module Dalliance
192
213
  #Save the error for future analysis...
193
214
  self.dalliance_error_hash = {:error => e.class.name, :message => e.message, :backtrace => e.backtrace}
194
215
 
195
- error_dalliance!
216
+ begin
217
+ error_dalliance!
218
+ rescue
219
+ begin
220
+ self.dalliance_status = 'processing_error'
221
+
222
+ dalliance_log("[dalliance] #{self.class.name}(#{id}) - #{dalliance_status} #{dalliance_error_hash}")
223
+
224
+ self.dalliance_error_hash = { error: 'Persistance Failure: See Logs' }
225
+
226
+ self.class.where(id: self.id).update_all(dalliance_status: dalliance_status, dalliance_error_hash: dalliance_error_hash )
227
+ rescue
228
+ end
229
+ end
196
230
 
197
231
  #Don't raise the error if we're backgound_processing...
198
232
  raise e unless backgound_processing && self.class.dalliance_options[:worker_class].rescue_error?
@@ -205,9 +239,7 @@ module Dalliance
205
239
 
206
240
  duration = Time.now - start_time
207
241
 
208
- if self.class.dalliance_options[:logger]
209
- self.class.dalliance_options[:logger].info("[dalliance] #{self.class.name}(#{id}) - #{dalliance_status} #{duration.to_i}")
210
- end
242
+ dalliance_log("[dalliance] #{self.class.name}(#{id}) - #{dalliance_status} #{duration.to_i}")
211
243
 
212
244
  if self.class.dalliance_options[:duration_column]
213
245
  self.class.where(id: self.id).update_all(self.class.dalliance_options[:duration_column] => duration.to_i)
@@ -274,4 +306,4 @@ module Dalliance
274
306
  end
275
307
  end
276
308
  end
277
- end
309
+ end
@@ -11,4 +11,4 @@ module Dalliance
11
11
  end
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -0,0 +1,15 @@
1
+ # Rails 4.1.0 and StateMachine don't play nice
2
+ # https://github.com/pluginaweek/state_machine/issues/295
3
+ require 'state_machine/version'
4
+
5
+ if defined?(Rails)
6
+ if StateMachine::VERSION > '1.2.0'
7
+ # If you see this message, please test removing this file
8
+ # If it's still required, please bump up the version above
9
+ Rails.logger.warn "Please remove me, StateMachine version has changed"
10
+ end
11
+ end
12
+
13
+ module StateMachine::Integrations::ActiveModel
14
+ public :around_validation
15
+ end
@@ -2,7 +2,7 @@ module Dalliance
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 7
5
+ TINY = 8
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -142,6 +142,18 @@ describe DallianceModel do
142
142
 
143
143
  subject.dalliance_progress.should == 0
144
144
  end
145
+
146
+ it "should handle persistance errors" do
147
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_error_method_with_state_machine_exception
148
+
149
+ subject.dalliance_background_process
150
+ Delayed::Worker.new(:queues => [:dalliance]).work_off
151
+ subject.reload
152
+
153
+ subject.should be_processing_error
154
+ subject.dalliance_error_hash.should_not be_empty
155
+ subject.dalliance_error_hash[:error].should == 'Persistance Failure: See Logs'
156
+ end
145
157
  end
146
158
 
147
159
  context "validation error" do
@@ -175,5 +187,17 @@ describe DallianceModel do
175
187
 
176
188
  subject.dalliance_progress.should == 0
177
189
  end
190
+
191
+ it "should handle persistance errors" do
192
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method_with_state_machine_exception
193
+
194
+ subject.dalliance_background_process
195
+ Delayed::Worker.new(:queues => [:dalliance]).work_off
196
+ subject.reload
197
+
198
+ subject.should be_validation_error
199
+ subject.dalliance_error_hash.should_not be_empty
200
+ subject.dalliance_error_hash[:error].should == 'Persistance Failure: See Logs'
201
+ end
178
202
  end
179
- end
203
+ end
@@ -158,6 +158,18 @@ describe DallianceModel do
158
158
 
159
159
  subject.dalliance_progress.should == 0
160
160
  end
161
+
162
+ it "should handle persistance errors" do
163
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_error_method_with_state_machine_exception
164
+
165
+ subject.dalliance_background_process
166
+ Resque::Worker.new(:dalliance).process
167
+ subject.reload
168
+
169
+ subject.should be_processing_error
170
+ subject.dalliance_error_hash.should_not be_empty
171
+ subject.dalliance_error_hash[:error].should == 'Persistance Failure: See Logs'
172
+ end
161
173
  end
162
174
 
163
175
  context "validation error" do
@@ -191,5 +203,17 @@ describe DallianceModel do
191
203
 
192
204
  subject.dalliance_progress.should == 0
193
205
  end
206
+
207
+ it "should handle persistance errors" do
208
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method_with_state_machine_exception
209
+
210
+ subject.dalliance_background_process
211
+ Resque::Worker.new(:dalliance).process
212
+ subject.reload
213
+
214
+ subject.should be_validation_error
215
+ subject.dalliance_error_hash.should_not be_empty
216
+ subject.dalliance_error_hash[:error].should == 'Persistance Failure: See Logs'
217
+ end
194
218
  end
195
- end
219
+ end
@@ -64,6 +64,16 @@ describe DallianceModel do
64
64
 
65
65
  subject.dalliance_progress.should == 0
66
66
  end
67
+
68
+ it "should handle persistance errors" do
69
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_error_method_with_state_machine_exception
70
+
71
+ expect { subject.dalliance_background_process }.to raise_error(RuntimeError)
72
+
73
+ subject.should be_processing_error
74
+ subject.dalliance_error_hash.should_not be_empty
75
+ subject.dalliance_error_hash[:error].should == 'Persistance Failure: See Logs'
76
+ end
67
77
  end
68
78
 
69
79
  context "validation error" do
@@ -87,6 +97,16 @@ describe DallianceModel do
87
97
 
88
98
  subject.dalliance_progress.should == 0
89
99
  end
100
+
101
+ it "should handle persistance errors" do
102
+ DallianceModel.dalliance_options[:dalliance_method] = :dalliance_validation_error_method_with_state_machine_exception
103
+
104
+ subject.dalliance_background_process
105
+
106
+ subject.should be_validation_error
107
+ subject.dalliance_error_hash.should_not be_empty
108
+ subject.dalliance_error_hash[:error].should == 'Persistance Failure: See Logs'
109
+ end
90
110
  end
91
111
 
92
112
  context "destroy" do
@@ -117,4 +137,4 @@ describe DallianceModel do
117
137
  subject.destroy.should be_true
118
138
  end
119
139
  end
120
- end
140
+ end
@@ -14,20 +14,22 @@ require 'dalliance'
14
14
 
15
15
  RSpec.configure do |config|
16
16
  #http://blog.rubyhead.com/2010/04/27/database-during-tests/
17
- config.before do
18
- ActiveRecord::Base.connection.begin_db_transaction
19
- ActiveRecord::Base.connection.increment_open_transactions
20
- end
17
+ # config.before do
18
+ # ActiveRecord::Base.connection.begin_db_transaction
19
+ # ActiveRecord::Base.connection.increment_open_transactions
20
+ # end
21
21
 
22
- config.after do
23
- if ActiveRecord::Base.connection.open_transactions != 0
24
- ActiveRecord::Base.connection.rollback_db_transaction
25
- ActiveRecord::Base.connection.decrement_open_transactions
26
- end
27
- end
22
+ # config.after do
23
+ # if ActiveRecord::Base.connection.open_transactions != 0
24
+ # ActiveRecord::Base.connection.rollback_db_transaction
25
+ # ActiveRecord::Base.connection.decrement_open_transactions
26
+ # end
27
+ # end
28
28
  end
29
29
 
30
30
  #We don't need a full rails app to test...
31
31
  require 'support/active_record'
32
32
 
33
- #NOTE: Resque tests require REDIS $redis-server
33
+ #NOTE: Resque tests require REDIS
34
+ # $brew install redis
35
+ # $redis-server /usr/local/etc/redis.conf
@@ -62,4 +62,16 @@ class DallianceModel < ActiveRecord::Base
62
62
 
63
63
  store_dalliance_validation_error!
64
64
  end
65
- end
65
+
66
+ def dalliance_error_method_with_state_machine_exception
67
+ self.stub(:error_dalliance!).and_raise(RuntimeError.new)
68
+
69
+ dalliance_error_method
70
+ end
71
+
72
+ def dalliance_validation_error_method_with_state_machine_exception
73
+ self.stub(:validation_error_dalliance!).and_raise(RuntimeError.new)
74
+
75
+ dalliance_validation_error_method
76
+ end
77
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalliance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Sullivan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-20 00:00:00.000000000 Z
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -142,6 +142,7 @@ files:
142
142
  - lib/dalliance/engine.rb
143
143
  - lib/dalliance/progress_meter.rb
144
144
  - lib/dalliance/schema.rb
145
+ - lib/dalliance/state_machine.rb
145
146
  - lib/dalliance/version.rb
146
147
  - lib/dalliance/workers.rb
147
148
  - lib/dalliance/workers/delayed_job.rb
@@ -175,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  version: '0'
176
177
  requirements: []
177
178
  rubyforge_project: dalliance
178
- rubygems_version: 2.1.10
179
+ rubygems_version: 2.0.3
179
180
  signing_key:
180
181
  specification_version: 4
181
182
  summary: Wrapper for an ActiveRecord model with a single ascynhronous method