workhorse 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +10 -1
- data/FAQ.md +4 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/workhorse/daemon.rb +2 -0
- data/lib/workhorse/db_job.rb +4 -0
- data/lib/workhorse/poller.rb +3 -2
- data/lib/workhorse/worker.rb +1 -0
- data/test/workhorse/poller_test.rb +37 -0
- data/test/workhorse/worker_test.rb +11 -0
- data/workhorse.gemspec +7 -7
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6cda82b0f03df2130e38841bff942ab7f3d559a1c6233121c6060a7c06d50d0
|
4
|
+
data.tar.gz: 64b0c6ba8e659ff3dcc4009b5c13ba91139e7f82a6043f42c0d3eed6c0368107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0998ffd89b16233c8fa97fa00b8db4de490f9dccdebc7a6002a5d44a0ac859a050a41e339c545f6ec5ebfaa9888671b693cf389a779975c214b54cd9328385d4'
|
7
|
+
data.tar.gz: 9b2d2d1fc6e3d2667286c9a5f48a247596612a9b0162b4cc202b536f43745a55894d35f45e2efd5badf431cbaea0a47f9108262d1d24252bf4410222d7eb58e5
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# Workhorse Change log
|
2
2
|
|
3
|
-
## 0.3.
|
3
|
+
## 0.3.4 - 2018-09-24
|
4
|
+
|
5
|
+
* *Fixes #14
|
6
|
+
|
7
|
+
* Fixes crucial bug where multiple jobs of the same queue could be executed
|
8
|
+
simultaneously.
|
9
|
+
|
10
|
+
* Makes `Workhorse::DbJob` attributes accessible for earlier versions of rails.
|
11
|
+
|
12
|
+
## 0.3.3 - 2018-02-26
|
4
13
|
|
5
14
|
* Adds missing require for `concurrent` library that is required in some
|
6
15
|
versions of Rails
|
data/FAQ.md
CHANGED
@@ -75,3 +75,7 @@ production mode.
|
|
75
75
|
## Why does workhorse not support timeouts?
|
76
76
|
|
77
77
|
Generic timeout implementations are [a dangerous thing](http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/) in Ruby. This is why we decided against providing this feature in Workhorse and recommend to implement the timeouts inside of your jobs - i.e. via network timeouts.
|
78
|
+
|
79
|
+
## Why is workhorse not integrated into Rails per default?
|
80
|
+
|
81
|
+
We have submitted [a pull request](https://github.com/rails/rails/pull/31504) to Rails, but they stated that they won't add any new adapters to Rails. There are plans to integrate this on the Gem side only - stay tuned.
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ task :gemspec do
|
|
15
15
|
spec.add_development_dependency 'rake'
|
16
16
|
spec.add_development_dependency 'rubocop', '0.51.0'
|
17
17
|
spec.add_development_dependency 'minitest'
|
18
|
-
spec.add_development_dependency 'mysql2'
|
18
|
+
spec.add_development_dependency 'mysql2'
|
19
19
|
spec.add_development_dependency 'benchmark-ips'
|
20
20
|
spec.add_dependency 'activesupport'
|
21
21
|
spec.add_dependency 'activerecord'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/lib/workhorse/daemon.rb
CHANGED
@@ -8,6 +8,8 @@ module Workhorse
|
|
8
8
|
|
9
9
|
fail 'Count must be an integer > 0.' unless count.is_a?(Integer) && count > 0
|
10
10
|
|
11
|
+
FileUtils.mkdir_p('tmp/pids')
|
12
|
+
|
11
13
|
if @pidfile.nil?
|
12
14
|
@pidfile = count > 1 ? 'tmp/pids/workhorse.%i.pid' : 'tmp/pids/workhorse.pid'
|
13
15
|
elsif @count > 1 && !@pidfile.include?('%s')
|
data/lib/workhorse/db_job.rb
CHANGED
data/lib/workhorse/poller.rb
CHANGED
@@ -88,7 +88,7 @@ module Workhorse
|
|
88
88
|
# ---------------------------------------------------------------
|
89
89
|
# Select jobs to execute
|
90
90
|
# ---------------------------------------------------------------
|
91
|
-
|
91
|
+
|
92
92
|
# Construct selects for each queue which then are UNIONed for the final
|
93
93
|
# set. This is required because we only want the first job of each queue
|
94
94
|
# to be posted.
|
@@ -188,8 +188,9 @@ module Workhorse
|
|
188
188
|
select = valid_ordered_select
|
189
189
|
|
190
190
|
# Restrict queues that are currently in progress
|
191
|
+
bad_states = [Workhorse::DbJob::STATE_LOCKED, Workhorse::DbJob::STATE_STARTED]
|
191
192
|
bad_queries_select = table.project(table[:queue])
|
192
|
-
.where(table[:state].in(
|
193
|
+
.where(table[:state].in(bad_states))
|
193
194
|
# .distinct is not chainable in older Arel versions
|
194
195
|
bad_queries_select.distinct
|
195
196
|
select = select.where(table[:queue].not_in(bad_queries_select))
|
data/lib/workhorse/worker.rb
CHANGED
@@ -10,4 +10,41 @@ class Workhorse::PollerTest < WorkhorseTest
|
|
10
10
|
w.shutdown
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
def test_valid_queues
|
15
|
+
w = Workhorse::Worker.new(polling_interval: 60)
|
16
|
+
|
17
|
+
Workhorse.enqueue BasicJob.new(sleep_time: 2), queue: :q1
|
18
|
+
Workhorse.enqueue BasicJob.new(sleep_time: 2), queue: :q1
|
19
|
+
Workhorse.enqueue BasicJob.new(sleep_time: 2), queue: :q2
|
20
|
+
Workhorse.enqueue BasicJob.new(sleep_time: 2), queue: :q2
|
21
|
+
|
22
|
+
assert_equal %w[q1 q2], w.poller.send(:valid_queues)
|
23
|
+
|
24
|
+
first_job = Workhorse::DbJob.first
|
25
|
+
first_job.mark_locked!(42)
|
26
|
+
|
27
|
+
assert_equal %w[q2], w.poller.send(:valid_queues)
|
28
|
+
|
29
|
+
first_job.mark_started!
|
30
|
+
|
31
|
+
assert_equal %w[q2], w.poller.send(:valid_queues)
|
32
|
+
|
33
|
+
first_job.mark_succeeded!
|
34
|
+
|
35
|
+
assert_equal %w[q1 q2], w.poller.send(:valid_queues)
|
36
|
+
|
37
|
+
last_job = Workhorse::DbJob.last
|
38
|
+
last_job.mark_locked!(42)
|
39
|
+
|
40
|
+
assert_equal %w[q1], w.poller.send(:valid_queues)
|
41
|
+
|
42
|
+
begin
|
43
|
+
fail 'Some exception'
|
44
|
+
rescue => e
|
45
|
+
last_job.mark_failed!(e)
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_equal %w[q1 q2], w.poller.send(:valid_queues)
|
49
|
+
end
|
13
50
|
end
|
@@ -109,6 +109,17 @@ class Workhorse::WorkerTest < WorkhorseTest
|
|
109
109
|
assert_equal 'succeeded', jobs[2].state
|
110
110
|
end
|
111
111
|
|
112
|
+
def test_queue_not_parallel
|
113
|
+
Workhorse::DbJob.delete_all
|
114
|
+
Workhorse.enqueue BasicJob.new(sleep_time: 0.2), queue: :q1
|
115
|
+
Workhorse.enqueue BasicJob.new(sleep_time: 0.2), queue: :q1
|
116
|
+
|
117
|
+
work 0.2, polling_interval: 0.2
|
118
|
+
jobs = Workhorse::DbJob.all.to_a
|
119
|
+
assert_equal 'succeeded', jobs[0].state
|
120
|
+
assert_equal 'waiting', jobs[1].state
|
121
|
+
end
|
122
|
+
|
112
123
|
def test_multiple_queued_same_queue
|
113
124
|
# One queue
|
114
125
|
Workhorse.enqueue BasicJob.new(sleep_time: 0.2), queue: :q1
|
data/workhorse.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: workhorse 0.3.
|
2
|
+
# stub: workhorse 0.3.4 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "workhorse".freeze
|
6
|
-
s.version = "0.3.
|
6
|
+
s.version = "0.3.4"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Sitrox".freeze]
|
11
|
-
s.date = "2018-
|
11
|
+
s.date = "2018-09-24"
|
12
12
|
s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, "CHANGELOG.md".freeze, "FAQ.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/rubocop".freeze, "lib/generators/workhorse/install_generator.rb".freeze, "lib/generators/workhorse/templates/bin/workhorse.rb".freeze, "lib/generators/workhorse/templates/config/initializers/workhorse.rb".freeze, "lib/generators/workhorse/templates/create_table_jobs.rb".freeze, "lib/workhorse.rb".freeze, "lib/workhorse/daemon.rb".freeze, "lib/workhorse/daemon/shell_handler.rb".freeze, "lib/workhorse/db_job.rb".freeze, "lib/workhorse/enqueuer.rb".freeze, "lib/workhorse/jobs/cleanup_succeeded_jobs.rb".freeze, "lib/workhorse/jobs/run_rails_op.rb".freeze, "lib/workhorse/performer.rb".freeze, "lib/workhorse/poller.rb".freeze, "lib/workhorse/pool.rb".freeze, "lib/workhorse/worker.rb".freeze, "test/lib/db_schema.rb".freeze, "test/lib/jobs.rb".freeze, "test/lib/test_helper.rb".freeze, "test/workhorse/enqueuer_test.rb".freeze, "test/workhorse/performer_test.rb".freeze, "test/workhorse/poller_test.rb".freeze, "test/workhorse/pool_test.rb".freeze, "test/workhorse/worker_test.rb".freeze, "workhorse.gemspec".freeze]
|
13
|
-
s.rubygems_version = "2.
|
13
|
+
s.rubygems_version = "2.5.2.3".freeze
|
14
14
|
s.summary = "Multi-threaded job backend with database queuing for ruby.".freeze
|
15
15
|
s.test_files = ["test/lib/db_schema.rb".freeze, "test/lib/jobs.rb".freeze, "test/lib/test_helper.rb".freeze, "test/workhorse/enqueuer_test.rb".freeze, "test/workhorse/performer_test.rb".freeze, "test/workhorse/poller_test.rb".freeze, "test/workhorse/pool_test.rb".freeze, "test/workhorse/worker_test.rb".freeze]
|
16
16
|
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
23
23
|
s.add_development_dependency(%q<rubocop>.freeze, ["= 0.51.0"])
|
24
24
|
s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
|
25
|
-
s.add_development_dependency(%q<mysql2>.freeze, ["
|
25
|
+
s.add_development_dependency(%q<mysql2>.freeze, [">= 0"])
|
26
26
|
s.add_development_dependency(%q<benchmark-ips>.freeze, [">= 0"])
|
27
27
|
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 0"])
|
28
28
|
s.add_runtime_dependency(%q<activerecord>.freeze, [">= 0"])
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
34
34
|
s.add_dependency(%q<rubocop>.freeze, ["= 0.51.0"])
|
35
35
|
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
36
|
-
s.add_dependency(%q<mysql2>.freeze, ["
|
36
|
+
s.add_dependency(%q<mysql2>.freeze, [">= 0"])
|
37
37
|
s.add_dependency(%q<benchmark-ips>.freeze, [">= 0"])
|
38
38
|
s.add_dependency(%q<activesupport>.freeze, [">= 0"])
|
39
39
|
s.add_dependency(%q<activerecord>.freeze, [">= 0"])
|
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
|
|
45
45
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
46
46
|
s.add_dependency(%q<rubocop>.freeze, ["= 0.51.0"])
|
47
47
|
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
48
|
-
s.add_dependency(%q<mysql2>.freeze, ["
|
48
|
+
s.add_dependency(%q<mysql2>.freeze, [">= 0"])
|
49
49
|
s.add_dependency(%q<benchmark-ips>.freeze, [">= 0"])
|
50
50
|
s.add_dependency(%q<activesupport>.freeze, [">= 0"])
|
51
51
|
s.add_dependency(%q<activerecord>.freeze, [">= 0"])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workhorse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: mysql2
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: benchmark-ips
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
212
|
version: '0'
|
213
213
|
requirements: []
|
214
214
|
rubyforge_project:
|
215
|
-
rubygems_version: 2.6
|
215
|
+
rubygems_version: 2.7.6
|
216
216
|
signing_key:
|
217
217
|
specification_version: 4
|
218
218
|
summary: Multi-threaded job backend with database queuing for ruby.
|