delayed_job_heartbeat_plugin 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cef7ae61852d4de36ca9f5cc1059a576dea01abe
|
4
|
+
data.tar.gz: 5f3d3eea13aff2b10d4deddfb2e366c45e0ded48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 114f547ef885c5cf30fbc00b0402c0aed425439620549ffdadd96db5443390ec8abd881d686405ed5e2107260ae1a57e9dfb6673a31dcd721122dddb565ec3c8
|
7
|
+
data.tar.gz: 695f793b5732247503f4795057ee59ec0df1ac68d5fd24ebd8206b504e8d37c74d2a1a0ebc566ffdcbcabddb195c82ea1cf53277b9826b172b42ea8ee7ff1175
|
data/CHANGELOG.md
ADDED
data/lib/delayed/heartbeat.rb
CHANGED
@@ -34,11 +34,11 @@ module Delayed
|
|
34
34
|
|
35
35
|
def cleanup_workers(workers, mark_attempt_failed: true)
|
36
36
|
Delayed::Heartbeat::Worker.transaction do
|
37
|
-
|
38
|
-
worker.unlock_jobs(mark_attempt_failed: mark_attempt_failed)
|
37
|
+
worker_job_map = workers.each_with_object(Hash.new) do |worker, worker_job_map|
|
38
|
+
worker_job_map[worker] = worker.unlock_jobs(mark_attempt_failed: mark_attempt_failed)
|
39
39
|
end
|
40
40
|
Delayed::Heartbeat::Worker.delete_workers(workers)
|
41
|
-
Delayed::Heartbeat::DeleteWorkerResults.new(
|
41
|
+
Delayed::Heartbeat::DeleteWorkerResults.new(worker_job_map)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -1,42 +1,32 @@
|
|
1
1
|
module Delayed
|
2
2
|
module Heartbeat
|
3
3
|
class DeleteWorkerResults
|
4
|
-
|
4
|
+
def initialize(worker_job_map)
|
5
|
+
@worker_job_map = worker_job_map
|
6
|
+
end
|
7
|
+
|
8
|
+
def workers
|
9
|
+
@worker_job_map.keys
|
10
|
+
end
|
5
11
|
|
6
|
-
def
|
7
|
-
@
|
8
|
-
@unlocked_jobs = unlocked_jobs
|
12
|
+
def unlocked_jobs(worker = nil)
|
13
|
+
worker ? @worker_job_map.fetch(worker, []) : @worker_job_map.values.flatten
|
9
14
|
end
|
10
15
|
|
11
16
|
def empty?
|
12
|
-
|
17
|
+
@worker_job_map.empty?
|
13
18
|
end
|
14
19
|
|
15
20
|
def to_s
|
16
21
|
io = StringIO.new
|
17
22
|
workers.each do |worker|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
worker_string = worker ? worker_description(worker) : unlocked_job.locked_by
|
24
|
-
io.puts("Unlocked orphaned job #{unlocked_job.id} from worker #{worker_string}")
|
25
|
-
end
|
26
|
-
|
27
|
-
io.string
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def worker_map
|
33
|
-
@worker_map ||= workers.each_with_object(Hash.new) do |worker, worker_map|
|
34
|
-
worker_map[worker.name] = worker
|
23
|
+
worker_description = "#{worker.label}(#{worker.name})"
|
24
|
+
io.puts("Deleted worker #{worker_description}")
|
25
|
+
unlocked_jobs(worker).each do |unlocked_job|
|
26
|
+
io.puts("Unlocked orphaned job #{unlocked_job.id} from worker #{worker_description}")
|
27
|
+
end
|
35
28
|
end
|
36
|
-
|
37
|
-
|
38
|
-
def worker_description(worker)
|
39
|
-
"#{worker.label}(#{worker.name})"
|
29
|
+
io.string.rstrip
|
40
30
|
end
|
41
31
|
end
|
42
32
|
end
|
@@ -3,32 +3,29 @@ require 'spec_helper'
|
|
3
3
|
describe Delayed::Heartbeat::DeleteWorkerResults do
|
4
4
|
let(:worker) { create_worker(name: 'my-worker') }
|
5
5
|
let(:job) { create_job(locked_by: worker.name) }
|
6
|
-
let(:results) { create_results(
|
6
|
+
let(:results) { create_results(worker => [job]) }
|
7
7
|
|
8
8
|
describe "#workers" do
|
9
9
|
specify { expect(results.workers).to eq [worker] }
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#unlocked_jobs" do
|
13
|
-
|
13
|
+
let(:other_worker) { create_worker(name: 'my-other-worker') }
|
14
|
+
let(:other_job) { create_job(locked_by: worker.name) }
|
15
|
+
let(:results) { create_results(worker => [job], other_worker => [other_job]) }
|
16
|
+
|
17
|
+
specify { expect(results.unlocked_jobs(worker)).to eq [job] }
|
18
|
+
specify { expect(results.unlocked_jobs).to match_array [job, other_job] }
|
14
19
|
end
|
15
20
|
|
16
21
|
describe "#to_s" do
|
17
22
|
it "includes workers" do
|
18
|
-
results = create_results(
|
23
|
+
results = create_results(worker => [])
|
19
24
|
expect(results.to_s).to include(worker.name)
|
20
25
|
end
|
21
26
|
|
22
|
-
it "includes jobs for
|
23
|
-
results = create_results([worker], [job])
|
24
|
-
expect(results.to_s).to include(job.id.to_s)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "includes jobs locked by an unknown worker" do
|
28
|
-
job = create_job(locked_by: 'unknown-worker')
|
29
|
-
results = create_results([], [job])
|
27
|
+
it "includes jobs for workers" do
|
30
28
|
expect(results.to_s).to include(job.id.to_s)
|
31
|
-
expect(results.to_s).to include(job.locked_by)
|
32
29
|
end
|
33
30
|
end
|
34
31
|
|
@@ -41,7 +38,7 @@ describe Delayed::Heartbeat::DeleteWorkerResults do
|
|
41
38
|
Delayed::Job.create!(attributes)
|
42
39
|
end
|
43
40
|
|
44
|
-
def create_results(
|
45
|
-
Delayed::Heartbeat::DeleteWorkerResults.new(
|
41
|
+
def create_results(worker_job_map)
|
42
|
+
Delayed::Heartbeat::DeleteWorkerResults.new(worker_job_map)
|
46
43
|
end
|
47
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_job_heartbeat_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Turkel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: delayed_job
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- .gitignore
|
167
167
|
- .rspec
|
168
168
|
- .travis.yml
|
169
|
+
- CHANGELOG.md
|
169
170
|
- Gemfile
|
170
171
|
- LICENSE.txt
|
171
172
|
- README.md
|