rocketjob 1.1.1 → 1.1.2
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/lib/rocket_job/dirmon_entry.rb +2 -2
- data/lib/rocket_job/version.rb +1 -1
- data/lib/rocket_job/worker.rb +6 -2
- data/test/dirmon_entry_test.rb +20 -0
- data/test/worker_test.rb +54 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75e6c5434b4b1968db94743e4b81fcc0a68cabc3
|
4
|
+
data.tar.gz: 735b0996986532d05ee46c546df4033a2b0d3c95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0556e6e99fa676eaa9eea871b5c32ffa372794ad5358a16f1daa11f28e0739bfc7954760d00a1d1d358ad135dfcf88e08823cdd22957fc41a5fbeb47b71fd0bd
|
7
|
+
data.tar.gz: f780fa752304a93234e9dee155ab47a1949011c20d4a7cd2a949b068e0c65e195296a6edf7469d95af695d9c83d2f8041bcc3d53964fe2e71814d2a28dafeb5c
|
@@ -129,7 +129,7 @@ module RocketJob
|
|
129
129
|
validates_presence_of :pattern, :job_class_name, :perform_method
|
130
130
|
|
131
131
|
validates_each :perform_method do |record, attr, value|
|
132
|
-
if (klass = record.job_class) && !klass.
|
132
|
+
if (klass = record.job_class) && !klass.instance_methods.include?(value)
|
133
133
|
record.errors.add(attr, "Method not implemented by #{record.job_class_name}")
|
134
134
|
end
|
135
135
|
end
|
@@ -145,7 +145,7 @@ module RocketJob
|
|
145
145
|
end
|
146
146
|
|
147
147
|
validates_each :arguments do |record, attr, value|
|
148
|
-
if (klass = record.job_class)
|
148
|
+
if (klass = record.job_class) && klass.instance_methods.include?(record.perform_method)
|
149
149
|
count = klass.argument_count(record.perform_method)
|
150
150
|
record.errors.add(attr, "There must be #{count} argument(s)") if value.size != count
|
151
151
|
end
|
data/lib/rocket_job/version.rb
CHANGED
data/lib/rocket_job/worker.rb
CHANGED
@@ -117,11 +117,14 @@ module RocketJob
|
|
117
117
|
# Destroy's all instances of zombie workers and requeues any jobs still "running"
|
118
118
|
# on those workers
|
119
119
|
def self.destroy_zombies
|
120
|
+
count = 0
|
120
121
|
each do |worker|
|
121
|
-
next unless zombie?
|
122
|
+
next unless worker.zombie?
|
122
123
|
logger.warn "Destroying zombie worker #{worker.name}, and requeueing its jobs"
|
123
124
|
worker.destroy
|
125
|
+
count += 1
|
124
126
|
end
|
127
|
+
count
|
125
128
|
end
|
126
129
|
|
127
130
|
def self.destroy_dead_workers
|
@@ -220,8 +223,9 @@ module RocketJob
|
|
220
223
|
# - The worker process is "hanging"
|
221
224
|
# - The worker is no longer able to communicate with the MongoDB Server
|
222
225
|
def zombie?(missed = 4)
|
226
|
+
return false unless running?
|
223
227
|
dead_seconds = Config.instance.heartbeat_seconds * missed
|
224
|
-
(Time.now -
|
228
|
+
(Time.now - heartbeat.updated_at) >= dead_seconds
|
225
229
|
end
|
226
230
|
|
227
231
|
protected
|
data/test/dirmon_entry_test.rb
CHANGED
@@ -97,6 +97,16 @@ class DirmonEntryTest < Minitest::Test
|
|
97
97
|
assert_equal ["can't be blank"], entry.errors[:pattern], entry.errors.inspect
|
98
98
|
end
|
99
99
|
|
100
|
+
context 'perform_method' do
|
101
|
+
context 'with an invalid method' do
|
102
|
+
should 'add errors to the entry' do
|
103
|
+
entry = RocketJob::DirmonEntry.new(job_class_name: 'Jobs::TestJob', perform_method: :missing_perform_method)
|
104
|
+
assert_equal false, entry.valid?
|
105
|
+
assert_equal ['Method not implemented by Jobs::TestJob'], entry.errors[:perform_method], entry.errors.inspect
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
100
110
|
context 'job_class_name' do
|
101
111
|
should 'ensure presence' do
|
102
112
|
assert entry = RocketJob::DirmonEntry.new(pattern: '/abc/**')
|
@@ -106,6 +116,16 @@ class DirmonEntryTest < Minitest::Test
|
|
106
116
|
end
|
107
117
|
|
108
118
|
context 'arguments' do
|
119
|
+
should 'allow no arguments' do
|
120
|
+
assert entry = RocketJob::DirmonEntry.new(
|
121
|
+
job_class_name: 'Jobs::TestJob',
|
122
|
+
pattern: '/abc/**',
|
123
|
+
perform_method: :result
|
124
|
+
)
|
125
|
+
assert_equal true, entry.valid?, entry.errors.inspect
|
126
|
+
assert_equal [], entry.errors[:arguments], entry.errors.inspect
|
127
|
+
end
|
128
|
+
|
109
129
|
should 'ensure correct number of arguments' do
|
110
130
|
assert entry = RocketJob::DirmonEntry.new(
|
111
131
|
job_class_name: 'Jobs::TestJob',
|
data/test/worker_test.rb
CHANGED
@@ -20,6 +20,7 @@ class WorkerTest < Minitest::Test
|
|
20
20
|
|
21
21
|
teardown do
|
22
22
|
@job.destroy if @job && !@job.new_record?
|
23
|
+
@worker.destroy if @worker && !@worker.new_record?
|
23
24
|
end
|
24
25
|
|
25
26
|
context '.config' do
|
@@ -39,5 +40,58 @@ class WorkerTest < Minitest::Test
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
43
|
+
context '#zombie?' do
|
44
|
+
setup do
|
45
|
+
RocketJob::Config.instance.heartbeat_seconds = 1
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'when not a zombie' do
|
49
|
+
@worker.build_heartbeat(
|
50
|
+
updated_at: 2.seconds.ago,
|
51
|
+
current_threads: 3
|
52
|
+
)
|
53
|
+
@worker.started!
|
54
|
+
assert_equal false, @worker.zombie?
|
55
|
+
assert_equal false, @worker.zombie?(4)
|
56
|
+
assert_equal true, @worker.zombie?(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
should 'when a zombie' do
|
60
|
+
@worker.build_heartbeat(
|
61
|
+
updated_at: 1.hour.ago,
|
62
|
+
current_threads: 5
|
63
|
+
)
|
64
|
+
@worker.started!
|
65
|
+
assert_equal true, @worker.zombie?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context '.destroy_zombies' do
|
70
|
+
setup do
|
71
|
+
RocketJob::Config.instance.heartbeat_seconds = 1
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'when not a zombie' do
|
75
|
+
@worker.build_heartbeat(
|
76
|
+
updated_at: 2.seconds.ago,
|
77
|
+
current_threads: 3
|
78
|
+
)
|
79
|
+
@worker.started!
|
80
|
+
assert_equal 0, RocketJob::Worker.destroy_zombies
|
81
|
+
assert_equal true, RocketJob::Worker.where(id: @worker.id).exist?
|
82
|
+
end
|
83
|
+
|
84
|
+
should 'when a zombie' do
|
85
|
+
@worker.build_heartbeat(
|
86
|
+
updated_at: 10.seconds.ago,
|
87
|
+
current_threads: 3
|
88
|
+
)
|
89
|
+
@worker.started!
|
90
|
+
assert_equal 1, RocketJob::Worker.destroy_zombies
|
91
|
+
assert_equal false, RocketJob::Worker.where(id: @worker.id).exist?
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
42
96
|
end
|
43
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketjob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aasm
|