chore-core 1.8.4 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chore/queues/filesystem/consumer.rb +1 -1
- data/lib/chore/queues/filesystem/publisher.rb +4 -4
- data/lib/chore/version.rb +2 -2
- data/lib/chore/worker.rb +2 -0
- data/spec/chore/strategies/worker/forked_worker_strategy_spec.rb +11 -1
- data/spec/chore/worker_spec.rb +14 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0800ed952e9c16ccde3058ff9db8a4b9a72adf44
|
4
|
+
data.tar.gz: b24b312e93158e7942ae11896d9680f9f8a7714d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86f131b78103e360f0219b7b55a53da68338e676791dedcea638130e38e132665a4d33cf2bd0f90e78957184dd8b9d19ea88b7801866097b276d113debb654bd
|
7
|
+
data.tar.gz: 5f32aa7d1db7aab0579b1bfb43c31497502f76964e71e4d9faf0d6c1230be157901694602cb8a76f82e6c7627d2a74337e82f377a71652f03cbd18f1dfd4b23f
|
@@ -16,6 +16,9 @@ module Chore
|
|
16
16
|
# use of mutex and file locking should make this both threadsafe and safe for multiple
|
17
17
|
# processes to use the same queue directory simultaneously.
|
18
18
|
def publish(queue_name,job)
|
19
|
+
# First try encoding the job to avoid writing empty job files if this fails
|
20
|
+
encoded_job = encode_job(job)
|
21
|
+
|
19
22
|
FILE_MUTEX.synchronize do
|
20
23
|
while true
|
21
24
|
# keep trying to get a file with nothing in it meaning we just created it
|
@@ -23,10 +26,7 @@ module Chore
|
|
23
26
|
f = File.open(filename(queue_name, job[:class].to_s), "w")
|
24
27
|
if f.flock(File::LOCK_EX | File::LOCK_NB) && f.size == 0
|
25
28
|
begin
|
26
|
-
f.write(
|
27
|
-
rescue StandardError => e
|
28
|
-
Chore.logger.error "#{e.class.name}: #{e.message}. Could not write #{job[:class]} job to '#{queue_name}' queue file."
|
29
|
-
Chore.logger.error e.backtrace.join("\n")
|
29
|
+
f.write(encoded_job)
|
30
30
|
ensure
|
31
31
|
f.flock(File::LOCK_UN)
|
32
32
|
end
|
data/lib/chore/version.rb
CHANGED
data/lib/chore/worker.rb
CHANGED
@@ -66,6 +66,7 @@ module Chore
|
|
66
66
|
item.consumer.complete(item.id)
|
67
67
|
else
|
68
68
|
Chore.run_hooks_for(:on_failure,item.message,e)
|
69
|
+
item.consumer.reject(item.id)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
@@ -116,6 +117,7 @@ module Chore
|
|
116
117
|
item.consumer.complete(item.id)
|
117
118
|
else
|
118
119
|
klass.run_hooks_for(:on_failure, message, e)
|
120
|
+
item.consumer.reject(item.id)
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
@@ -8,8 +8,18 @@ describe Chore::Strategy::ForkedWorkerStrategy do
|
|
8
8
|
allow(strategy).to receive(:exit!)
|
9
9
|
strategy
|
10
10
|
end
|
11
|
+
let(:consumer) { double('consumer', :complete => nil, :reject => nil) }
|
11
12
|
let(:job_timeout) { 60 }
|
12
|
-
let(:job)
|
13
|
+
let(:job) do
|
14
|
+
Chore::UnitOfWork.new(
|
15
|
+
SecureRandom.uuid,
|
16
|
+
'test',
|
17
|
+
job_timeout,
|
18
|
+
Chore::Encoder::JsonEncoder.encode(TestJob.job_hash([1,2,"3"])),
|
19
|
+
0,
|
20
|
+
consumer
|
21
|
+
)
|
22
|
+
end
|
13
23
|
let!(:worker) { Chore::Worker.new(job) }
|
14
24
|
let(:pid) { Random.rand(2048) }
|
15
25
|
|
data/spec/chore/worker_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe Chore::Worker do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
let(:consumer) { double('consumer', :complete => nil) }
|
16
|
+
let(:consumer) { double('consumer', :complete => nil, :reject => nil) }
|
17
17
|
let(:job_args) { [1,2,'3'] }
|
18
18
|
let(:job) { SimpleJob.job_hash(job_args) }
|
19
19
|
|
@@ -91,6 +91,12 @@ describe Chore::Worker do
|
|
91
91
|
Chore::Worker.start(work)
|
92
92
|
end
|
93
93
|
|
94
|
+
it 'should reject job' do
|
95
|
+
work = Chore::UnitOfWork.new(2,'test',60,job,0,consumer)
|
96
|
+
consumer.should_receive(:reject).with(2)
|
97
|
+
Chore::Worker.start(work)
|
98
|
+
end
|
99
|
+
|
94
100
|
context 'more than the maximum allowed times' do
|
95
101
|
before(:each) do
|
96
102
|
Chore.config.stub(:max_attempts).and_return(10)
|
@@ -127,6 +133,13 @@ describe Chore::Worker do
|
|
127
133
|
Chore::Worker.start(work)
|
128
134
|
end
|
129
135
|
|
136
|
+
it 'should reject job' do
|
137
|
+
work = Chore::UnitOfWork.new(2,'test',60,encoded_job,0,consumer)
|
138
|
+
consumer.should_receive(:reject).with(2)
|
139
|
+
|
140
|
+
Chore::Worker.start(work)
|
141
|
+
end
|
142
|
+
|
130
143
|
context 'more than the maximum allowed times' do
|
131
144
|
it 'should permanently fail' do
|
132
145
|
work = Chore::UnitOfWork.new(2,'test',60,encoded_job,999,consumer)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chore-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tapjoy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -186,9 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.4.
|
189
|
+
rubygems_version: 2.4.8
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Job processing... for the future!
|
193
193
|
test_files: []
|
194
|
-
has_rdoc:
|