asyncapi-server 1.1.2 → 1.1.3

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: 98465ac054db6133b48db7f710198054c7c60b60
4
- data.tar.gz: 0036e1102a9f42cd9c8b5e50bcef8113232874a6
3
+ metadata.gz: 6474a23ea2a71357536415e3f47a521631f7dfd6
4
+ data.tar.gz: f2dd84f467e36bb75be0e1d050ee1ce89c813c5f
5
5
  SHA512:
6
- metadata.gz: 43e185eccae647e7b8db9f76731aa9d0f531b773e43340fd395485443b29f55684dfca7b2333d317819f885f246300159c83c3d73413052bb50742ed9d457dba
7
- data.tar.gz: 812bb5f496deb99e2934d0e70fe49ecbe76b5d807d902e4ac058675a4523715133efd28f0f02137bc79ffe0de1049ca37e75450793d521b6a7f2e2466ff33fd1
6
+ metadata.gz: a96efc749932659c6f8e192b083a2c6bbe14b97de47bfe08ec2eb59512a8f3a4776267ebe659a4672c4c3411d50256142f391f1b4500a0b9e0aca10283393480
7
+ data.tar.gz: 1fa06b7a02572ad9722a7f7212bb9c3743dc1a5a88c8a3dcdcedc8b18a3091ee103ddde8ca5d42c72b4c482da06edc22d9c5cb867788dfbf773457190046eed2
@@ -3,8 +3,9 @@ module Asyncapi::Server
3
3
 
4
4
  include Sidekiq::Worker
5
5
  sidekiq_options retry: false
6
+ MAX_RETRIES = 2
6
7
 
7
- def perform(job_id)
8
+ def perform(job_id, retries=0)
8
9
  job = Job.find(job_id)
9
10
  runner_class = job.class_name.constantize
10
11
 
@@ -15,8 +16,19 @@ module Asyncapi::Server
15
16
  job_message = [e.message, e.backtrace].flatten.join("\n")
16
17
  raise e
17
18
  ensure
18
- job.update_attributes(status: job_status)
19
- report_job_status(job, job_message)
19
+ if job
20
+ job.update_attributes(status: job_status)
21
+ report_job_status(job, job_message)
22
+ else
23
+ # For some reason "ActiveRecord::Base.after_transaction",
24
+ # ":after_commit" and ":after_create" does not prevent
25
+ # the ActiveRecord-Sidekiq race condition. In order to
26
+ # prevent this just retry running JobWorker until it finds
27
+ # the job by job_id.
28
+ if retries <= MAX_RETRIES
29
+ JobWorker.perform_async(job_id, retries+1)
30
+ end
31
+ end
20
32
  end
21
33
 
22
34
  private
@@ -1,5 +1,5 @@
1
1
  module Asyncapi
2
2
  module Server
3
- VERSION = "1.1.2"
3
+ VERSION = "1.1.3"
4
4
  end
5
5
  end
@@ -74,8 +74,14 @@ module Asyncapi
74
74
  expect(job.status).to eq "error"
75
75
  end
76
76
  end
77
- end
78
77
 
78
+ context "job is nil" do
79
+ it "retries JobWorker" do
80
+ expect(JobWorker).to receive(:perform_async).with("999", 1).and_return true
81
+ expect { described_class.new.perform("999") }.to raise_error
82
+ end
83
+ end
84
+ end
79
85
  end
80
86
  end
81
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asyncapi-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - G5
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-21 00:00:00.000000000 Z
13
+ date: 2016-08-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: kaminari
@@ -338,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
338
338
  version: '0'
339
339
  requirements: []
340
340
  rubyforge_project:
341
- rubygems_version: 2.6.4
341
+ rubygems_version: 2.5.1
342
342
  signing_key:
343
343
  specification_version: 4
344
344
  summary: Asynchronous API communication - Server