Class: BlackStack::MyRemoteProcess

Inherits:
MyChildProcess show all
Defined in:
lib/myremoteprocess.rb

Overview

no maneja conexion a la base de datos. ejecuta un loop mientras el metodo canRun? retorne true.

Direct Known Subclasses

MyBotProcess

Constant Summary

Constants inherited from MyProcess

BlackStack::MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS

Instance Attribute Summary collapse

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

Methods inherited from MyProcess

#canRun?, #division, #doSleep, #fullWorkerName, fullWorkerName, #get, #hello, #initialize, kill, #list, macaddress, #notify, #pid, #ping, #process, #set, #whyCantRun

Constructor Details

This class inherits a constructor from BlackStack::MyProcess

Instance Attribute Details

#workerObject

Returns the value of attribute worker.



7
8
9
# File 'lib/myremoteprocess.rb', line 7

def worker
  @worker
end

Instance Method Details

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
# File 'lib/myremoteprocess.rb', line 41

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
    )
  
    logger.log "Remote process is alive!"
  
    # actualiza parametros de la central
    logger.logs "Update from central (1-remote)... "
    self.get
    logger.done
  
    # actualizo los datos de este worker (parent process)
    logger.logs "Update worker (1-remote)... "
    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 Remote"
      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
  
        # envia senial a la central.
        # si tiene asignada una division, envia senial a la division.          
        logger.logs "Ping... "
        self.ping()
        logger.done
  
        # envia senial a la central.
        # si tiene asignada una division, envia senial a la division.          
        logger.logs "Notify to Division... "
        self.notify()
        logger.done
  
        # corro el procesamiento
        self.process(ARGV)
  
      rescue => e
        puts ""
        logger.log "Remote Process Error: " + e.to_s + "\r\n" + e.backtrace.join("\r\n").to_s      
      end
  
      # actualiza parametros de la central
      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 "-------------------------------------------"
  
      GC.start
      #DB.disconnect
  
    end # main while
  
    # 
    logger.log self.whyCantRun()
    
end

#updateWorkerObject

update worker configuration in the division TODO: deprecated



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/myremoteprocess.rb', line 11

def updateWorker()      
  # creo un remote worker que manejare en este proceso remote
  self.worker = BlackStack::RemoteWorker.new
  # me notifico a la central. obtengo asignacion si ya la tenia
  # y vuelco la configuracion al remote worker
  url = "#{BlackStack::Pampa::api_url}/api1.3/pampa/get.json"
  res = BlackStack::Netting::call_post(url, {
    'api_key' => BlackStack::Pampa::api_key, 
    'name' => self.fullWorkerName }.merge( BlackStack::RemoteHost.new.poll )
  )
  parsed = JSON.parse(res.body)
  if (parsed['status'] != BlackStack::Netting::SUCCESS)
    raise parsed['status'].to_s
  else  
    self.worker.id                  = parsed['id']
    self.worker.assigned_process    = parsed['assigned_process']
    self.worker.id_client           = parsed['id_client']
    self.worker.id_division         = parsed['id_division']
    self.worker.division_name       = parsed['division_name']
    self.worker.ws_url              = parsed['ws_url']
    self.worker.ws_port             = parsed['ws_port']
    self.worker.division            = BlackStack::RemoteDivision.new
    self.worker.division.name       = parsed['division_name']
  end
  # llamo al metodo de la clase padre que reporta la configuracion a
  # la division del worker
  self.set(parsed['assigned_process'], parsed['id_client'])
end