asynchronic 1.3.1 → 1.4.0

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: a48e57f1b93e2a2d84f3fba80708b40350c756db
4
- data.tar.gz: 63e282e6e55c00d2ada87c934b6712f5f4de61c3
3
+ metadata.gz: a1dfc813a24c2580723d255461a9a6b91376d562
4
+ data.tar.gz: 793f9fd3f28c7fc712f98adeba227128b37644f9
5
5
  SHA512:
6
- metadata.gz: 3fb56ecfca909f90d6ab86ac280bf6b93211cbda896d82ae66d7e6de0f563d7dc3d25696167cd72f514d83f49af6237906915ba2ee73b4ff27082d42ea3c95cd
7
- data.tar.gz: 036fb94d1c004a38a85bf4ce78bca64b102044b057289fe77b76f21c2189f2f7849ef7e56dddb6848ac1de7f313d5a8dd9f7537798ca8f88faa5721ab209a270
6
+ metadata.gz: 1a003d3fefe9a1a4f79535a6dc0e1639306f347672d75b1aef6e625c59da4aaeca68a98d0d8d73f02646d62bcef6ec431836531d7292bdb25c0d1bd4854a4ff9
7
+ data.tar.gz: c2d6023bd1ea95d9b6147193bea9be6b36062c5bf774c08cd39e85029e4b5825067902553c14db0be6d05416e82b03ba4bea404376a62c64aad00fd0c0508caa
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0
@@ -6,8 +7,20 @@ rvm:
6
7
  - 2.2
7
8
  - 2.3.0
8
9
  - 2.4.0
9
- - jruby
10
- services:
11
- - redis-server
10
+ - 2.5.0
11
+ - jruby-1.7.25
12
+ - jruby-9.1.7.0
13
+ - ruby-head
14
+ - jruby-head
15
+
16
+ matrix:
17
+ fast_finish: true
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+
12
22
  before_install:
13
- - gem install bundler
23
+ - gem install bundler
24
+
25
+ services:
26
+ - redis-server
@@ -25,13 +25,15 @@ module Asynchronic
25
25
 
26
26
  private
27
27
 
28
+ attr_reader :process
29
+
28
30
  def async(type, params={})
29
- @process.nest type, params
31
+ process.nest type, params
30
32
  nil
31
33
  end
32
34
 
33
35
  def set(key, value)
34
- @process.set key, value
36
+ process.set key, value
35
37
  end
36
38
 
37
39
  def retry_when(exceptions, interval=1)
@@ -41,6 +41,12 @@ module Asynchronic
41
41
  completed? || aborted?
42
42
  end
43
43
 
44
+ def full_status
45
+ processes.each_with_object(name => status) do |process, hash|
46
+ hash.update(process.full_status)
47
+ end
48
+ end
49
+
44
50
  def params
45
51
  data_store.scoped(:params).no_lazy.readonly
46
52
  end
@@ -67,6 +73,10 @@ module Asynchronic
67
73
  Process.new environment, id.remove_last(2) if id.nested?
68
74
  end
69
75
 
76
+ def root
77
+ id.nested? ? Process.new(environment, id.sections.first) : self
78
+ end
79
+
70
80
  def real_error
71
81
  return nil unless error
72
82
 
@@ -107,7 +117,7 @@ module Asynchronic
107
117
  end
108
118
 
109
119
  def nest(type, params={})
110
- self.class.create @environment, type, params.merge(id: id[:processes][processes.count])
120
+ self.class.create environment, type, params.merge(id: id[:processes][processes.count])
111
121
  end
112
122
 
113
123
  def set(key, value)
@@ -139,9 +149,7 @@ module Asynchronic
139
149
 
140
150
  private
141
151
 
142
- def environment
143
- @environment
144
- end
152
+ attr_reader :environment
145
153
 
146
154
  def data_store
147
155
  @data_store ||= environment.data_store.scoped id
@@ -169,15 +177,19 @@ module Asynchronic
169
177
  end
170
178
  end
171
179
 
172
- def abort!(exception)
173
- self.error = Error.new exception
180
+ def abort!(exception=nil)
181
+ self.error = Error.new exception if exception
174
182
  aborted!
175
183
  end
176
184
 
177
185
  def run
178
- running!
179
- self.result = job.call
180
- waiting!
186
+ if root.aborted?
187
+ abort!
188
+ else
189
+ running!
190
+ self.result = job.call
191
+ waiting!
192
+ end
181
193
  rescue Exception => ex
182
194
  message = "Failed process #{type} (#{id})\n#{ex.class} #{ex.message}\n#{ex.backtrace.join("\n")}"
183
195
  Asynchronic.logger.error('Asynchronic') { message }
@@ -189,7 +201,9 @@ module Asynchronic
189
201
  def wakeup_children
190
202
  if waiting?
191
203
  if processes.any?(&:aborted?)
192
- abort! Error.new "Error caused by #{processes.select(&:aborted?).map{|p| p.name}.join(', ')}"
204
+ childs_with_errors = processes.select(&:error)
205
+ error = childs_with_errors.any? ? "Error caused by #{childs_with_errors.map(&:name).join(', ')}" : nil
206
+ abort! error
193
207
  elsif processes.all?(&:completed?)
194
208
  completed!
195
209
  else
@@ -1,3 +1,3 @@
1
1
  module Asynchronic
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
  end
data/spec/jobs.rb CHANGED
@@ -240,10 +240,10 @@ class DataJob < Asynchronic::Job
240
240
  end
241
241
 
242
242
 
243
- class NestedJobWithErrorInParent< Asynchronic::Job
243
+ class NestedJobWithErrorInParentJob < Asynchronic::Job
244
244
  def call
245
245
  async Child_1
246
- raise "Error in parent"
246
+ raise 'Error in parent'
247
247
  nil
248
248
  end
249
249
 
@@ -255,7 +255,7 @@ class NestedJobWithErrorInParent< Asynchronic::Job
255
255
  end
256
256
 
257
257
 
258
- class NestedJobWithErrorInChild < Asynchronic::Job
258
+ class NestedJobWithErrorInChildJob < Asynchronic::Job
259
259
 
260
260
  def call
261
261
  async Child_1
@@ -300,7 +300,7 @@ class NestedJobWithErrorInChild < Asynchronic::Job
300
300
 
301
301
  class Child_2_2 < Asynchronic::Job
302
302
  def call
303
- raise "Error in Child_2_2"
303
+ raise 'Error in Child_2_2'
304
304
  end
305
305
  end
306
306
 
@@ -323,4 +323,41 @@ class NestedJobWithErrorInChild < Asynchronic::Job
323
323
  end
324
324
  end
325
325
  end
326
+ end
327
+
328
+
329
+ class AbortQueuedAfertErrorJob < Asynchronic::Job
330
+ def call
331
+ async Child_1
332
+ async Child_2
333
+ async Child_3
334
+ async Child_4
335
+ nil
336
+ end
337
+
338
+ class Child_1 < Asynchronic::Job
339
+ def call
340
+ 1.upto(2) do |i|
341
+ async Child_2, alias: "Child_1_#{i}"
342
+ end
343
+ end
344
+ end
345
+
346
+ class Child_2 < Asynchronic::Job
347
+ def call
348
+ nil
349
+ end
350
+ end
351
+
352
+ class Child_3 < Asynchronic::Job
353
+ def call
354
+ raise 'Forced error'
355
+ end
356
+ end
357
+
358
+ class Child_4 < Asynchronic::Job
359
+ def call
360
+ nil
361
+ end
362
+ end
326
363
  end
@@ -462,28 +462,104 @@ module LifeCycleExamples
462
462
  process.data.must_equal text: 'Input was 1', value: 1
463
463
  end
464
464
 
465
- it 'NestedJobWithErrorInChild' do
466
- process = create NestedJobWithErrorInChild, queue: :test_queue
465
+ it 'Nested job with error in child' do
466
+ process = create NestedJobWithErrorInChildJob
467
467
 
468
468
  process.enqueue
469
469
 
470
470
  Timeout.timeout(1) do
471
471
  until process.status == :aborted
472
- execute queue_engine[:test_queue]
472
+ execute queue
473
473
  end
474
474
  end
475
475
 
476
476
  process.real_error.must_equal "Error in Child_2_2"
477
477
  end
478
478
 
479
- it 'NestedJobWithErrorInParent' do
480
- process = create NestedJobWithErrorInParent, queue: :test_queue
479
+ it 'Nested job with error in parent' do
480
+ process = create NestedJobWithErrorInParentJob
481
481
 
482
482
  process.enqueue
483
483
 
484
- execute queue_engine[:test_queue]
484
+ execute queue
485
485
 
486
486
  process.real_error.must_equal "Error in parent"
487
487
  end
488
488
 
489
+ it 'Abort queued afert error' do
490
+ process = create AbortQueuedAfertErrorJob
491
+
492
+ process.enqueue
493
+
494
+ execute queue
495
+
496
+ process.full_status.must_equal AbortQueuedAfertErrorJob => :waiting,
497
+ AbortQueuedAfertErrorJob::Child_1 => :queued,
498
+ AbortQueuedAfertErrorJob::Child_2 => :queued,
499
+ AbortQueuedAfertErrorJob::Child_3 => :queued,
500
+ AbortQueuedAfertErrorJob::Child_4 => :queued
501
+
502
+ execute queue
503
+
504
+ process.full_status.must_equal AbortQueuedAfertErrorJob => :waiting,
505
+ AbortQueuedAfertErrorJob::Child_1 => :waiting,
506
+ 'Child_1_1' => :queued,
507
+ 'Child_1_2' => :queued,
508
+ AbortQueuedAfertErrorJob::Child_2 => :queued,
509
+ AbortQueuedAfertErrorJob::Child_3 => :queued,
510
+ AbortQueuedAfertErrorJob::Child_4 => :queued
511
+
512
+ execute queue
513
+
514
+ process.full_status.must_equal AbortQueuedAfertErrorJob => :waiting,
515
+ AbortQueuedAfertErrorJob::Child_1 => :waiting,
516
+ 'Child_1_1' => :queued,
517
+ 'Child_1_2' => :queued,
518
+ AbortQueuedAfertErrorJob::Child_2 => :completed,
519
+ AbortQueuedAfertErrorJob::Child_3 => :queued,
520
+ AbortQueuedAfertErrorJob::Child_4 => :queued
521
+
522
+ execute queue
523
+
524
+ process.full_status.must_equal AbortQueuedAfertErrorJob => :aborted,
525
+ AbortQueuedAfertErrorJob::Child_1 => :waiting,
526
+ 'Child_1_1' => :queued,
527
+ 'Child_1_2' => :queued,
528
+ AbortQueuedAfertErrorJob::Child_2 => :completed,
529
+ AbortQueuedAfertErrorJob::Child_3 => :aborted,
530
+ AbortQueuedAfertErrorJob::Child_4 => :queued
531
+
532
+ execute queue
533
+
534
+ process.full_status.must_equal AbortQueuedAfertErrorJob => :aborted,
535
+ AbortQueuedAfertErrorJob::Child_1 => :waiting,
536
+ 'Child_1_1' => :queued,
537
+ 'Child_1_2' => :queued,
538
+ AbortQueuedAfertErrorJob::Child_2 => :completed,
539
+ AbortQueuedAfertErrorJob::Child_3 => :aborted,
540
+ AbortQueuedAfertErrorJob::Child_4 => :aborted
541
+
542
+ execute queue
543
+
544
+ process.full_status.must_equal AbortQueuedAfertErrorJob => :aborted,
545
+ AbortQueuedAfertErrorJob::Child_1 => :aborted,
546
+ 'Child_1_1' => :aborted,
547
+ 'Child_1_2' => :queued,
548
+ AbortQueuedAfertErrorJob::Child_2 => :completed,
549
+ AbortQueuedAfertErrorJob::Child_3 => :aborted,
550
+ AbortQueuedAfertErrorJob::Child_4 => :aborted
551
+
552
+ execute queue
553
+
554
+ process.full_status.must_equal AbortQueuedAfertErrorJob => :aborted,
555
+ AbortQueuedAfertErrorJob::Child_1 => :aborted,
556
+ 'Child_1_1' => :aborted,
557
+ 'Child_1_2' => :aborted,
558
+ AbortQueuedAfertErrorJob::Child_2 => :completed,
559
+ AbortQueuedAfertErrorJob::Child_3 => :aborted,
560
+ AbortQueuedAfertErrorJob::Child_4 => :aborted
561
+
562
+ process.real_error.must_equal 'Forced error'
563
+ end
564
+
489
565
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asynchronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-18 00:00:00.000000000 Z
11
+ date: 2018-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis