tax_generator 0.5.1 → 0.5.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/Rakefile +1 -1
- data/lib/tax_generator/all.rb +1 -0
- data/lib/tax_generator/classes/processor.rb +72 -9
- data/lib/tax_generator/version.rb +1 -1
- data/spec/lib/tax_generator/classes/file_creator_spec.rb +1 -1
- 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: 18cb322618a66792931dece02a7ee66078c56f3d
|
4
|
+
data.tar.gz: f94a7f55687d90e2a40bb7fd3527afffa035bb4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26f93898da8b74174afd41bffd5308c7f9446766cce6166eb6c89001bf3fbb34f8620fd78ee14293cc5c64d6e8cc5d1ec4ae08f3348756c9075e5240436c20e5
|
7
|
+
data.tar.gz: 05e310ba1f4dec94e32be4923197dd7eb36d9f9fcc85a3779daa68eb5a150cf1a9b45429116e255d343674aaa20e829e98cd991e419e2a1faf6bf209af395cce
|
data/Rakefile
CHANGED
@@ -23,5 +23,5 @@ task default: [:all]
|
|
23
23
|
|
24
24
|
desc 'Test the plugin under all supported Rails versions.'
|
25
25
|
task :all do |_t|
|
26
|
-
exec('bundle exec rubocop . && bundle exec inch --pedantic && bundle exec yard stats --list-undoc && bundle exec rake spec')
|
26
|
+
exec('bundle exec rubocop -a . && bundle exec inch --pedantic && bundle exec yard stats --list-undoc && bundle exec rake spec')
|
27
27
|
end
|
data/lib/tax_generator/all.rb
CHANGED
@@ -46,6 +46,9 @@ module TaxGenerator
|
|
46
46
|
@worker_supervisor = Celluloid::SupervisionGroup.run!
|
47
47
|
@workers = @worker_supervisor.pool(TaxGenerator::FileCreator, as: :workers, size: 50)
|
48
48
|
Actor.current.link @workers
|
49
|
+
@jobs_mutex = Mutex.new
|
50
|
+
@job_to_worker_mutex = Mutex.new
|
51
|
+
@worker_to_job_mutex = Mutex.new
|
49
52
|
@jobs = {}
|
50
53
|
@job_to_worker = {}
|
51
54
|
@worker_to_job = {}
|
@@ -135,7 +138,9 @@ module TaxGenerator
|
|
135
138
|
#
|
136
139
|
# @api public
|
137
140
|
def all_workers_finished?
|
138
|
-
@
|
141
|
+
@jobs_mutex.synchronize do
|
142
|
+
@jobs.all? { |_job_id, job| job['status'] == 'finished' }
|
143
|
+
end
|
139
144
|
end
|
140
145
|
|
141
146
|
# registers all the jobs so that the managers can have access to them at any time
|
@@ -148,7 +153,9 @@ module TaxGenerator
|
|
148
153
|
def register_jobs(*jobs)
|
149
154
|
jobs.pmap do |job|
|
150
155
|
job = job.stringify_keys
|
151
|
-
@
|
156
|
+
@jobs_mutex.synchronize do
|
157
|
+
@jobs[job['atlas_id']] = job
|
158
|
+
end
|
152
159
|
end
|
153
160
|
end
|
154
161
|
|
@@ -165,8 +172,10 @@ module TaxGenerator
|
|
165
172
|
# jobs need to be added into the manager before starting task to avoid adding new key while iterating
|
166
173
|
register_jobs(*jobs)
|
167
174
|
current_actor = Actor.current
|
168
|
-
@
|
169
|
-
@
|
175
|
+
@jobs_mutex.synchronize do
|
176
|
+
@jobs.pmap do |_job_id, job|
|
177
|
+
@workers.async.work(job, current_actor) if @workers.alive?
|
178
|
+
end
|
170
179
|
end
|
171
180
|
end
|
172
181
|
|
@@ -216,8 +225,36 @@ module TaxGenerator
|
|
216
225
|
terminate
|
217
226
|
end
|
218
227
|
|
228
|
+
# registeres a worker inside the job_to_worker storage using the 'atlas_id' key from the job hash
|
229
|
+
# @param [TaxGenerator::FileCreator] worker the worker that needs to be registered
|
230
|
+
# @param [Hash] job the job that will be used to register the worker
|
231
|
+
#
|
232
|
+
# @return [void]
|
233
|
+
#
|
234
|
+
# @api public
|
235
|
+
def register_job_to_worker(job, worker)
|
236
|
+
@job_to_worker_mutex.synchronize do
|
237
|
+
@job_to_worker[job['atlas_id']] = worker
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# registeres a job to a worker, using the mailbox address of the worker (which is unique)
|
242
|
+
# @param [TaxGenerator::FileCreator] worker the worker that will be used to registerr the job
|
243
|
+
# @param [Hash] job the job that willbe registered to a worker
|
244
|
+
#
|
245
|
+
# @return [void]
|
246
|
+
#
|
247
|
+
# @api public
|
248
|
+
def register_worker_to_job(job, worker)
|
249
|
+
@worker_to_job_mutex.synchronize do
|
250
|
+
@worker_to_job[worker.mailbox.address] = job
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
219
254
|
# registers the worker so that the current actor has access to it at any given time and starts the worker
|
220
255
|
# @see TaxGenerator::FileCreator#start_work
|
256
|
+
# @see #register_job_to_worker
|
257
|
+
# @see #register_worker_to_job
|
221
258
|
#
|
222
259
|
# @param [Hash] job the job that the worker will work
|
223
260
|
# @param [TaxGenerator::FileCreator] worker the worker that will create the file
|
@@ -226,8 +263,8 @@ module TaxGenerator
|
|
226
263
|
#
|
227
264
|
# @api public
|
228
265
|
def register_worker_for_job(job, worker)
|
229
|
-
|
230
|
-
|
266
|
+
register_job_to_worker(job, worker)
|
267
|
+
register_worker_to_job(job, worker)
|
231
268
|
log_message("worker #{worker.job_id} registed into manager")
|
232
269
|
Actor.current.link worker
|
233
270
|
worker.async.start_work
|
@@ -252,6 +289,32 @@ module TaxGenerator
|
|
252
289
|
end
|
253
290
|
end
|
254
291
|
|
292
|
+
# fetches the job from a worker
|
293
|
+
# @param [TaxGenerator::FileCreator] worker the worker that died
|
294
|
+
#
|
295
|
+
# @return [void]
|
296
|
+
#
|
297
|
+
# @api public
|
298
|
+
def get_job_from_worker(worker)
|
299
|
+
@worker_to_job_mutex.synchronize do
|
300
|
+
@worker_to_job[worker.mailbox.address]
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
# deletes the worker from the worker_to_job storage
|
305
|
+
# @param [TaxGenerator::FileCreator] worker the worker that died
|
306
|
+
#
|
307
|
+
# @return [void]
|
308
|
+
#
|
309
|
+
# @api public
|
310
|
+
def delete_from_worker_to_job(worker)
|
311
|
+
mailbox = worker.mailbox.address
|
312
|
+
@worker_to_job_mutex.synchronize do
|
313
|
+
@worker_to_job.delete(mailbox)
|
314
|
+
end
|
315
|
+
mailbox
|
316
|
+
end
|
317
|
+
|
255
318
|
# logs the message about working being dead if a worker crashes
|
256
319
|
# @param [TaxGenerator::FileCreator] worker the worker that died
|
257
320
|
# @param [String] reason the reason for which the worker died
|
@@ -260,10 +323,10 @@ module TaxGenerator
|
|
260
323
|
#
|
261
324
|
# @api public
|
262
325
|
def worker_died(worker, reason)
|
263
|
-
|
264
|
-
|
326
|
+
job = get_job_from_worker(worker)
|
327
|
+
mailbox = delete_from_worker_to_job(worker)
|
265
328
|
return if reason.blank? || job.blank?
|
266
|
-
log_message("worker job #{job['atlas_id']} with mailbox #{
|
329
|
+
log_message("worker job #{job['atlas_id']} with mailbox #{mailbox.inspect} died for reason: #{log_error(reason)}", log_method: 'fatal')
|
267
330
|
end
|
268
331
|
end
|
269
332
|
end
|
@@ -77,7 +77,7 @@ describe TaxGenerator::FileCreator do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'fetch_atlas_details' do
|
80
|
-
subject.
|
80
|
+
subject.stubs(:atlas_node).returns(fake_node)
|
81
81
|
TaxGenerator::Destination.expects(:new).with(first_destination).returns(first_destination)
|
82
82
|
first_destination.stubs(:to_hash).returns({})
|
83
83
|
actual = subject.fetch_atlas_details
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tax_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bogdanRada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|