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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09ab52748f634684d65e8eb548ba12cf3a8020e5
4
- data.tar.gz: d09aba8b0de7b845e4adb3fc503c277af494e174
3
+ metadata.gz: 0800ed952e9c16ccde3058ff9db8a4b9a72adf44
4
+ data.tar.gz: b24b312e93158e7942ae11896d9680f9f8a7714d
5
5
  SHA512:
6
- metadata.gz: 050d7fdf8d36d4a2effe4808690bd28b399b9f1634c24aef19fec0b7971804fa587cda8bbdc3d92b97ecec421d87659ceaead9c860954979c26369b8d00a609c
7
- data.tar.gz: d046c3fc0a634074dbfff548a5b9dc69e95d330a35259be6552414447459bdeb10d0b0bef1de348f70f7c5e5641d6a447d92094f1fda0108861f58c4f76f83a4
6
+ metadata.gz: 86f131b78103e360f0219b7b55a53da68338e676791dedcea638130e38e132665a4d33cf2bd0f90e78957184dd8b9d19ea88b7801866097b276d113debb654bd
7
+ data.tar.gz: 5f32aa7d1db7aab0579b1bfb43c31497502f76964e71e4d9faf0d6c1230be157901694602cb8a76f82e6c7627d2a74337e82f377a71652f03cbd18f1dfd4b23f
@@ -108,7 +108,7 @@ module Chore
108
108
 
109
109
  def complete(id)
110
110
  Chore.logger.debug "Completing (deleting): #{id}"
111
- FileUtils.rm(File.join(@in_progress_dir, id))
111
+ FileUtils.rm_f(File.join(@in_progress_dir, id))
112
112
  end
113
113
 
114
114
  private
@@ -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(job.to_json)
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
@@ -1,8 +1,8 @@
1
1
  module Chore
2
2
  module Version #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 8
5
- PATCH = 4
4
+ MINOR = 9
5
+ PATCH = 0
6
6
 
7
7
  STRING = [ MAJOR, MINOR, PATCH ].join('.')
8
8
  end
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) { Chore::UnitOfWork.new(SecureRandom.uuid, 'test', job_timeout, Chore::Encoder::JsonEncoder.encode(TestJob.job_hash([1,2,"3"])), 0) }
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
 
@@ -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.8.4
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-02-02 00:00:00.000000000 Z
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.5
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: