inst-jobs 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/{inst_job → inst_jobs} +0 -0
- data/lib/delayed/lifecycle.rb +1 -1
- data/lib/delayed/settings.rb +1 -1
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/work_queue/in_process.rb +7 -3
- data/lib/delayed/work_queue/parent_process.rb +10 -6
- data/lib/delayed/worker.rb +4 -4
- data/lib/delayed/yaml_extensions.rb +1 -1
- data/spec/delayed/work_queue/in_process_spec.rb +5 -2
- data/spec/delayed/work_queue/parent_process_spec.rb +7 -6
- data/spec/delayed/worker_spec.rb +14 -2
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdcb9f78f236ad4d8c70bc96f61d50b9a1df60f1
|
4
|
+
data.tar.gz: c931fcff9a08ea2022b3984a210bf46fbe6fcea6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d235844cce086cab4981aa6434c1300a482582a65570245f575405ec12079c24aa0178aa411e0a7628fbd4950bb8cea22d7b2543622e21746058d529da69433f
|
7
|
+
data.tar.gz: 476c8716bc4b1328bd502d1e7acc37fea629e468da21582d09ee62b7556fcfee506de88a6d50dfbe761638c86dc90e6869f550d755519c6c5eeb41342359ad24
|
data/bin/{inst_job → inst_jobs}
RENAMED
File without changes
|
data/lib/delayed/lifecycle.rb
CHANGED
data/lib/delayed/settings.rb
CHANGED
data/lib/delayed/version.rb
CHANGED
@@ -3,9 +3,13 @@ module WorkQueue
|
|
3
3
|
# The simplest possible implementation of a WorkQueue -- just turns around and
|
4
4
|
# queries the queue inline.
|
5
5
|
class InProcess
|
6
|
-
def get_and_lock_next_available(worker_name,
|
7
|
-
Delayed::Worker.lifecycle.run_callbacks(:work_queue_pop, self) do
|
8
|
-
Delayed::Job.get_and_lock_next_available(
|
6
|
+
def get_and_lock_next_available(worker_name, worker_config)
|
7
|
+
Delayed::Worker.lifecycle.run_callbacks(:work_queue_pop, self, worker_name, worker_config) do
|
8
|
+
Delayed::Job.get_and_lock_next_available(
|
9
|
+
worker_name,
|
10
|
+
worker_config[:queue],
|
11
|
+
worker_config[:min_priority],
|
12
|
+
worker_config[:max_priority])
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -58,11 +58,11 @@ class ParentProcess
|
|
58
58
|
@addrinfo = addrinfo
|
59
59
|
end
|
60
60
|
|
61
|
-
def get_and_lock_next_available(
|
61
|
+
def get_and_lock_next_available(worker_name, worker_config)
|
62
62
|
@socket ||= @addrinfo.connect
|
63
|
-
Marshal.dump([
|
63
|
+
Marshal.dump([worker_name, worker_config], @socket)
|
64
64
|
response = Marshal.load(@socket)
|
65
|
-
unless response.nil? || (response.is_a?(Delayed::Job) && response.locked_by ==
|
65
|
+
unless response.nil? || (response.is_a?(Delayed::Job) && response.locked_by == worker_name)
|
66
66
|
raise(ProtocolError, "response is not a locked job: #{response.inspect}")
|
67
67
|
end
|
68
68
|
response
|
@@ -145,10 +145,14 @@ class ParentProcess
|
|
145
145
|
# request and then leave the socket open. Doing so would leave us hanging
|
146
146
|
# here forever. This is only a reasonable assumption because we control
|
147
147
|
# the client.
|
148
|
-
|
148
|
+
worker_name, worker_config = client_timeout { Marshal.load(socket) }
|
149
149
|
response = nil
|
150
|
-
Delayed::Worker.lifecycle.run_callbacks(:work_queue_pop, self) do
|
151
|
-
response = Delayed::Job.get_and_lock_next_available(
|
150
|
+
Delayed::Worker.lifecycle.run_callbacks(:work_queue_pop, self, worker_name, worker_config) do
|
151
|
+
response = Delayed::Job.get_and_lock_next_available(
|
152
|
+
worker_name,
|
153
|
+
worker_config[:queue],
|
154
|
+
worker_config[:min_priority],
|
155
|
+
worker_config[:max_priority])
|
152
156
|
@clients[socket].working = !response.nil?
|
153
157
|
end
|
154
158
|
client_timeout { Marshal.dump(response, socket) }
|
data/lib/delayed/worker.rb
CHANGED
@@ -30,14 +30,14 @@ class Worker
|
|
30
30
|
|
31
31
|
def initialize(options = {})
|
32
32
|
@exit = false
|
33
|
-
@config = options
|
34
33
|
@parent_pid = options[:parent_pid]
|
35
|
-
@queue_name = options[:queue]
|
34
|
+
@queue_name = options[:queue] ||= Settings.queue
|
36
35
|
@min_priority = options[:min_priority]
|
37
36
|
@max_priority = options[:max_priority]
|
38
37
|
@max_job_count = options[:worker_max_job_count].to_i
|
39
38
|
@max_memory_usage = options[:worker_max_memory_usage].to_i
|
40
|
-
@work_queue = options
|
39
|
+
@work_queue = options.delete(:work_queue) || WorkQueue::InProcess.new
|
40
|
+
@config = options
|
41
41
|
@job_count = 0
|
42
42
|
|
43
43
|
app = Rails.application
|
@@ -95,7 +95,7 @@ class Worker
|
|
95
95
|
def run
|
96
96
|
self.class.lifecycle.run_callbacks(:loop, self) do
|
97
97
|
job = self.class.lifecycle.run_callbacks(:pop, self) do
|
98
|
-
work_queue.get_and_lock_next_available(name,
|
98
|
+
work_queue.get_and_lock_next_available(name, config)
|
99
99
|
end
|
100
100
|
|
101
101
|
if job
|
@@ -81,7 +81,7 @@ module Delayed
|
|
81
81
|
rescue ActiveRecord::RecordNotFound
|
82
82
|
raise Delayed::Backend::RecordNotFound, "Couldn't find #{klass} with id #{object.value.inspect}"
|
83
83
|
end
|
84
|
-
when "tag:ruby.yaml.org,2002:Delayed::Periodic", "!ruby/Delayed::Periodic"
|
84
|
+
when "tag:ruby.yaml.org,2002:Delayed::Periodic", "!ruby/Delayed::Periodic", "!ruby/object:Delayed::Periodic"
|
85
85
|
Delayed::Periodic.scheduled[object.value] || raise(NameError, "job #{object.value} is no longer scheduled")
|
86
86
|
else
|
87
87
|
super
|
@@ -14,13 +14,16 @@ RSpec.describe Delayed::WorkQueue::InProcess do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
let(:subject) { described_class.new }
|
17
|
-
let(:
|
17
|
+
let(:worker_config) { {queue: "test", min_priority: 1, max_priority: 2} }
|
18
|
+
let(:args) { ["worker_name", worker_config] }
|
18
19
|
|
19
20
|
it 'triggers the lifecycle event around the pop' do
|
20
21
|
called = false
|
21
22
|
Delayed::Worker.lifecycle.around(:work_queue_pop) do |queue, &cb|
|
22
23
|
expect(queue).to eq(subject)
|
23
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).
|
24
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).
|
25
|
+
with("worker_name", "test", 1, 2).
|
26
|
+
and_return(:job)
|
24
27
|
called = true
|
25
28
|
cb.call(queue)
|
26
29
|
end
|
@@ -14,6 +14,9 @@ RSpec.describe Delayed::WorkQueue::ParentProcess do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
let(:subject) { described_class.new }
|
17
|
+
let(:worker_config) { { queue: "queue_name", min_priority: 1, max_priority: 2 } }
|
18
|
+
let(:args) { ["worker_name", worker_config] }
|
19
|
+
let(:job_args) { ["worker_name", "queue_name", 1, 2] }
|
17
20
|
|
18
21
|
it 'generates a server listening on a valid unix socket' do
|
19
22
|
server = subject.server
|
@@ -34,7 +37,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess do
|
|
34
37
|
let(:subject) { described_class.new(addrinfo) }
|
35
38
|
let(:addrinfo) { double('Addrinfo') }
|
36
39
|
let(:connection) { double('Socket') }
|
37
|
-
let(:args) { ["worker_name", "queue_name", 1, 2] }
|
38
40
|
let(:job) { Delayed::Job.new(locked_by: "worker_name") }
|
39
41
|
|
40
42
|
it 'marshals the given arguments to the server and returns the response' do
|
@@ -77,7 +79,6 @@ RSpec.describe Delayed::WorkQueue::ParentProcess do
|
|
77
79
|
describe Delayed::WorkQueue::ParentProcess::Server do
|
78
80
|
let(:subject) { described_class.new(listen_socket) }
|
79
81
|
let(:listen_socket) { Socket.unix_server_socket(Delayed::WorkQueue::ParentProcess.generate_socket_path) }
|
80
|
-
let(:args) { [1,2,3] }
|
81
82
|
let(:job) { :a_job }
|
82
83
|
|
83
84
|
it 'accepts new clients' do
|
@@ -89,7 +90,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess do
|
|
89
90
|
client = Socket.unix(subject.listen_socket.local_address.unix_path)
|
90
91
|
subject.run_once
|
91
92
|
|
92
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*
|
93
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(job)
|
93
94
|
Marshal.dump(args, client)
|
94
95
|
subject.run_once
|
95
96
|
expect(Marshal.load(client)).to eq(job)
|
@@ -123,12 +124,12 @@ RSpec.describe Delayed::WorkQueue::ParentProcess do
|
|
123
124
|
subject.run_once
|
124
125
|
expect(subject.all_workers_idle?).to be(true)
|
125
126
|
|
126
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*
|
127
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(job)
|
127
128
|
Marshal.dump(args, client)
|
128
129
|
subject.run_once
|
129
130
|
expect(subject.all_workers_idle?).to be(false)
|
130
131
|
|
131
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*
|
132
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(nil)
|
132
133
|
Marshal.dump(args, client)
|
133
134
|
subject.run_once
|
134
135
|
expect(subject.all_workers_idle?).to be(true)
|
@@ -142,7 +143,7 @@ RSpec.describe Delayed::WorkQueue::ParentProcess do
|
|
142
143
|
Delayed::Worker.lifecycle.around(:work_queue_pop) do |queue, &cb|
|
143
144
|
expect(subject.all_workers_idle?).to be(true)
|
144
145
|
expect(queue).to eq(subject)
|
145
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*
|
146
|
+
expect(Delayed::Job).to receive(:get_and_lock_next_available).with(*job_args).and_return(job)
|
146
147
|
called = true
|
147
148
|
res = cb.call(queue)
|
148
149
|
expect(subject.all_workers_idle?).to be(false)
|
data/spec/delayed/worker_spec.rb
CHANGED
@@ -2,15 +2,27 @@ require_relative "../spec_helper"
|
|
2
2
|
|
3
3
|
module Delayed
|
4
4
|
describe Worker do
|
5
|
+
let(:worker_config) { {
|
6
|
+
queue: "test", min_priority: 1, max_priority: 2, stuff: "stuff",
|
7
|
+
}.freeze }
|
8
|
+
subject { described_class.new(worker_config.dup) }
|
9
|
+
|
5
10
|
describe "#perform" do
|
6
11
|
it "fires off an error callback when a job raises an exception" do
|
7
12
|
fired = false
|
8
13
|
Worker.lifecycle.before(:error) {|worker, exception| fired = true}
|
9
|
-
worker = Worker.new
|
10
14
|
job = double(:last_error= => nil, attempts: 1, reschedule: nil)
|
11
|
-
|
15
|
+
subject.perform(job)
|
12
16
|
expect(fired).to be_truthy
|
13
17
|
end
|
14
18
|
end
|
19
|
+
|
20
|
+
describe "#run" do
|
21
|
+
it "passes extra config options through to the WorkQueue" do
|
22
|
+
expect(subject.work_queue).to receive(:get_and_lock_next_available).
|
23
|
+
with(subject.name, worker_config).and_return(nil)
|
24
|
+
subject.run
|
25
|
+
end
|
26
|
+
end
|
15
27
|
end
|
16
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Luetke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: after_transaction_commit
|
@@ -253,11 +253,11 @@ description:
|
|
253
253
|
email:
|
254
254
|
- brianp@instructure.com
|
255
255
|
executables:
|
256
|
-
-
|
256
|
+
- inst_jobs
|
257
257
|
extensions: []
|
258
258
|
extra_rdoc_files: []
|
259
259
|
files:
|
260
|
-
- bin/
|
260
|
+
- bin/inst_jobs
|
261
261
|
- db/migrate/20101216224513_create_delayed_jobs.rb
|
262
262
|
- db/migrate/20110208031356_add_delayed_jobs_tag.rb
|
263
263
|
- db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb
|
@@ -341,7 +341,7 @@ files:
|
|
341
341
|
- spec/shared/worker.rb
|
342
342
|
- spec/shared_jobs_specs.rb
|
343
343
|
- spec/spec_helper.rb
|
344
|
-
homepage:
|
344
|
+
homepage: https://github.com/instructure/inst-jobs
|
345
345
|
licenses: []
|
346
346
|
metadata: {}
|
347
347
|
post_install_message:
|
@@ -360,7 +360,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
360
360
|
version: '0'
|
361
361
|
requirements: []
|
362
362
|
rubyforge_project:
|
363
|
-
rubygems_version: 2.
|
363
|
+
rubygems_version: 2.4.7
|
364
364
|
signing_key:
|
365
365
|
specification_version: 4
|
366
366
|
summary: Instructure-maintained fork of delayed_job
|
@@ -388,3 +388,4 @@ test_files:
|
|
388
388
|
- spec/shared/worker.rb
|
389
389
|
- spec/shared_jobs_specs.rb
|
390
390
|
- spec/spec_helper.rb
|
391
|
+
has_rdoc:
|