gb_dispatch 0.1.1 → 0.1.3
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 +4 -4
- data/.github/workflows/pull_request.yml +38 -0
- data/CHANGELOG.txt +4 -0
- data/Gemfile +3 -2
- data/Gemfile.lock +27 -28
- data/gb_dispatch.gemspec +2 -6
- data/lib/gb_dispatch/queue.rb +30 -21
- data/lib/gb_dispatch/version.rb +1 -1
- data/spec/queue_spec.rb +70 -1
- data/spec/spec_helper.rb +0 -1
- metadata +7 -66
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba5c5e7feb6bbcbd32177295f9b4c94445cf3f00fccf2bf526191974b2a9cc44
|
|
4
|
+
data.tar.gz: 31d741e2c2df908b4ace1ce692ac778922332eb8a661ad744f6a5383e9b9cd8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e00972fa6b4df1b8a3bc02f3a884ed44ae684d3f473c345939ca58484d4fcc7b58b842f72d4591ffad77dc5bc79480a4c6822d945f7babba9d45919dcd10d481
|
|
7
|
+
data.tar.gz: 2fa31828e4f3c11b0a81f57c83ce64a0e561f2f3018ab2829f68ac62a9c92419c3da89dd7107984498f4b7de34427a9ff81e3379ed6a8fc60799ec49356523aa
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Pull Request check
|
|
2
|
+
on:
|
|
3
|
+
- pull_request
|
|
4
|
+
- workflow_dispatch
|
|
5
|
+
env:
|
|
6
|
+
RACK_ENV: test
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
name: Run test
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
env:
|
|
12
|
+
SIMPLECOV: json
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
ruby: [ '3.2', '3.3', '3.4', '4.0' ]
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout code
|
|
19
|
+
uses: actions/checkout@v6
|
|
20
|
+
- name: Setup ruby
|
|
21
|
+
uses: ruby/setup-ruby@v1
|
|
22
|
+
with:
|
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
|
24
|
+
- name: Install gems
|
|
25
|
+
run: |
|
|
26
|
+
gem install bundler
|
|
27
|
+
bundle config set with 'development test'
|
|
28
|
+
bundle install
|
|
29
|
+
- name: Runs tests
|
|
30
|
+
run: |
|
|
31
|
+
bundle exec rspec -f j -o rspec_results.json -f p
|
|
32
|
+
- name: RSpec Report
|
|
33
|
+
if: always()
|
|
34
|
+
uses: SonicGarden/rspec-report-action@v6
|
|
35
|
+
continue-on-error: true
|
|
36
|
+
with:
|
|
37
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
38
|
+
json-path: rspec_results.json
|
data/CHANGELOG.txt
CHANGED
data/Gemfile
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
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,48 +1,47 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
gb_dispatch (0.1.
|
|
5
|
-
concurrent-ruby (
|
|
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.
|
|
11
|
-
concurrent-ruby-ext (1.
|
|
12
|
-
concurrent-ruby (= 1.
|
|
13
|
-
diff-lcs (1.
|
|
14
|
-
docile (1.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
rspec-
|
|
19
|
-
rspec-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
rspec-expectations (3.7.0)
|
|
10
|
+
concurrent-ruby (1.3.6)
|
|
11
|
+
concurrent-ruby-ext (1.3.6)
|
|
12
|
+
concurrent-ruby (= 1.3.6)
|
|
13
|
+
diff-lcs (1.4.4)
|
|
14
|
+
docile (1.4.0)
|
|
15
|
+
rake (13.3.1)
|
|
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.
|
|
26
|
-
rspec-mocks (3.
|
|
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.
|
|
29
|
-
rspec-support (3.
|
|
30
|
-
simplecov (0.
|
|
27
|
+
rspec-support (~> 3.10.0)
|
|
28
|
+
rspec-support (3.10.3)
|
|
29
|
+
simplecov (0.21.2)
|
|
31
30
|
docile (~> 1.1)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
simplecov-html (0.
|
|
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)
|
|
41
40
|
concurrent-ruby-ext
|
|
42
41
|
gb_dispatch!
|
|
43
|
-
rake (
|
|
44
|
-
rspec
|
|
42
|
+
rake (>= 13.2)
|
|
43
|
+
rspec (~> 3.10)
|
|
45
44
|
simplecov
|
|
46
45
|
|
|
47
46
|
BUNDLED WITH
|
|
48
|
-
|
|
47
|
+
4.0.3
|
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/
|
|
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,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.
|
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.6'
|
|
23
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
|
24
|
-
spec.add_development_dependency 'rspec', '~> 3.4'
|
|
25
|
-
spec.add_development_dependency 'simplecov'
|
|
21
|
+
spec.add_runtime_dependency 'concurrent-ruby', '>= 1.0'
|
|
26
22
|
end
|
data/lib/gb_dispatch/queue.rb
CHANGED
|
@@ -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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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,28 @@ 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
|
+
begin
|
|
63
|
+
ActiveRecord::Base.connection_pool.with_connection do
|
|
64
|
+
yield
|
|
65
|
+
end
|
|
66
|
+
ensure
|
|
67
|
+
ActiveRecord::Base.clear_active_connections!
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def with_rails_executor
|
|
72
|
+
return yield unless defined?(Rails) && Rails::VERSION::MAJOR >= 5
|
|
73
|
+
|
|
74
|
+
Rails.application.executor.wrap do
|
|
75
|
+
yield
|
|
76
|
+
end
|
|
77
|
+
end
|
|
69
78
|
end
|
|
70
79
|
end
|
data/lib/gb_dispatch/version.rb
CHANGED
data/spec/queue_spec.rb
CHANGED
|
@@ -147,4 +147,73 @@ describe GBDispatch::Queue do
|
|
|
147
147
|
expect(a).to eq :bar
|
|
148
148
|
end
|
|
149
149
|
end
|
|
150
|
-
|
|
150
|
+
|
|
151
|
+
context 'activerecord without rails' do
|
|
152
|
+
before(:each) do
|
|
153
|
+
module ActiveRecord
|
|
154
|
+
class Base
|
|
155
|
+
class DummyConnectionPool
|
|
156
|
+
def with_connection
|
|
157
|
+
yield
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def force_new_connection
|
|
161
|
+
with_connection do
|
|
162
|
+
yield
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def self.connection_pool
|
|
168
|
+
@pool ||= DummyConnectionPool.new
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def self.clear_active_connections!
|
|
172
|
+
true
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
after(:each) do
|
|
179
|
+
begin
|
|
180
|
+
Kernel.send :remove_const, 'ActiveRecord'
|
|
181
|
+
rescue
|
|
182
|
+
nil
|
|
183
|
+
end
|
|
184
|
+
begin
|
|
185
|
+
Object.send :remove_const, 'ActiveRecord'
|
|
186
|
+
rescue
|
|
187
|
+
nil
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it 'should wrap execution with connection pool when activerecord is present without rails' do
|
|
192
|
+
a = :foo
|
|
193
|
+
queue = GBDispatch::Queue.new(:test)
|
|
194
|
+
expect(ActiveRecord::Base.connection_pool).to receive(:with_connection).and_call_original
|
|
195
|
+
expect(ActiveRecord::Base).to receive(:clear_active_connections!)
|
|
196
|
+
queue.await.perform_now do
|
|
197
|
+
a = :bar
|
|
198
|
+
end
|
|
199
|
+
expect(a).to eq :bar
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it 'should execute lambda and wrap with connection pool' do
|
|
203
|
+
a = :foo
|
|
204
|
+
queue = GBDispatch::Queue.new(:test)
|
|
205
|
+
expect(ActiveRecord::Base.connection_pool).to receive(:with_connection).and_call_original
|
|
206
|
+
expect(ActiveRecord::Base).to receive(:clear_active_connections!)
|
|
207
|
+
queue.await.perform_now ->() { a = :bar }
|
|
208
|
+
expect(a).to eq :bar
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it 'should return exception object on failure without rails' do
|
|
212
|
+
queue = GBDispatch::Queue.new(:test)
|
|
213
|
+
a = queue.perform_now ->() do
|
|
214
|
+
raise StandardError.new 'Test error'
|
|
215
|
+
end
|
|
216
|
+
expect(a).to be_kind_of StandardError
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kacper Kawecki
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2026-03-17 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: '1.6'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '1.6'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: rake
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '10.0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '10.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.4'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '3.4'
|
|
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:
|
|
@@ -88,6 +31,7 @@ executables: []
|
|
|
88
31
|
extensions: []
|
|
89
32
|
extra_rdoc_files: []
|
|
90
33
|
files:
|
|
34
|
+
- ".github/workflows/pull_request.yml"
|
|
91
35
|
- ".gitignore"
|
|
92
36
|
- ".idea/.name"
|
|
93
37
|
- ".idea/encodings.xml"
|
|
@@ -114,11 +58,10 @@ files:
|
|
|
114
58
|
- spec/queue_spec.rb
|
|
115
59
|
- spec/runner_spec.rb
|
|
116
60
|
- spec/spec_helper.rb
|
|
117
|
-
homepage: https://github.com/
|
|
61
|
+
homepage: https://github.com/letsbuilders/gb-dispatch
|
|
118
62
|
licenses:
|
|
119
63
|
- MIT
|
|
120
64
|
metadata: {}
|
|
121
|
-
post_install_message:
|
|
122
65
|
rdoc_options: []
|
|
123
66
|
require_paths:
|
|
124
67
|
- lib
|
|
@@ -133,9 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
133
76
|
- !ruby/object:Gem::Version
|
|
134
77
|
version: '0'
|
|
135
78
|
requirements: []
|
|
136
|
-
|
|
137
|
-
rubygems_version: 2.7.6
|
|
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:
|