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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 317ad3db4dcd7234da44f8b4640c0d6692438ec8
4
- data.tar.gz: 14f96024f09d3254c34ffa947cdcb2570edda110
3
+ metadata.gz: 18cb322618a66792931dece02a7ee66078c56f3d
4
+ data.tar.gz: f94a7f55687d90e2a40bb7fd3527afffa035bb4a
5
5
  SHA512:
6
- metadata.gz: ef9751ef774b8f9be7d353299d202850f7b16b1d7e958f3b52483f1d350d27ff91375619fb31bd68f04ed39002f50713f5f5b9cbeef4f5c002d09b47e2fadd7b
7
- data.tar.gz: 32fe13515c63955a79f120148c69d64cfdf63fe1d4ac6bbea35b8459599e4fda746f1743f1dbcb04a09900237ee98281546fa1359075452655fda94d77184571
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
@@ -19,6 +19,7 @@ require 'ostruct'
19
19
  require 'erb'
20
20
  require 'tilt'
21
21
  require 'tilt/erb'
22
+ require 'thread'
22
23
 
23
24
  %w(classes helpers).each do |folder_name|
24
25
  Gem.find_files("tax_generator/#{folder_name}/**/*.rb").each { |path| require path }
@@ -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
- @jobs.all? { |_job_id, job| job['status'] == 'finished' }
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
- @jobs[job['atlas_id']] = job
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
- @jobs.pmap do |_job_id, job|
169
- @workers.async.work(job, current_actor) if @workers.alive?
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
- @job_to_worker[job['atlas_id']] = worker
230
- @worker_to_job[worker.mailbox.address] = job
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
- mailbox_address = worker.mailbox.address
264
- job = @worker_to_job.delete(mailbox_address)
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 #{mailbox_address.inspect} died for reason: #{log_error(reason)}", log_method: 'fatal')
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
@@ -17,7 +17,7 @@ module TaxGenerator
17
17
  # minor release version
18
18
  MINOR = 5
19
19
  # tiny release version
20
- TINY = 1
20
+ TINY = 2
21
21
  # prelease version ( set this only if it is a prelease)
22
22
  PRE = nil
23
23
 
@@ -77,7 +77,7 @@ describe TaxGenerator::FileCreator do
77
77
  end
78
78
 
79
79
  it 'fetch_atlas_details' do
80
- subject.taxonomy.expects(:[]).with(subject.job_id).returns(fake_node)
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.1
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: 2015-12-18 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri