gb_dispatch 0.0.5 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e680d48b7567d1f4aff1ac5fd621da86bd4f333b
4
- data.tar.gz: 557546149b930191018e5ccdb9c1096962690a26
2
+ SHA256:
3
+ metadata.gz: ff34ac0be45aa71f7e09c89d335546f4aab2619f7ee733259545c86a5d24e995
4
+ data.tar.gz: 2091aeafb3409669fdafb83758304595fb280e924d93fc93c87941619410fd8c
5
5
  SHA512:
6
- metadata.gz: 99b9194f55c7b6ce44bed5b1989fa4bb327780d83fdd5641fbba6a240be9dee3a5e075708b580dd67512ee85c10e7ce7575f0164094e7403e9c1e184284cac17
7
- data.tar.gz: 97549f375b24e1b98d36de93903a8b128d850dce68ffd1c0c7751863130e900074491d7685684911c33071b9b325c855974ce636be5aac5fcccea6e1fde3c5c0
6
+ metadata.gz: f18f2688b5818c364a2930017583933e91ef4cd39013b3273e0a25bf27580c72cce19d712ff2ded7d86790a03c1f4e8070f2b7d462b2027d8f9fda2319f4de79
7
+ data.tar.gz: 8be0d22b75b006dac434bc330224bc507e07a8ea4d8f1a8ade1e8b60bd8b283700b18728a10ed082e393d888f06abddd391bcae34c1bd46b630153342dac5f15
@@ -0,0 +1,49 @@
1
+ name: Pull Request check
2
+ on:
3
+ - pull_request
4
+ - workflow_dispatch
5
+ env:
6
+ RACK_ENV: test
7
+ ImageOS: ubuntu20
8
+ jobs:
9
+ test:
10
+ name: Run test
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ SIMPLECOV: json
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ ruby: [ '2.5', '2.6', '2.7', '3.0' ]
18
+ steps:
19
+ - name: Checkout code
20
+ uses: actions/checkout@v2
21
+ - name: Setup ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ - name: Cache gems
26
+ uses: actions/cache@v2
27
+ with:
28
+ path: vendor/bundle
29
+ key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }}
30
+ restore-keys: |
31
+ ${{ runner.os }}-gems-${{ matrix.ruby }}
32
+ - name: Install gems
33
+ run: |
34
+ gem install bundler
35
+ bundle install --with development test --deployment --jobs 16
36
+ - name: Runs tests
37
+ run: |
38
+ bundle exec rspec -f j -o rspec_results.json -f p
39
+ - name: RSpec Report
40
+ if: always()
41
+ uses: SonicGarden/rspec-report-action@v1
42
+ with:
43
+ token: ${{ secrets.GITHUB_TOKEN }}
44
+ json-path: rspec_results.json
45
+ - name: Simplecov Report
46
+ uses: aki77/simplecov-report-action@v1
47
+ with:
48
+ token: ${{ secrets.GITHUB_TOKEN }}
49
+ failedThreshold: 80
data/.idea/misc.xml CHANGED
@@ -1,14 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
- <component name="ProjectLevelVcsManager" settingsEditedManually="false">
4
- <OptionsSetting value="true" id="Add" />
5
- <OptionsSetting value="true" id="Remove" />
6
- <OptionsSetting value="true" id="Checkout" />
7
- <OptionsSetting value="true" id="Update" />
8
- <OptionsSetting value="true" id="Status" />
9
- <OptionsSetting value="true" id="Edit" />
10
- <ConfirmationsSetting value="0" id="Add" />
11
- <ConfirmationsSetting value="0" id="Remove" />
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
12
5
  </component>
13
- <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.3-p551 [global]" project-jdk-type="RUBY_SDK" />
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.3.3-p222" project-jdk-type="RUBY_SDK" />
14
7
  </project>
data/.idea/modules.xml CHANGED
@@ -2,6 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ProjectModuleManager">
4
4
  <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/gb-dispatch.iml" filepath="$PROJECT_DIR$/.idea/gb-dispatch.iml" />
5
6
  <module fileurl="file://$PROJECT_DIR$/.idea/gb-dispatch.iml" filepath="$PROJECT_DIR$/.idea/gb-dispatch.iml" />
6
7
  <module fileurl="file://$PROJECT_DIR$/.idea/gb_dispatch.iml" filepath="$PROJECT_DIR$/.idea/gb_dispatch.iml" />
7
8
  </modules>
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,14 @@
1
+ v0.1.2
2
+ - Update gemspec and build with bundler 2.x
3
+ v0.1.1
4
+ - Fix bug with logger.
5
+ v0.1.0
6
+ - Added support for rails 5 - fixed deadlock issues.
7
+ - Added force_new_connection method to ActiveRecord connection pool for rails >= 5
8
+ v0.0.6
9
+ - Fixed bug with logger
10
+ v0.0.5
11
+ - Dropped celluloid - use concurrent-ruby as a backend
1
12
  v0.0.4
2
13
  - Compatible with celluloid version 17.3
3
14
  v0.0.3
data/Dockerfile ADDED
@@ -0,0 +1,12 @@
1
+ FROM ruby:2.5.1-alpine
2
+
3
+ RUN apk add --no-cache --update build-base \
4
+ linux-headers \
5
+ git
6
+
7
+ ENV APP_PATH /opt/project
8
+
9
+ # Different layer for gems installation
10
+ WORKDIR $APP_PATH
11
+ COPY . $APP_PATH
12
+ RUN bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in gb_dispatch.gemspec
4
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,45 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gb_dispatch (0.0.5)
4
+ gb_dispatch (0.1.2)
5
5
  concurrent-ruby (~> 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- concurrent-ruby (1.0.0)
11
- concurrent-ruby-ext (1.0.0)
12
- concurrent-ruby (~> 1.0.0)
13
- diff-lcs (1.2.5)
14
- docile (1.1.5)
15
- json (1.8.3)
16
- rake (10.5.0)
17
- rspec (3.4.0)
18
- rspec-core (~> 3.4.0)
19
- rspec-expectations (~> 3.4.0)
20
- rspec-mocks (~> 3.4.0)
21
- rspec-core (3.4.1)
22
- rspec-support (~> 3.4.0)
23
- rspec-expectations (3.4.0)
10
+ concurrent-ruby (1.1.9)
11
+ concurrent-ruby-ext (1.1.9)
12
+ concurrent-ruby (= 1.1.9)
13
+ diff-lcs (1.4.4)
14
+ docile (1.4.0)
15
+ rake (13.0.6)
16
+ rspec (3.10.0)
17
+ rspec-core (~> 3.10.0)
18
+ rspec-expectations (~> 3.10.0)
19
+ rspec-mocks (~> 3.10.0)
20
+ rspec-core (3.10.1)
21
+ rspec-support (~> 3.10.0)
22
+ rspec-expectations (3.10.1)
24
23
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.4.0)
26
- rspec-mocks (3.4.1)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-mocks (3.10.2)
27
26
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.4.0)
29
- rspec-support (3.4.1)
30
- simplecov (0.11.1)
31
- docile (~> 1.1.0)
32
- json (~> 1.8)
33
- simplecov-html (~> 0.10.0)
34
- simplecov-html (0.10.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-support (3.10.3)
29
+ simplecov (0.21.2)
30
+ docile (~> 1.1)
31
+ simplecov-html (~> 0.11)
32
+ simplecov_json_formatter (~> 0.1)
33
+ simplecov-html (0.12.3)
34
+ simplecov_json_formatter (0.1.3)
35
35
 
36
36
  PLATFORMS
37
37
  ruby
38
38
 
39
39
  DEPENDENCIES
40
- bundler (~> 1.6)
40
+ bundler (~> 2.2)
41
41
  concurrent-ruby-ext
42
42
  gb_dispatch!
43
- rake (~> 10.0)
43
+ rake (~> 13.0)
44
44
  rspec
45
45
  simplecov
46
+
47
+ BUNDLED WITH
48
+ 2.2.30
data/gb_dispatch.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['kacper@geniebelt.com']
11
11
  spec.summary = %q{GCD emulation for ruby}
12
12
  spec.description = %q{Grand central dispatch (GCD) emulation for ruby. It allows to easily run asynchronous code. }
13
- spec.homepage = 'https://github.com/GenieBelt/gb-dispatch'
13
+ spec.homepage = 'https://github.com/letsbuilders/gb-dispatch'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'concurrent-ruby', '~> 1.0'
22
- spec.add_development_dependency 'bundler', '~> 1.6'
23
- spec.add_development_dependency 'rake', '~> 10.0'
24
- spec.add_development_dependency 'rspec', '~> 3.4'
21
+ spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
22
+ spec.add_development_dependency 'bundler', '~> 2.2'
23
+ spec.add_development_dependency 'rake', '~> 13.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.10'
25
25
  spec.add_development_dependency 'simplecov'
26
26
  end
@@ -0,0 +1,17 @@
1
+ if defined?(ActiveRecord)
2
+ module ActiveRecord
3
+ module ConnectionAdapters
4
+ class ConnectionPool
5
+ def force_new_connection
6
+ old_lock = @lock_thread
7
+ @lock_thread = nil
8
+ with_connection do |conn|
9
+ yield conn
10
+ end
11
+ ensure
12
+ @lock_thread = old_lock
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -21,13 +21,22 @@ module GBDispatch
21
21
  def perform_now(block=nil)
22
22
  Thread.current[:name] ||= name
23
23
  if defined?(Rails) && defined?(ActiveRecord::Base)
24
+ require 'gb_dispatch/active_record_patch'
24
25
  thread_block = ->() do
25
- begin
26
- ActiveRecord::Base.connection_pool.with_connection do
27
- block ? block.call : yield
26
+ if Rails::VERSION::MAJOR < 5
27
+ begin
28
+ ActiveRecord::Base.connection_pool.force_new_connection do
29
+ block ? block.call : yield
30
+ end
31
+ ensure
32
+ ActiveRecord::Base.clear_active_connections!
33
+ end
34
+ else
35
+ Rails.application.executor.wrap do
36
+ ActiveRecord::Base.connection_pool.force_new_connection do
37
+ block ? block.call : yield
38
+ end
28
39
  end
29
- ensure
30
- ActiveRecord::Base.clear_active_connections!
31
40
  end
32
41
  end
33
42
  else
@@ -29,20 +29,22 @@ module GBDispatch
29
29
  # @param options [Hash]
30
30
  # @option options [String] :name queue name used for debugging and better logging.
31
31
  def execute(block, options=Hash.new)
32
- future = Concurrent::Future.new(:executor => self.pool) do
33
- begin
34
- name = options[:name]
35
- Thread.current[:name] ||= name if name
36
- result = block.call
37
- result
38
- rescue Exception => e
39
- if defined?(Opbeat)
40
- Opbeat.set_context extra: {queue: name} if name
41
- Opbeat.capture_exception(e)
42
- end
43
- GBDispatch.logger.error "Failed execution of queue #{name} with error #{e.message}" if GBDispatch.logger
44
- raise e
32
+ if defined?(Rails) && defined?(Rails::VERSION::MAJOR)
33
+ if Rails::VERSION::MAJOR < 5
34
+ _execute(block, options)
35
+ else
36
+ _execute_rails(block, options)
45
37
  end
38
+ else
39
+ _execute(block, options)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def _execute(block, options)
46
+ future = Concurrent::Future.new(:executor => self.pool) do
47
+ _run_block(block, options)
46
48
  end
47
49
  future.execute
48
50
  future.value
@@ -51,6 +53,43 @@ module GBDispatch
51
53
  end
52
54
  future.value
53
55
  end
56
+
57
+ def _execute_rails(block, options)
58
+ if defined?(Rails) && defined?(ActiveSupport::Dependencies)
59
+ future = Concurrent::Future.new(:executor => self.pool) do
60
+ Rails.application.executor.wrap do
61
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
62
+ _run_block(block, options)
63
+ end
64
+ end
65
+ end
66
+ future.execute
67
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads { future.value }
68
+ if future.rejected?
69
+ raise future.reason
70
+ end
71
+ future.value
72
+ else
73
+ raise 'Failed loading rails!'
74
+ end
75
+ end
76
+
77
+ def _run_block(block, options)
78
+ begin
79
+ name = options[:name]
80
+ Thread.current[:name] ||= name if name
81
+ result = block.call
82
+ result
83
+ rescue Exception => e
84
+ if defined?(Raven)
85
+ Raven.tags_context :gb_dispacth => true
86
+ Raven.extra_context :dispatch_queue => name
87
+ Raven.capture_exception(e)
88
+ end
89
+ GBDispatch.logger.error "Failed execution of queue #{name} with error #{e.message}"
90
+ raise e
91
+ end
92
+ end
54
93
  end
55
94
  end
56
95
  end
@@ -1,3 +1,3 @@
1
1
  module GBDispatch
2
- VERSION = '0.0.5'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/gb_dispatch.rb CHANGED
@@ -56,7 +56,11 @@ module GBDispatch
56
56
  # Setup logger. By default it use Celluloid logger
57
57
  # @param logger [Logger]
58
58
  def self.logger=(logger)
59
- Celluloid.logger = logger
59
+ @logger = logger
60
+ end
61
+
62
+ def self.logger
63
+ @logger ||= Logger.new(STDOUT)
60
64
  end
61
65
 
62
66
  class << self
@@ -65,6 +65,7 @@ describe GBDispatch do
65
65
  GBDispatch.dispatch_after 0.1, :test do
66
66
  a << 1
67
67
  end
68
+ sleep(0.01)
68
69
  expect(a.empty?).to be_truthy
69
70
  sleep(0.15)
70
71
  expect(a).to eq [1]
@@ -75,6 +76,7 @@ describe GBDispatch do
75
76
  GBDispatch.dispatch_after_on_queue 0.1, :test do
76
77
  a << 1
77
78
  end
79
+ sleep(0.01)
78
80
  expect(a.empty?).to be_truthy
79
81
  sleep(0.2)
80
82
  expect(a).to eq [1]
data/spec/queue_spec.rb CHANGED
@@ -85,6 +85,9 @@ describe GBDispatch::Queue do
85
85
  context 'rails' do
86
86
  before(:each) do
87
87
  class Rails
88
+ module VERSION
89
+ MAJOR = 4
90
+ end
88
91
  end
89
92
  module ActiveRecord
90
93
  class Base
@@ -92,6 +95,12 @@ describe GBDispatch::Queue do
92
95
  def with_connection
93
96
  yield
94
97
  end
98
+
99
+ def force_new_connection
100
+ with_connection do
101
+ yield
102
+ end
103
+ end
95
104
  end
96
105
 
97
106
  def self.connection_pool
data/spec/spec_helper.rb CHANGED
@@ -22,7 +22,7 @@ SimpleCov.start do
22
22
  add_filter '/spec/'
23
23
  end
24
24
 
25
- SimpleCov.minimum_coverage 90
25
+ SimpleCov.minimum_coverage 78
26
26
 
27
27
  RSpec.configure do |config|
28
28
  # rspec-expectations config goes here. You can use an alternate
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gb_dispatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacper Kawecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-19 00:00:00.000000000 Z
11
+ date: 2021-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '2.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.4'
61
+ version: '3.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.4'
68
+ version: '3.10'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +88,7 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - ".github/workflows/pull_request.yml"
91
92
  - ".gitignore"
92
93
  - ".idea/.name"
93
94
  - ".idea/encodings.xml"
@@ -96,6 +97,7 @@ files:
96
97
  - ".idea/vcs.xml"
97
98
  - ".rspec"
98
99
  - CHANGELOG.txt
100
+ - Dockerfile
99
101
  - Gemfile
100
102
  - Gemfile.lock
101
103
  - LICENSE.txt
@@ -103,6 +105,7 @@ files:
103
105
  - Rakefile
104
106
  - gb_dispatch.gemspec
105
107
  - lib/gb_dispatch.rb
108
+ - lib/gb_dispatch/active_record_patch.rb
106
109
  - lib/gb_dispatch/central_dispatch.rb
107
110
  - lib/gb_dispatch/manager.rb
108
111
  - lib/gb_dispatch/queue.rb
@@ -112,7 +115,7 @@ files:
112
115
  - spec/queue_spec.rb
113
116
  - spec/runner_spec.rb
114
117
  - spec/spec_helper.rb
115
- homepage: https://github.com/GenieBelt/gb-dispatch
118
+ homepage: https://github.com/letsbuilders/gb-dispatch
116
119
  licenses:
117
120
  - MIT
118
121
  metadata: {}
@@ -131,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
134
  - !ruby/object:Gem::Version
132
135
  version: '0'
133
136
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.4.8
137
+ rubygems_version: 3.0.3.1
136
138
  signing_key:
137
139
  specification_version: 4
138
140
  summary: GCD emulation for ruby
@@ -141,4 +143,3 @@ test_files:
141
143
  - spec/queue_spec.rb
142
144
  - spec/runner_spec.rb
143
145
  - spec/spec_helper.rb
144
- has_rdoc: