Class: BlackStack::MyLocalProcess
- Inherits:
-
MyChildProcess
- Object
- MyProcess
- MyChildProcess
- BlackStack::MyLocalProcess
- Defined in:
- lib/mylocalprocess.rb
Overview
Process located in the same LAN than the Database Server
Direct Known Subclasses
Constant Summary
Constants inherited from MyProcess
BlackStack::MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS
Instance Attribute Summary
Attributes inherited from MyProcess
#assigned_division_changed, #assigned_process, #assigned_process_changed, #division_name, #email, #id, #id_client, #id_division, #logger, #minimum_enlapsed_seconds, #password, #verify_configuration, #worker_name, #ws_port, #ws_url
Instance Method Summary collapse
- #division ⇒ Object
-
#initialize(the_worker_name, the_division_name, the_minimum_enlapsed_seconds = BlackStack::MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS, the_verify_configuration = true, the_email = nil, the_password = nil) ⇒ MyLocalProcess
constructor
constructor.
- #run ⇒ Object
-
#updateWorker ⇒ Object
update worker configuration in the division.
- #worker ⇒ Object
Methods inherited from MyProcess
#canRun?, #doSleep, fullWorkerName, #fullWorkerName, #get, #hello, kill, #list, macaddress, #notify, #pid, #ping, #process, #set, #whyCantRun
Constructor Details
#initialize(the_worker_name, the_division_name, the_minimum_enlapsed_seconds = BlackStack::MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS, the_verify_configuration = true, the_email = nil, the_password = nil) ⇒ MyLocalProcess
constructor
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mylocalprocess.rb', line 7 def initialize( the_worker_name, the_division_name, the_minimum_enlapsed_seconds=BlackStack::MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS, the_verify_configuration=true, the_email=nil, the_password=nil ) super(the_worker_name, the_division_name, the_minimum_enlapsed_seconds, the_verify_configuration, the_email, the_password) end |
Instance Method Details
#division ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mylocalprocess.rb', line 18 def division() if (self.division_name != "local") d = BlackStack::Division.where(:name=>self.division_name).first if (d!=nil) return BlackStack::Division.where(:db_name=>d.db_name, :home=>true).first else return nil end else return BlackStack::Division.where(:central=>true).first end end |
#run ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/mylocalprocess.rb', line 59 def run() super # creo el objeto logger self.logger = RemoteLogger.new( "#{self.fullWorkerName}.log", BlackStack::Pampa::api_protocol, BlackStack::Pampa::api_domain, BlackStack::Pampa::api_port, BlackStack::Pampa::api_key, self.id_client # ID of the client that has this thread assigned ) # announcing my in the log logger.log "Child process is alive!" # obtengo los parametros del worker logger.logs "Update from central (1-local)... " self.get logger.done # actualizo los datos de este worker (parent process) logger.logs "Update worker (1-local)... " self.updateWorker logger.done # actualizo los datos de este worker (parent process) logger.logs "Switch logger id_client (log folder may change)... " self.logger.id_client = self.id_client logger.done while (self.canRun?) # reseteo en contador nested del logger self.logger.reset() # announcing my in the log logger.log "Going to Run Local" logger.log "Process: #{self.assigned_process.to_s}." logger.log "Client: #{(self.id_client.to_s.size==0)? 'n/a' : self.id_client.to_s}." # obtengo la hora de inicio start_time = Time.now begin # libero recursos logger.logs "Release resources... " GC.start DB.disconnect logger.done # cargo el objeto worker logger.logs "Load the worker... " the_worker = self.worker logger.done # actualizo el valor del proceso que corre actualmente para este worker logger.logs "Update current process... " the_worker.process=self.assigned_process the_worker.active = true the_worker.save() logger.done logger.logs "Ping... " the_worker.ping() logger.done # corro el procesamiento self.process(ARGV) rescue => e puts "" logger.log "Local Process Error: " + e.to_s + "\r\n" + e.backtrace.join("\r\n").to_s end # obtengo los parametros del worker logger.logs "Update from central (2)... " self.get logger.done # actualizo los datos de este worker (parent process) logger.logs "Update worker (2)... " self.updateWorker logger.done # sleep logger.logs "Sleep... " self.doSleep(start_time) logger.done logger.log "-------------------------------------------" DB.disconnect GC.start end # main while # logger.log "Process Finish!" logger.log "Finish Reason: " + self.whyCantRun.to_s # logger.logs "Disconnect to Database... " begin DB.disconnect() logger.done rescue => e logger.error(e) end end |
#updateWorker ⇒ Object
update worker configuration in the division
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mylocalprocess.rb', line 37 def updateWorker() w = BlackStack::Worker.where(:name=>self.fullWorkerName).first if (w==nil) w = BlackStack::Worker.new w.id = guid() w.process = '' w.last_ping_time = now() w.name = self.fullWorkerName w.assigned_process = self.assigned_process w.id_client = self.id_client w.division_name = self.division_name w.save end if (w!=nil) w.assigned_process = self.assigned_process w.id_client = self.id_client w.division_name = self.division_name w.id_division = self.id_division w.save end end |
#worker ⇒ Object
31 32 33 |
# File 'lib/mylocalprocess.rb', line 31 def worker() BlackStack::Worker.where(:name=>self.fullWorkerName).first end |