gb_dispatch 0.1.2 → 0.1.4

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
2
  SHA256:
3
- metadata.gz: ff34ac0be45aa71f7e09c89d335546f4aab2619f7ee733259545c86a5d24e995
4
- data.tar.gz: 2091aeafb3409669fdafb83758304595fb280e924d93fc93c87941619410fd8c
3
+ metadata.gz: 1c59ba469fa518ae4155cc6bd0f47054e71015e5e945250cf8db53ee09cb67ad
4
+ data.tar.gz: 276468d56b40a9aea7753d62196273956e24145a2a0398b8d6c7a3c48c4b7b31
5
5
  SHA512:
6
- metadata.gz: f18f2688b5818c364a2930017583933e91ef4cd39013b3273e0a25bf27580c72cce19d712ff2ded7d86790a03c1f4e8070f2b7d462b2027d8f9fda2319f4de79
7
- data.tar.gz: 8be0d22b75b006dac434bc330224bc507e07a8ea4d8f1a8ade1e8b60bd8b283700b18728a10ed082e393d888f06abddd391bcae34c1bd46b630153342dac5f15
6
+ metadata.gz: 2da4897ce97fef40cb183aa62cfc742a4e0df4c17a3f538ea8769c85fa1983ac6d4cc08ae715aaec2cb5244b5d2d640478525e125fe1e30ea8da8306a833b78e
7
+ data.tar.gz: d3943ef7a5a087a2fd5f2a816c09a727ce0b710d202c4eaba3f59f15678ce26dfb5d0e417e6711effefba7a81fbdf405facc767b433914e4ffa0e8fab2e41a77
@@ -4,7 +4,6 @@ on:
4
4
  - workflow_dispatch
5
5
  env:
6
6
  RACK_ENV: test
7
- ImageOS: ubuntu20
8
7
  jobs:
9
8
  test:
10
9
  name: Run test
@@ -14,36 +13,26 @@ jobs:
14
13
  strategy:
15
14
  fail-fast: false
16
15
  matrix:
17
- ruby: [ '2.5', '2.6', '2.7', '3.0' ]
16
+ ruby: [ '3.2', '3.3', '3.4', '4.0' ]
18
17
  steps:
19
18
  - name: Checkout code
20
- uses: actions/checkout@v2
19
+ uses: actions/checkout@v6
21
20
  - name: Setup ruby
22
21
  uses: ruby/setup-ruby@v1
23
22
  with:
24
23
  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
24
  - name: Install gems
33
25
  run: |
34
26
  gem install bundler
35
- bundle install --with development test --deployment --jobs 16
27
+ bundle config set with 'development test'
28
+ bundle install
36
29
  - name: Runs tests
37
30
  run: |
38
31
  bundle exec rspec -f j -o rspec_results.json -f p
39
32
  - name: RSpec Report
40
33
  if: always()
41
- uses: SonicGarden/rspec-report-action@v1
34
+ uses: SonicGarden/rspec-report-action@v6
35
+ continue-on-error: true
42
36
  with:
43
37
  token: ${{ secrets.GITHUB_TOKEN }}
44
38
  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/Gemfile CHANGED
@@ -1,11 +1,12 @@
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
5
5
 
6
6
  gem 'concurrent-ruby-ext'
7
+ gem 'rake', '>= 13.2'
7
8
 
8
9
  group :test do
9
- gem 'rspec'
10
+ gem 'rspec', '~> 3.10'
10
11
  gem 'simplecov', :require => false
11
12
  end
data/Gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gb_dispatch (0.1.2)
5
- concurrent-ruby (~> 1.0)
4
+ gb_dispatch (0.1.3)
5
+ concurrent-ruby (>= 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- concurrent-ruby (1.1.9)
11
- concurrent-ruby-ext (1.1.9)
12
- concurrent-ruby (= 1.1.9)
10
+ concurrent-ruby (1.3.6)
11
+ concurrent-ruby-ext (1.3.6)
12
+ concurrent-ruby (= 1.3.6)
13
13
  diff-lcs (1.4.4)
14
14
  docile (1.4.0)
15
- rake (13.0.6)
15
+ rake (13.3.1)
16
16
  rspec (3.10.0)
17
17
  rspec-core (~> 3.10.0)
18
18
  rspec-expectations (~> 3.10.0)
@@ -37,12 +37,11 @@ PLATFORMS
37
37
  ruby
38
38
 
39
39
  DEPENDENCIES
40
- bundler (~> 2.2)
41
40
  concurrent-ruby-ext
42
41
  gb_dispatch!
43
- rake (~> 13.0)
44
- rspec
42
+ rake (>= 13.2)
43
+ rspec (~> 3.10)
45
44
  simplecov
46
45
 
47
46
  BUNDLED WITH
48
- 2.2.30
47
+ 4.0.3
data/gb_dispatch.gemspec CHANGED
@@ -18,9 +18,5 @@ 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_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
- spec.add_development_dependency 'simplecov'
21
+ spec.add_runtime_dependency 'concurrent-ruby', '>= 1.0'
26
22
  end
@@ -20,27 +20,12 @@ module GBDispatch
20
20
  # @return [Object, Exception] returns value of executed block or exception if block execution failed.
21
21
  def perform_now(block=nil)
22
22
  Thread.current[:name] ||= name
23
- if defined?(Rails) && defined?(ActiveRecord::Base)
24
- require 'gb_dispatch/active_record_patch'
25
- thread_block = ->() do
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
39
- end
23
+ thread_block = ->() do
24
+ with_rails_executor do
25
+ with_connection_pool do
26
+ block ? block.call : yield
40
27
  end
41
28
  end
42
- else
43
- thread_block = block ? block : ->() { yield }
44
29
  end
45
30
  begin
46
31
  Runner.execute thread_block, name: name
@@ -56,8 +41,9 @@ module GBDispatch
56
41
  # @return [Concurrent::ScheduledTask]
57
42
  def perform_after(time, block=nil)
58
43
  task = Concurrent::ScheduledTask.new(time) do
59
- block = ->(){ yield } unless block
60
- self.async.perform_now block
44
+ self.async.perform_now do
45
+ block ? block.call : yield
46
+ end
61
47
  end
62
48
  task.execute
63
49
  task
@@ -66,5 +52,24 @@ module GBDispatch
66
52
  def to_s
67
53
  self.name.to_s
68
54
  end
55
+
56
+ private
57
+
58
+ def with_connection_pool
59
+ return yield unless defined?(ActiveRecord::Base)
60
+
61
+ require 'gb_dispatch/active_record_patch'
62
+ ActiveRecord::Base.connection_pool.with_connection do
63
+ yield
64
+ end
65
+ end
66
+
67
+ def with_rails_executor
68
+ return yield unless defined?(Rails) && Rails::VERSION::MAJOR >= 5
69
+
70
+ Rails.application.executor.wrap do
71
+ yield
72
+ end
73
+ end
69
74
  end
70
75
  end
@@ -1,3 +1,3 @@
1
1
  module GBDispatch
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.4'
3
3
  end
data/spec/queue_spec.rb CHANGED
@@ -140,11 +140,77 @@ describe GBDispatch::Queue do
140
140
  a = :foo
141
141
  queue = GBDispatch::Queue.new(:test)
142
142
  expect(ActiveRecord::Base.connection_pool).to receive(:with_connection).and_call_original
143
- expect(ActiveRecord::Base).to receive(:clear_active_connections!)
144
143
  queue.await.perform_now do
145
144
  a = :bar
146
145
  end
147
146
  expect(a).to eq :bar
148
147
  end
149
148
  end
150
- end
149
+
150
+ context 'activerecord without rails' do
151
+ before(:each) do
152
+ module ActiveRecord
153
+ class Base
154
+ class DummyConnectionPool
155
+ def with_connection
156
+ yield
157
+ end
158
+
159
+ def force_new_connection
160
+ with_connection do
161
+ yield
162
+ end
163
+ end
164
+ end
165
+
166
+ def self.connection_pool
167
+ @pool ||= DummyConnectionPool.new
168
+ end
169
+
170
+ def self.clear_active_connections!
171
+ true
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ after(:each) do
178
+ begin
179
+ Kernel.send :remove_const, 'ActiveRecord'
180
+ rescue
181
+ nil
182
+ end
183
+ begin
184
+ Object.send :remove_const, 'ActiveRecord'
185
+ rescue
186
+ nil
187
+ end
188
+ end
189
+
190
+ it 'should wrap execution with connection pool when activerecord is present without rails' do
191
+ a = :foo
192
+ queue = GBDispatch::Queue.new(:test)
193
+ expect(ActiveRecord::Base.connection_pool).to receive(:with_connection).and_call_original
194
+ queue.await.perform_now do
195
+ a = :bar
196
+ end
197
+ expect(a).to eq :bar
198
+ end
199
+
200
+ it 'should execute lambda and wrap with connection pool' do
201
+ a = :foo
202
+ queue = GBDispatch::Queue.new(:test)
203
+ expect(ActiveRecord::Base.connection_pool).to receive(:with_connection).and_call_original
204
+ queue.await.perform_now ->() { a = :bar }
205
+ expect(a).to eq :bar
206
+ end
207
+
208
+ it 'should return exception object on failure without rails' do
209
+ queue = GBDispatch::Queue.new(:test)
210
+ a = queue.perform_now ->() do
211
+ raise StandardError.new 'Test error'
212
+ end
213
+ expect(a).to be_kind_of StandardError
214
+ end
215
+ end
216
+ end
data/spec/spec_helper.rb CHANGED
@@ -17,7 +17,6 @@
17
17
  #
18
18
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
19
  require 'simplecov'
20
- require 'ostruct'
21
20
  SimpleCov.start do
22
21
  add_filter '/spec/'
23
22
  end
metadata CHANGED
@@ -1,85 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gb_dispatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacper Kawecki
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-11-09 00:00:00.000000000 Z
10
+ date: 2026-03-19 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: concurrent-ruby
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '1.0'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.2'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.2'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.10'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.10'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
22
  requirements:
73
23
  - - ">="
74
24
  - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
25
+ version: '1.0'
83
26
  description: 'Grand central dispatch (GCD) emulation for ruby. It allows to easily
84
27
  run asynchronous code. '
85
28
  email:
@@ -119,7 +62,6 @@ homepage: https://github.com/letsbuilders/gb-dispatch
119
62
  licenses:
120
63
  - MIT
121
64
  metadata: {}
122
- post_install_message:
123
65
  rdoc_options: []
124
66
  require_paths:
125
67
  - lib
@@ -134,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
76
  - !ruby/object:Gem::Version
135
77
  version: '0'
136
78
  requirements: []
137
- rubygems_version: 3.0.3.1
138
- signing_key:
79
+ rubygems_version: 3.6.2
139
80
  specification_version: 4
140
81
  summary: GCD emulation for ruby
141
82
  test_files: