fleiss 0.4.5 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -2
- data/.rubocop.yml +1 -1
- data/Gemfile +7 -0
- data/Gemfile.lock +53 -49
- data/fleiss.gemspec +3 -9
- data/lib/fleiss/cli.rb +1 -1
- metadata +7 -100
- data/spec/fleiss/backend/active_record_spec.rb +0 -135
- data/spec/fleiss/executor_spec.rb +0 -29
- data/spec/fleiss/worker_spec.rb +0 -68
- data/spec/fleiss_spec.rb +0 -13
- data/spec/spec_helper.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 242a1ac6bbf715ff7850982b3206ab78191520915c7ec7780d4a84bf1390c9bd
|
4
|
+
data.tar.gz: f6ce5dbf58062f847a3213a3a96d5a0909c9ef7f73f93d0bc71012bff5451629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 512cf207ecac8195420583f622df97ca7d282498941da500b8e56e1de90e8f2e08522497453e28904630fd67b8820b075bc7c1af28d0936daff0a102dae9f070
|
7
|
+
data.tar.gz: 462ec0e4cd5976744c8a8793be2190fb0c1289eb0ab0480ee92359ad8c246c3542c3b9f36810708601060f438088374d0bb45763655259d1e62943a9daf89eeb
|
data/.github/workflows/test.yml
CHANGED
@@ -11,9 +11,9 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
|
-
ruby-version: ["2.
|
14
|
+
ruby-version: ["2.7", "3.0", "3.1", "3.2"]
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v3
|
17
17
|
- uses: ruby/setup-ruby@v1
|
18
18
|
with:
|
19
19
|
ruby-version: ${{ matrix.ruby-version }}
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fleiss (0.
|
4
|
+
fleiss (0.5.1)
|
5
5
|
activejob (>= 6.0)
|
6
6
|
activerecord (>= 6.0)
|
7
7
|
concurrent-ruby
|
@@ -9,80 +9,84 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activejob (
|
13
|
-
activesupport (=
|
12
|
+
activejob (7.0.4.2)
|
13
|
+
activesupport (= 7.0.4.2)
|
14
14
|
globalid (>= 0.3.6)
|
15
|
-
activemodel (
|
16
|
-
activesupport (=
|
17
|
-
activerecord (
|
18
|
-
activemodel (=
|
19
|
-
activesupport (=
|
20
|
-
activesupport (
|
15
|
+
activemodel (7.0.4.2)
|
16
|
+
activesupport (= 7.0.4.2)
|
17
|
+
activerecord (7.0.4.2)
|
18
|
+
activemodel (= 7.0.4.2)
|
19
|
+
activesupport (= 7.0.4.2)
|
20
|
+
activesupport (7.0.4.2)
|
21
21
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
22
22
|
i18n (>= 1.6, < 2)
|
23
23
|
minitest (>= 5.1)
|
24
24
|
tzinfo (~> 2.0)
|
25
|
-
zeitwerk (~> 2.3)
|
26
25
|
ast (2.4.2)
|
27
|
-
concurrent-ruby (1.
|
28
|
-
diff-lcs (1.
|
29
|
-
globalid (
|
26
|
+
concurrent-ruby (1.2.0)
|
27
|
+
diff-lcs (1.5.0)
|
28
|
+
globalid (1.1.0)
|
30
29
|
activesupport (>= 5.0)
|
31
|
-
i18n (1.
|
30
|
+
i18n (1.12.0)
|
32
31
|
concurrent-ruby (~> 1.0)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
json (2.6.3)
|
33
|
+
mini_portile2 (2.8.1)
|
34
|
+
minitest (5.17.0)
|
35
|
+
mysql2 (0.5.5)
|
36
|
+
parallel (1.22.1)
|
37
|
+
parser (3.2.0.0)
|
37
38
|
ast (~> 2.4.1)
|
38
|
-
pg (1.
|
39
|
-
rainbow (3.
|
39
|
+
pg (1.4.5)
|
40
|
+
rainbow (3.1.1)
|
40
41
|
rake (13.0.6)
|
41
|
-
regexp_parser (2.
|
42
|
+
regexp_parser (2.6.2)
|
42
43
|
rexml (3.2.5)
|
43
|
-
rspec (3.
|
44
|
-
rspec-core (~> 3.
|
45
|
-
rspec-expectations (~> 3.
|
46
|
-
rspec-mocks (~> 3.
|
47
|
-
rspec-core (3.
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-expectations (3.
|
44
|
+
rspec (3.12.0)
|
45
|
+
rspec-core (~> 3.12.0)
|
46
|
+
rspec-expectations (~> 3.12.0)
|
47
|
+
rspec-mocks (~> 3.12.0)
|
48
|
+
rspec-core (3.12.1)
|
49
|
+
rspec-support (~> 3.12.0)
|
50
|
+
rspec-expectations (3.12.2)
|
50
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.
|
52
|
-
rspec-mocks (3.
|
52
|
+
rspec-support (~> 3.12.0)
|
53
|
+
rspec-mocks (3.12.3)
|
53
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
-
rspec-support (~> 3.
|
55
|
-
rspec-support (3.
|
56
|
-
rubocop (1.
|
55
|
+
rspec-support (~> 3.12.0)
|
56
|
+
rspec-support (3.12.0)
|
57
|
+
rubocop (1.44.1)
|
58
|
+
json (~> 2.3)
|
57
59
|
parallel (~> 1.10)
|
58
|
-
parser (>= 3.
|
60
|
+
parser (>= 3.2.0.0)
|
59
61
|
rainbow (>= 2.2.2, < 4.0)
|
60
62
|
regexp_parser (>= 1.8, < 3.0)
|
61
|
-
rexml
|
62
|
-
rubocop-ast (>= 1.
|
63
|
+
rexml (>= 3.2.5, < 4.0)
|
64
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
63
65
|
ruby-progressbar (~> 1.7)
|
64
|
-
unicode-display_width (>=
|
65
|
-
rubocop-ast (1.
|
66
|
-
parser (>= 3.
|
67
|
-
rubocop-bsm (0.6.
|
66
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
67
|
+
rubocop-ast (1.24.1)
|
68
|
+
parser (>= 3.1.1.0)
|
69
|
+
rubocop-bsm (0.6.1)
|
68
70
|
rubocop (~> 1.0)
|
69
71
|
rubocop-performance
|
70
72
|
rubocop-rake
|
71
73
|
rubocop-rspec
|
72
|
-
rubocop-
|
74
|
+
rubocop-capybara (2.17.0)
|
75
|
+
rubocop (~> 1.41)
|
76
|
+
rubocop-performance (1.16.0)
|
73
77
|
rubocop (>= 1.7.0, < 2.0)
|
74
78
|
rubocop-ast (>= 0.4.0)
|
75
79
|
rubocop-rake (0.6.0)
|
76
80
|
rubocop (~> 1.0)
|
77
|
-
rubocop-rspec (2.
|
78
|
-
rubocop (~> 1.
|
79
|
-
rubocop-
|
81
|
+
rubocop-rspec (2.18.1)
|
82
|
+
rubocop (~> 1.33)
|
83
|
+
rubocop-capybara (~> 2.17)
|
80
84
|
ruby-progressbar (1.11.0)
|
81
|
-
sqlite3 (1.
|
82
|
-
|
85
|
+
sqlite3 (1.6.0)
|
86
|
+
mini_portile2 (~> 2.8.0)
|
87
|
+
tzinfo (2.0.6)
|
83
88
|
concurrent-ruby (~> 1.0)
|
84
|
-
unicode-display_width (2.
|
85
|
-
zeitwerk (2.4.2)
|
89
|
+
unicode-display_width (2.4.2)
|
86
90
|
|
87
91
|
PLATFORMS
|
88
92
|
ruby
|
@@ -98,4 +102,4 @@ DEPENDENCIES
|
|
98
102
|
sqlite3
|
99
103
|
|
100
104
|
BUNDLED WITH
|
101
|
-
2.
|
105
|
+
2.3.16
|
data/fleiss.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'fleiss'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.5.1'
|
4
4
|
s.authors = ['Black Square Media Ltd']
|
5
5
|
s.email = ['info@blacksquaremedia.com']
|
6
6
|
s.summary = %(Minimialist background jobs backed by ActiveJob and ActiveRecord.)
|
@@ -10,19 +10,13 @@ Gem::Specification.new do |s|
|
|
10
10
|
|
11
11
|
s.executables = ['fleiss']
|
12
12
|
s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
|
13
|
-
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
14
13
|
s.require_paths = ['lib']
|
15
|
-
s.required_ruby_version = '>= 2.
|
14
|
+
s.required_ruby_version = '>= 2.7'
|
16
15
|
|
17
16
|
s.add_dependency 'activejob', '>= 6.0'
|
18
17
|
s.add_dependency 'activerecord', '>= 6.0'
|
19
18
|
s.add_dependency 'concurrent-ruby'
|
20
19
|
|
21
20
|
s.add_development_dependency 'bundler'
|
22
|
-
s.
|
23
|
-
s.add_development_dependency 'pg'
|
24
|
-
s.add_development_dependency 'rake'
|
25
|
-
s.add_development_dependency 'rspec'
|
26
|
-
s.add_development_dependency 'rubocop-bsm'
|
27
|
-
s.add_development_dependency 'sqlite3'
|
21
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
28
22
|
end
|
data/lib/fleiss/cli.rb
CHANGED
@@ -31,7 +31,7 @@ module Fleiss
|
|
31
31
|
return unless opts[:config]
|
32
32
|
|
33
33
|
# Load config file
|
34
|
-
conf = YAML.safe_load(ERB.new(
|
34
|
+
conf = YAML.safe_load(ERB.new(File.read(opts[:config])).result)
|
35
35
|
raise ArgumentError, "File in #{opts[:config]} does not contain a valid configuration" unless conf.is_a?(Hash)
|
36
36
|
|
37
37
|
conf.each do |key, value|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fleiss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Black Square Media Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -66,90 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: mysql2
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !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'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pg
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rake
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop-bsm
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: sqlite3
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
69
|
description: Run background jobs with your favourite stack.
|
154
70
|
email:
|
155
71
|
- info@blacksquaremedia.com
|
@@ -178,15 +94,11 @@ files:
|
|
178
94
|
- lib/fleiss/cli.rb
|
179
95
|
- lib/fleiss/executor.rb
|
180
96
|
- lib/fleiss/worker.rb
|
181
|
-
- spec/fleiss/backend/active_record_spec.rb
|
182
|
-
- spec/fleiss/executor_spec.rb
|
183
|
-
- spec/fleiss/worker_spec.rb
|
184
|
-
- spec/fleiss_spec.rb
|
185
|
-
- spec/spec_helper.rb
|
186
97
|
homepage: https://github.com/bsm/fleiss
|
187
98
|
licenses:
|
188
99
|
- Apache-2.0
|
189
|
-
metadata:
|
100
|
+
metadata:
|
101
|
+
rubygems_mfa_required: 'true'
|
190
102
|
post_install_message:
|
191
103
|
rdoc_options: []
|
192
104
|
require_paths:
|
@@ -195,20 +107,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
107
|
requirements:
|
196
108
|
- - ">="
|
197
109
|
- !ruby/object:Gem::Version
|
198
|
-
version: '2.
|
110
|
+
version: '2.7'
|
199
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
112
|
requirements:
|
201
113
|
- - ">="
|
202
114
|
- !ruby/object:Gem::Version
|
203
115
|
version: '0'
|
204
116
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.4.6
|
206
118
|
signing_key:
|
207
119
|
specification_version: 4
|
208
120
|
summary: Minimialist background jobs backed by ActiveJob and ActiveRecord.
|
209
|
-
test_files:
|
210
|
-
- spec/fleiss/backend/active_record_spec.rb
|
211
|
-
- spec/fleiss/executor_spec.rb
|
212
|
-
- spec/fleiss/worker_spec.rb
|
213
|
-
- spec/fleiss_spec.rb
|
214
|
-
- spec/spec_helper.rb
|
121
|
+
test_files: []
|
@@ -1,135 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Fleiss::Backend::ActiveRecord do
|
4
|
-
def retrieve(job)
|
5
|
-
described_class.find(job.provider_job_id)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'persists jobs' do
|
9
|
-
job = TestJob.perform_later
|
10
|
-
rec = retrieve(job)
|
11
|
-
|
12
|
-
expect(rec.attributes).to include(
|
13
|
-
'queue_name' => 'test-queue',
|
14
|
-
'owner' => nil,
|
15
|
-
'started_at' => nil,
|
16
|
-
'finished_at' => nil,
|
17
|
-
)
|
18
|
-
expect(rec.scheduled_at).to be_within(2.seconds).of(Time.zone.now)
|
19
|
-
expect(rec.expires_at).to be_within(2.seconds).of(3.days.from_now)
|
20
|
-
expect(rec.job_data).to include(
|
21
|
-
'job_class' => 'TestJob',
|
22
|
-
'arguments' => [],
|
23
|
-
'executions' => 0,
|
24
|
-
'locale' => 'en',
|
25
|
-
'priority' => nil,
|
26
|
-
'provider_job_id' => nil,
|
27
|
-
'queue_name' => 'test-queue',
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'enqueues with delay' do
|
32
|
-
job = TestJob.set(wait: 1.day).perform_later
|
33
|
-
rec = retrieve(job)
|
34
|
-
expect(rec.scheduled_at).to be_within(2.seconds).of(1.day.from_now)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'enqueues with priority' do
|
38
|
-
job = TestJob.set(priority: 8).perform_later
|
39
|
-
rec = retrieve(job)
|
40
|
-
expect(rec.priority).to eq(8)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'exposes active job ID' do
|
44
|
-
job = TestJob.perform_later
|
45
|
-
rec = retrieve(job)
|
46
|
-
expect(rec.job_id.size).to eq(36)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'scopes pending' do
|
50
|
-
j1 = TestJob.perform_later
|
51
|
-
expect(retrieve(j1).start('owner')).to be_truthy
|
52
|
-
expect(retrieve(j1).finish('owner')).to be_truthy
|
53
|
-
|
54
|
-
j2 = TestJob.perform_later
|
55
|
-
_j3 = TestJob.set(wait: 1.hour).perform_later
|
56
|
-
j4 = TestJob.set(priority: 2).perform_later
|
57
|
-
|
58
|
-
expect(described_class.pending.ids).to eq [j4.provider_job_id, j2.provider_job_id]
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'scopes in_progress' do
|
62
|
-
_j1 = TestJob.perform_later
|
63
|
-
j2 = TestJob.perform_later
|
64
|
-
expect(retrieve(j2).start('owner')).to be_truthy
|
65
|
-
|
66
|
-
j3 = TestJob.perform_later
|
67
|
-
expect(retrieve(j3).start('owner')).to be_truthy
|
68
|
-
expect(described_class.in_progress('owner').ids).to match_array [j2.provider_job_id, j3.provider_job_id]
|
69
|
-
expect(described_class.in_progress('other').ids).to be_empty
|
70
|
-
|
71
|
-
expect(retrieve(j3).finish('owner')).to be_truthy
|
72
|
-
expect(described_class.in_progress('owner').ids).to eq [j2.provider_job_id]
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'scopes by queue' do
|
76
|
-
j1 = TestJob.perform_later
|
77
|
-
j2 = TestJob.set(queue: 'other').perform_later
|
78
|
-
expect(described_class.in_queue('test-queue').ids).to eq [j1.provider_job_id]
|
79
|
-
expect(described_class.in_queue('other').ids).to eq [j2.provider_job_id]
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'starts' do
|
83
|
-
job = TestJob.perform_later
|
84
|
-
rec = retrieve(job)
|
85
|
-
expect(rec.start('owner')).to be_truthy
|
86
|
-
expect(rec.start('other')).to be_falsey
|
87
|
-
expect(rec.reload.owner).to eq('owner')
|
88
|
-
expect(rec.started_at).to be_within(2.seconds).of(Time.zone.now)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'locks atomically' do
|
92
|
-
24.times do
|
93
|
-
TestJob.perform_later
|
94
|
-
end
|
95
|
-
counts = (1..4).map do |n|
|
96
|
-
Thread.new do
|
97
|
-
described_class.pending.to_a.count {|j| j.start "owner-#{n}" }
|
98
|
-
end
|
99
|
-
end.map(&:value)
|
100
|
-
expect(counts.sum).to eq(24)
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'finishes' do
|
104
|
-
job = TestJob.perform_later
|
105
|
-
rec = retrieve(job)
|
106
|
-
expect(rec.finish('owner')).to be_falsey
|
107
|
-
expect(rec.start('owner')).to be_truthy
|
108
|
-
expect(rec.finish('other')).to be_falsey
|
109
|
-
expect(rec.finish('owner')).to be_truthy
|
110
|
-
expect(rec.reload.owner).to eq('owner')
|
111
|
-
expect(rec.started_at).to be_within(2.seconds).of(Time.zone.now)
|
112
|
-
expect(rec.finished_at).to be_within(2.seconds).of(Time.zone.now)
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'reschedules' do
|
116
|
-
job = TestJob.perform_later
|
117
|
-
rec = retrieve(job)
|
118
|
-
expect(rec.reschedule('owner')).to be_falsey
|
119
|
-
expect(rec.start('owner')).to be_truthy
|
120
|
-
expect(rec.reschedule('other')).to be_falsey
|
121
|
-
expect(rec.reschedule('owner')).to be_truthy
|
122
|
-
expect(rec.reload.owner).to be_nil
|
123
|
-
expect(rec.started_at).to be_nil
|
124
|
-
expect(rec.scheduled_at).to be_within(2.seconds).of(Time.zone.now)
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'reconnects' do
|
128
|
-
expect(::ActiveRecord::Base).to receive(:clear_all_connections!).once.and_return(nil)
|
129
|
-
|
130
|
-
expect do
|
131
|
-
described_class.wrap_perform { raise ::ActiveRecord::StatementInvalid }
|
132
|
-
end
|
133
|
-
.to raise_error(::ActiveRecord::StatementInvalid) # re-raised anyway
|
134
|
-
end
|
135
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fleiss/executor'
|
3
|
-
|
4
|
-
RSpec.describe Fleiss::Executor do
|
5
|
-
subject { described_class.new max_size: 2 }
|
6
|
-
|
7
|
-
after { subject.kill }
|
8
|
-
|
9
|
-
it 'checks capacity' do
|
10
|
-
expect(described_class.new.capacity).to eq(1)
|
11
|
-
|
12
|
-
expect(subject.capacity).to eq(2)
|
13
|
-
subject.post { sleep(1) }
|
14
|
-
expect(subject.capacity).to eq(1)
|
15
|
-
subject.post { sleep(1) }
|
16
|
-
expect(subject.capacity).to eq(0)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'discards execution when capacity is reached' do
|
20
|
-
n = Concurrent::AtomicFixnum.new(0)
|
21
|
-
10.times do
|
22
|
-
10.times { subject.post { n.increment } }
|
23
|
-
sleep(0.001)
|
24
|
-
end
|
25
|
-
subject.shutdown
|
26
|
-
subject.wait_for_termination(1)
|
27
|
-
expect(n.value).to be_within(10).of(20)
|
28
|
-
end
|
29
|
-
end
|
data/spec/fleiss/worker_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fleiss/worker'
|
3
|
-
|
4
|
-
RSpec.describe Fleiss::Worker do
|
5
|
-
subject do
|
6
|
-
described_class.new queues: TestJob.queue_name, wait_time: 0.01
|
7
|
-
end
|
8
|
-
|
9
|
-
let! :runner do
|
10
|
-
t = Thread.new { subject.run }
|
11
|
-
t.abort_on_exception = true
|
12
|
-
t
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
runner.kill
|
17
|
-
end
|
18
|
-
|
19
|
-
around do |example|
|
20
|
-
callback = ->(*args) { notifications.push ActiveSupport::Notifications::Event.new(*args) }
|
21
|
-
ActiveSupport::Notifications.subscribed(callback, 'worker_perform.fleiss') do
|
22
|
-
example.call
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def wait_for
|
27
|
-
100.times do
|
28
|
-
break if yield
|
29
|
-
|
30
|
-
sleep(0.1)
|
31
|
-
end
|
32
|
-
expect(yield).to be_truthy
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'runs' do
|
36
|
-
# seed 24 jobs
|
37
|
-
24.times {|n| TestJob.perform_later(n) }
|
38
|
-
wait_for { Fleiss.backend.not_finished.count.positive? }
|
39
|
-
|
40
|
-
# ensure runner processes them all
|
41
|
-
wait_for { Fleiss.backend.not_finished.count.zero? }
|
42
|
-
|
43
|
-
# check what's been performed
|
44
|
-
expect(TestJob.performed.size).to eq(24)
|
45
|
-
expect(Fleiss.backend.finished.count).to eq(24)
|
46
|
-
expect(TestJob.performed).to match_array(0..23)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'handles failing jobs' do
|
50
|
-
TestJob.perform_later('raise')
|
51
|
-
wait_for { Fleiss.backend.not_finished.count.zero? }
|
52
|
-
expect(Fleiss.backend.finished.count).to eq(1)
|
53
|
-
|
54
|
-
expect(notifications.size).to eq(1)
|
55
|
-
expect(notifications.first.payload).to have_key(:id)
|
56
|
-
expect(notifications.first.payload).to have_key(:uuid)
|
57
|
-
expect(notifications.first.payload).to have_key(:thread_id)
|
58
|
-
expect(notifications.first.payload[:finished]).to be_truthy
|
59
|
-
expect(notifications.first.payload[:exception_object]).to be_an_instance_of(RuntimeError)
|
60
|
-
expect(notifications.first.payload[:exception_object].message).to eq('Failing')
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def notifications
|
66
|
-
@notifications ||= []
|
67
|
-
end
|
68
|
-
end
|
data/spec/fleiss_spec.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Fleiss do
|
4
|
-
it 'has a backend' do
|
5
|
-
expect(described_class.backend).to eq(Fleiss::Backend::ActiveRecord)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'enqueues' do
|
9
|
-
expect do
|
10
|
-
TestJob.set(wait: 1.week).perform_later
|
11
|
-
end.to change { described_class.backend.count }.by(1)
|
12
|
-
end
|
13
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
ENV['RACK_ENV'] ||= 'test'
|
2
|
-
|
3
|
-
require 'rspec'
|
4
|
-
require 'fleiss'
|
5
|
-
require 'fleiss/backend/active_record/migration'
|
6
|
-
require 'active_job'
|
7
|
-
require 'active_job/queue_adapters/fleiss_adapter'
|
8
|
-
require 'fileutils'
|
9
|
-
|
10
|
-
ActiveJob::Base.queue_adapter = :fleiss
|
11
|
-
ActiveJob::Base.logger = Logger.new(nil)
|
12
|
-
|
13
|
-
Time.zone_default = Time.find_zone!('UTC')
|
14
|
-
|
15
|
-
tmpdir = File.expand_path('./tmp', __dir__)
|
16
|
-
FileUtils.rm_rf tmpdir
|
17
|
-
FileUtils.mkdir_p tmpdir
|
18
|
-
|
19
|
-
database_url = ENV['DATABASE_URL'] || "sqlite3://#{tmpdir}/fleiss-test.sqlite3"
|
20
|
-
ActiveRecord::Base.configurations = { 'test' => { 'url' => database_url, 'pool' => 20 } }
|
21
|
-
|
22
|
-
ActiveRecord::Base.establish_connection :test
|
23
|
-
ActiveRecord::Base.connection.drop_table('fleiss_jobs', if_exists: true)
|
24
|
-
ActiveRecord::Migration.suppress_messages do
|
25
|
-
Fleiss::Backend::ActiveRecord::Migration.migrate(:up)
|
26
|
-
end
|
27
|
-
|
28
|
-
class TestJob < ActiveJob::Base
|
29
|
-
queue_as 'test-queue'
|
30
|
-
|
31
|
-
def self.performed
|
32
|
-
@performed ||= []
|
33
|
-
end
|
34
|
-
|
35
|
-
def ttl
|
36
|
-
72.hours
|
37
|
-
end
|
38
|
-
|
39
|
-
def perform(msg = nil)
|
40
|
-
raise 'Failing' if msg == 'raise'
|
41
|
-
|
42
|
-
self.class.performed.push(msg)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
RSpec.configure do |c|
|
47
|
-
c.after do
|
48
|
-
TestJob.performed.clear
|
49
|
-
Fleiss.backend.delete_all
|
50
|
-
end
|
51
|
-
end
|