Class: VTools::Harvester
- Inherits:
-
Object
- Object
- VTools::Harvester
- Includes:
- SharedMethods
- Defined in:
- lib/vtools/harvester.rb
Overview
Takes care about jobs
Class Method Summary collapse
-
.add_job(config) ⇒ Object
set new job.
-
.daemonize! ⇒ Object
collector.
Methods included from SharedMethods
Methods included from SharedMethods::Common
#config, #fix_encoding, #generate_path, #hash_to_obj, #json_to_obj, #keys_to_sym, #log, #logger=, #network_call, #parse_json, #path_generator
Class Method Details
.add_job(config) ⇒ Object
set new job
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vtools/harvester.rb', line 30 def add_job config job = Job.new config @jobs[job.id] = job @run_jobs += 1 # execute job Thread.new(job, config) do # catch job exceptions here with_error_handle do # catch job exceptions Storage.send({ :data => job.execute, :action => config.action }) end finish job # in any case close job instance end end |
.daemonize! ⇒ Object
collector
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vtools/harvester.rb', line 15 def daemonize! Storage.connect # connect jobs pool loop do with_error_handle do # catch job exceptions config = json_to_obj Storage.recv add_job config end if CONFIG[:max_jobs] > @run_jobs sleep CONFIG[:harvester_timer] end end |