pampa_workers 0.0.38

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fca2d5bf056b264b2630ea17240867025097cff7
4
+ data.tar.gz: fac05a77c3a324be33f92dfd4f247a0dc7d3a057
5
+ SHA512:
6
+ metadata.gz: 46793bba1c0d1b06ac04f5004546663cdb2fbe43f8d51dca8c077bc007506fe974ecebce16943f552e0d281f9d9efd2ae1c1251360abf9f0a01dee0528a161f3
7
+ data.tar.gz: 45705f311c6ca2b7a69fda32d787b84c6a590c6994fb7677d13767a825c493a81607030f9c449dd070f3e21f627d0b88ea311ad9afcbeaa9f57e722ae33103ff
@@ -0,0 +1,5 @@
1
+ module BlackStack
2
+ module BaseDivision
3
+
4
+ end # BaseDivision
5
+ end # module BlackStack
data/lib/baseworker.rb ADDED
@@ -0,0 +1,5 @@
1
+ module BlackStack
2
+ module BaseWorker
3
+ KEEP_ACTIVE_MINUTES = 5 # if the worker didnt send a ping during the last X minutes, it is considered as not-active
4
+ end # BaseWorker
5
+ end # module BlackStack
data/lib/client.rb ADDED
@@ -0,0 +1,245 @@
1
+ require 'invoicing_payments_processing'
2
+ require 'simple_host_monitoring'
3
+ require_relative './user'
4
+ require_relative './role'
5
+ require_relative './timezone'
6
+
7
+ module BlackStack
8
+ class Client < Sequel::Model(:client)
9
+ BlackStack::Client.dataset = BlackStack::Client.dataset.disable_insert_output
10
+
11
+ one_to_many :users, :class=>:'BlackStack::User', :key=>:id_client
12
+ many_to_one :timezone, :class=>:'BlackStack::Timezone', :key=>:id_timezone
13
+ many_to_one :billingCountry, :class=>:'BlackStack::LnCountry', :key=>:billing_id_lncountry
14
+ many_to_one :user_to_contect, :class=>'BlackStack:::User', :key=>:id_user_to_contact
15
+
16
+
17
+ # -----------------------------------------------------------------------------------------
18
+ # Arrays
19
+ #
20
+ #
21
+ # -----------------------------------------------------------------------------------------
22
+
23
+ # returns the workers belong this clients, that have not been deleted
24
+ def not_deleted_workers()
25
+ BlackStack::Worker.where(:id_client=>self.id, :delete_time=>nil)
26
+ end
27
+
28
+ # returns the hosts where this client has not-deleted workers, even if the host is not belong this client
29
+ def hosts()
30
+ BlackStack::LocalHost.where(id: self.not_deleted_workers.select(:id_host).all.map(&:id_host))
31
+ end
32
+
33
+ # returns the hosts belong this client
34
+ def own_hosts()
35
+ BlackStack::LocalHost.where(:id_client=>self.id, :delete_time=>nil)
36
+ end
37
+
38
+ # -----------------------------------------------------------------------------------------
39
+ # Storage:
40
+ #
41
+ #
42
+ # -----------------------------------------------------------------------------------------
43
+
44
+ # returns the location of the storage for this client
45
+ def storage_folder
46
+ "#{BlackStack::Pampa::storage_folder}/#{self.id.to_guid}"
47
+ end
48
+
49
+ def storage_sub_folder(name)
50
+ "#{BlackStack::Pampa::storage_folder}/#{self.id.to_guid}/#{name}"
51
+ end
52
+
53
+ # returns the max allowed KB in the storage for this client
54
+ def storage_total_kb
55
+ # TODO: get this parameter from the paid invoces
56
+ 1024*1024 # 1 GB
57
+ end
58
+
59
+ # returns the max allowed KB in the storage for this client
60
+ def storage_used_kb
61
+ path = self.storage_folder
62
+ fso = WIN32OLE.new('Scripting.FileSystemObject')
63
+ folder = fso.GetFolder(path)
64
+ (folder.size.to_f / 1024.to_f)
65
+ end
66
+
67
+ # returns the free available KB in the storage for this client
68
+ def storage_free_kb
69
+ total = self.storage_total_kb
70
+ used = self.storage_used_kb
71
+ total - used
72
+ end
73
+
74
+ # si el cliente no tiene creado el storage, entonces se lo crea, carpeta por carpeta, ferificando cada una si no existe ya.
75
+ def create_storage
76
+ folder = self.storage_folder
77
+ Dir.mkdir BlackStack::Pampa::storage_folder if Dir[BlackStack::Pampa::storage_folder].size==0
78
+ if Dir[folder].size==0
79
+ Dir.mkdir folder
80
+
81
+ BlackStack::Pampa::storage_sub_folders.each { |name|
82
+ s = "#{folder}/#{name}"
83
+ Dir.mkdir s if Dir[s].size==0
84
+ }
85
+ end
86
+ end
87
+
88
+ # retorna la primera division habilitada a la que pertenezca este cliente
89
+ def division
90
+ return self.users.first.division
91
+ end
92
+
93
+ # -----------------------------------------------------------------------------------------
94
+ # Configuration
95
+ #
96
+ #
97
+ # -----------------------------------------------------------------------------------------
98
+
99
+ # retorna true si la 5 variables (billing_address, billing_city, billing_state, billing_zipcode, billing_id_lncountry) tienen un valor destinto a nil o a un string vacio.
100
+ def hasBillingAddress?
101
+ if (
102
+ self.billing_address.to_s.size == 0 ||
103
+ self.billing_city.to_s.size == 0 ||
104
+ self.billing_state.to_s.size == 0 ||
105
+ self.billing_zipcode.to_s.size == 0 ||
106
+ self.billing_id_lncountry.to_s.size == 0
107
+ )
108
+ return false
109
+ else
110
+ return true
111
+ end
112
+ end
113
+
114
+ # retorna un array de objectos UserRole, asignados a todos los usuarios de este cliente
115
+ def user_roles
116
+ a = []
117
+ self.users.each { |o|
118
+ a.concat o.user_roles
119
+ # libero recursos
120
+ GC.start
121
+ DB.disconnect
122
+ }
123
+ a
124
+ end
125
+
126
+ # si el cliente no tiene una zona horaria configurada, retorna la zona horaria por defecto
127
+ # excepciones:
128
+ # => "Default timezone not found."
129
+ def getTimezone()
130
+ ret = nil
131
+ if (self.timezone != nil)
132
+ ret = self.timezone
133
+ else
134
+ ret = BlackStack::Timezone.where(:id=>BlackStack::Pampa::id_timezone_default).first
135
+ if (ret == nil)
136
+ raise "Default timezone not found."
137
+ end
138
+ end
139
+ return ret
140
+ end
141
+
142
+ # llama a la api de postmark preguntando el reseller email configurado para este clietne fue ferificado
143
+ def checkDomainForSSMVerified()
144
+ return_message = {}
145
+ domain = self.domain_for_ssm
146
+ email = self.from_email_for_ssm
147
+ id = ''
148
+ client = ''
149
+
150
+ if domain != nil && email != nil
151
+ begin
152
+ client_postmark = Postmark::AccountApiClient.new(POSTMARK_API_TOKEN, secure: true)
153
+ client_list = client_postmark.get_signatures()
154
+
155
+ client_list.each do |sign|
156
+ if sign[:domain] == domain
157
+ if sign[:email_address] == email
158
+ id = sign[:id]
159
+ break
160
+ end
161
+ end
162
+ end
163
+
164
+ if id.to_s.size > 0
165
+ client = client_postmark.get_sender(id)
166
+ if !client[:confirmed]
167
+ self.domain_for_ssm_verified = false
168
+ self.save
169
+
170
+ return_message[:status] = "No Verified"
171
+ return_message[:value] = client[:id]
172
+
173
+ return return_message.to_json
174
+ else
175
+ self.domain_for_ssm_verified = true
176
+ self.save
177
+
178
+ # sincronizo con la central
179
+ return_message = {}
180
+
181
+ return_message[:status] = "success"
182
+ return_message[:value] = client[:id]
183
+
184
+ return return_message.to_json
185
+ end
186
+ end
187
+
188
+ rescue Postmark::ApiInputError => e
189
+ return_message[:status] = e.to_s
190
+ return return_message.to_json
191
+ #return e
192
+ rescue => e
193
+ return_message[:status] = e.to_s
194
+ return return_message.to_json
195
+ #return e
196
+ end
197
+ else
198
+ return_message[:status] = 'error'
199
+ return_message[:value] = ''
200
+ return return_message.to_json
201
+ end # checkDomainForSSMVerified
202
+ end
203
+
204
+ # retorna true si el cliente esta configurado para usar su propia nombre/email en el envio de notificaciones
205
+ def resellerSignature?
206
+ self.from_name_for_ssm.to_s.size>0 && self.from_email_for_ssm.to_s.size>0
207
+ end
208
+
209
+ # retorna true si el cliente esta configurado para usar su propia nombre/email en el envio de notificaciones, y si el email fue verificado en postmark
210
+ def resellerSignatureEnabled?
211
+ =begin # TODO: Mover esto a un proceso asincronico
212
+ # si el cliente esta configurado para usar su propia nombre/email
213
+ if self.resellerSignature?
214
+ # pero el email fue verificado en postmark
215
+ if self.domain_for_ssm_verified==nil || self.domain_for_ssm_verified!=true
216
+ # hago la verificacion contra postmark
217
+ self.checkDomainForSSMVerified
218
+ end
219
+ end
220
+ =end
221
+ # return
222
+ resellerSignature? == true && self.domain_for_ssm_verified==true
223
+ end
224
+
225
+ # retorna el email configurado y confirmado en PostMark para cuenta reseller, o retorna el email por defecto
226
+ def resellerSignatureEmail
227
+ # configuracion de cuenta reseller
228
+ if self.resellerSignatureEnabled?
229
+ return self.from_email_for_ssm.to_s
230
+ else
231
+ return BlackStack::Params.getValue("notifications.user.email_from")
232
+ end
233
+ end
234
+
235
+ # retorna el nombre configurado para cuenta reseller, solo si el email esta confirmado en PostMark; o retorna el email por defecto
236
+ def resellerSignatureName
237
+ # configuracion de cuenta reseller
238
+ if self.resellerSignatureEnabled?
239
+ return self.from_email_for_ssm.to_s
240
+ else
241
+ return BlackStack::Params.getValue("notifications.user.name_from")
242
+ end
243
+ end
244
+ end # class Client
245
+ end # module BlackStack
data/lib/division.rb ADDED
@@ -0,0 +1,46 @@
1
+ module BlackStack
2
+
3
+ class Division < Sequel::Model(:division)
4
+ include BlackStack::BaseDivision
5
+ Division.dataset = Division.dataset.disable_insert_output
6
+
7
+ def home()
8
+ Division.where(
9
+ :db_url=>self.db_url,
10
+ :db_port=>self.db_port,
11
+ :db_user=>self.db_user,
12
+ :db_password=>self.db_password,
13
+ :db_name=>self.db_name,
14
+ :home=>true,
15
+ :available=>true
16
+ ).first
17
+ end
18
+
19
+ def self.getDefault()
20
+ q =
21
+ "SELECT TOP 1 d.id AS did " +
22
+ "FROM division d " +
23
+ "WHERE d.name='#{SIGNUP_DIVISION}' "
24
+ row = DB[q].first
25
+ if (row==nil)
26
+ return nil
27
+ end
28
+ return Division.where(:id=>row[:did]).first
29
+ end
30
+
31
+ # Actualiza el campo stat_name de todas las divisiones que son "gemelas" as la division pasada por parametro.
32
+ # Ver issue #976.
33
+ def self.updateStat(division, stat_name, date_time)
34
+ Division.where(
35
+ :db_url=>division.db_url,
36
+ :db_port=>division.db_port,
37
+ :db_user=>division.db_user,
38
+ :db_password=>division.db_password,
39
+ ).each { |d|
40
+ q = "UPDATE division SET #{stat_name}='#{date_time.to_s}' WHERE id='#{d.id}'"
41
+ }
42
+ end
43
+
44
+ end # class
45
+
46
+ end # module BlackStack
data/lib/login.rb ADDED
@@ -0,0 +1,7 @@
1
+ module BlackStack
2
+ class Login < Sequel::Model(:login)
3
+ BlackStack::Login.dataset = BlackStack::Login.dataset.disable_insert_output
4
+
5
+ many_to_one :user, :class=>:'BlackStack::User', :key=>:id_user
6
+ end
7
+ end # module BlackStack
@@ -0,0 +1,348 @@
1
+ module BlackStack
2
+
3
+ # clase de base para todos los bots ejecuten acciones con una cuenta de LinkedIn, Facebook, Twitter, etc.
4
+ class MyBotProcess < BlackStack::MyRemoteProcess
5
+ attr_accessor :username, :login_verifications, :run_once
6
+
7
+ # constructor
8
+ def initialize(
9
+ the_worker_name,
10
+ the_division_name,
11
+ the_minimum_enlapsed_seconds=MyProcess::DEFAULT_MINIMUM_ENLAPSED_SECONDS,
12
+ the_verify_configuration=true,
13
+ the_email=nil,
14
+ the_password=nil
15
+ )
16
+ super(the_worker_name, the_division_name, the_minimum_enlapsed_seconds, the_verify_configuration, the_email, the_password)
17
+ self.assigned_process = File.expand_path($0)
18
+ self.worker_name = "#{the_worker_name}"
19
+ self.division_name = the_division_name
20
+ self.minimum_enlapsed_seconds = the_minimum_enlapsed_seconds
21
+
22
+ # algunas clases como CreateLnUserProcess o RepairLnUserProcess, trabajan unicamente con el username especificado en este atributo, llamando al access point get_lnuser_by_username.
23
+ # si este atributo es nil, entonces la clase pide un lnuser a la division, llamando al access point get_lnuser.
24
+ self.username = nil
25
+
26
+ # al correr un proceso sin supervision, el login require verificaciones automaticas que demoran tiempo (account blocingcaptcha, sms pin, bloqueo)
27
+ # las verificaciones consument tiempo.
28
+ # si este proceso se corre de forma supevisada, las verificaciones se pueden deshabilitar
29
+ self.login_verifications = true
30
+
31
+ # al correr sin supervision, el proceso de terminar un un paquete de procesamiento y comenzar con otro, funcionando en un loop infinito.
32
+ # si este proceso se corre de forma supevisada, se desa correr el procesamiento una unica vez.
33
+ # cuando se activa este flag, generalmente se setea el atributo self.username tambien.
34
+ self.run_once = false
35
+ end
36
+
37
+ # returns a hash with the parameters of a lnuser
38
+ # raises an exception if it could not get a lnuser, or if ocurrs any other problem
39
+ def getLnUserByUsername(username)
40
+ nTries = 0
41
+ parsed = nil
42
+ lnuser = nil # hash
43
+ bSuccess = false
44
+ sError = ""
45
+ while (nTries < 5 && bSuccess == false)
46
+ begin
47
+ nTries = nTries + 1
48
+ url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/login.lnuser/get_lnuser.json"
49
+ res = BlackStack::Netting::call_post(url, {'api_key' => BlackStack::Pampa::api_key, 'username' => username.encode("UTF-8")})
50
+ parsed = JSON.parse(res.body)
51
+ if (parsed['status']=='success')
52
+ lnuser = parsed
53
+ bSuccess = true
54
+ else
55
+ sError = parsed['status']
56
+ end
57
+ rescue Errno::ECONNREFUSED => e
58
+ sError = "Errno::ECONNREFUSED:" + e.to_s
59
+ rescue => e2
60
+ sError = "Exception: " + e2.to_s
61
+ end
62
+ end # while
63
+
64
+ if (bSuccess==false)
65
+ raise "#{sError}"
66
+ end
67
+
68
+ return lnuser
69
+ end # getLnUser()
70
+
71
+ # returns a hash with the parameters of a lnuser
72
+ # raises an exception if it could not get a lnuser, or if ocurrs any other problem
73
+ def getLnUser(workflow_name='incrawl.lnsearchvariation')
74
+ nTries = 0
75
+ parsed = nil
76
+ lnuser = nil # hash
77
+ bSuccess = false
78
+ sError = ""
79
+ while (nTries < 5 && bSuccess == false)
80
+ begin
81
+ nTries = nTries + 1
82
+ url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/get_lnuser.json"
83
+ res = BlackStack::Netting::call_post(url, {'api_key' => BlackStack::Pampa::api_key, 'name' => self.fullWorkerName})
84
+ parsed = JSON.parse(res.body)
85
+ if (parsed['status']=='success')
86
+ lnuser = parsed
87
+ bSuccess = true
88
+ else
89
+ sError = parsed['status']
90
+ end
91
+ rescue Errno::ECONNREFUSED => e
92
+ sError = "Errno::ECONNREFUSED:" + e.to_s
93
+ rescue => e2
94
+ sError = "Exception" + e2.to_s
95
+ end
96
+ end # while
97
+
98
+ if (bSuccess==false)
99
+ raise "#{sError}"
100
+ end
101
+
102
+ return lnuser
103
+ end # getLnUser()
104
+
105
+ #
106
+ def notifyLnUserUrl(id_lnuser, url)
107
+ =begin
108
+ nTries = 0
109
+ parsed = nil
110
+ bSuccess = false
111
+ sError = ""
112
+ while (nTries < 5 && bSuccess == false)
113
+ begin
114
+ nTries = nTries + 1
115
+ url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/login.lnuser/notify_url.json"
116
+ res = BlackStack::Netting::call_post(url,
117
+ {:api_key => BlackStack::Pampa::api_key,
118
+ 'id_lnuser' => id_lnuser,
119
+ 'url' => url,}
120
+ )
121
+ parsed = JSON.parse(res.body)
122
+
123
+ if (parsed['status']=='success')
124
+ bSuccess = true
125
+ else
126
+ sError = parsed['status']
127
+ end
128
+ rescue Errno::ECONNREFUSED => e
129
+ sError = "Errno::ECONNREFUSED:" + e.to_s
130
+ rescue => e2
131
+ sError = "Exception" + e2.to_s
132
+ end
133
+ end # while
134
+
135
+ if (bSuccess==false)
136
+ raise "#{sError}"
137
+ end
138
+ =end
139
+ end # notifyLnUserStatus
140
+
141
+ #
142
+ def notifyLnUserStatus(id_lnuser, status, workflow_name='incrawl.lnsearchvariation')
143
+ nTries = 0
144
+ parsed = nil
145
+ bSuccess = false
146
+ sError = ""
147
+ while (nTries < 5 && bSuccess == false)
148
+ begin
149
+ nTries = nTries + 1
150
+ url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/notify_lnuser_status.json"
151
+ res = BlackStack::Netting::call_post(url,
152
+ {'api_key' => BlackStack::Pampa::api_key,
153
+ 'id_lnuser' => id_lnuser,
154
+ 'status' => status,}
155
+ )
156
+ parsed = JSON.parse(res.body)
157
+
158
+ if (parsed['status']=='success')
159
+ bSuccess = true
160
+ else
161
+ sError = parsed['status']
162
+ end
163
+ rescue Errno::ECONNREFUSED => e
164
+ sError = "Errno::ECONNREFUSED:" + e.to_s
165
+ rescue => e2
166
+ sError = "Exception" + e2.to_s
167
+ end
168
+ end # while
169
+
170
+ if (bSuccess==false)
171
+ raise "#{sError}"
172
+ end
173
+
174
+ end # notifyLnUserStatus
175
+
176
+ #
177
+ def notifyLnUserActivity(id_lnuser, code, workflow_name='incrawl.lnsearchvariation')
178
+ nTries = 0
179
+ parsed = nil
180
+ bSuccess = false
181
+ sError = ""
182
+ while (nTries < 5 && bSuccess == false)
183
+ begin
184
+ nTries = nTries + 1
185
+ url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/notify_lnuser_activity.json"
186
+ res = BlackStack::Netting::call_post(url,
187
+ {'api_key' => BlackStack::Pampa::api_key,
188
+ 'id_lnuser' => id_lnuser,
189
+ 'code' => code,}
190
+ )
191
+ parsed = JSON.parse(res.body)
192
+
193
+ if (parsed['status']=='success')
194
+ bSuccess = true
195
+ else
196
+ sError = parsed['status']
197
+ end
198
+ rescue Errno::ECONNREFUSED => e
199
+ sError = "Errno::ECONNREFUSED:" + e.to_s
200
+ rescue => e2
201
+ sError = "Exception" + e2.to_s
202
+ end
203
+ end # while
204
+
205
+ if (bSuccess==false)
206
+ raise "#{sError}"
207
+ end
208
+ end # notifyLnUserStatus
209
+
210
+ # Toma una captura del browser.
211
+ # Sube un registro a la tabla boterrorlog, con el id del worker, el proceso asinado, y el screenshot.
212
+ #
213
+ # uid: id de un registro en la tabla lnuser.
214
+ # description: backtrace de la excepcion.
215
+ #
216
+ def notifyError(uid, description, oid=nil)
217
+ # tomo captura de pantalla
218
+ file = nil
219
+ =begin # TODO: habilitar esto cuando se migre a RestClient en vez de CallPost
220
+ begin
221
+ screenshot_filename = "./error.png" # TODO: colocar un nombre unico formado por por el fullname del worker, y la fecha-hora.
222
+ BrowserFactory.screenshot screenshot_filename
223
+ file = File.new(screenshot_filename, "rb")
224
+ rescue => e
225
+ puts "Screenshot Error: #{e.to_s}"
226
+ file = nil
227
+ end
228
+ =end
229
+ #puts ""
230
+ #puts "id_worker:#{PROCESS.worker.id}"
231
+ #puts "worker_name:#{PROCESS.fullWorkerName}"
232
+ #puts "process:#{PROCESS.worker.assigned_process}"
233
+ #puts ""
234
+ # subo el error
235
+ nTries = 0
236
+ bSuccess = false
237
+ parsed = nil
238
+ sError = ""
239
+ while (nTries < 5 && bSuccess == false)
240
+ begin
241
+ nTries = nTries + 1
242
+ url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/boterror.json"
243
+ res = BlackStack::Netting::call_post(url, # TODO: migrar a RestClient para poder hacer file upload
244
+ 'api_key' => BlackStack::Pampa::api_key,
245
+ 'id_lnuser' => uid,
246
+ 'id_object' => oid,
247
+ 'worker_name' => PROCESS.fullWorkerName,
248
+ 'process' => PROCESS.worker.assigned_process,
249
+ 'description' => description,
250
+ 'screenshot' => file,
251
+ )
252
+ parsed = JSON.parse(res.body)
253
+ if (parsed['status']=='success')
254
+ bSuccess = true
255
+ else
256
+ sError = parsed['status']
257
+ end
258
+ rescue Errno::ECONNREFUSED => e
259
+ sError = "Errno::ECONNREFUSED:" + e.to_s
260
+ rescue => e2
261
+ sError = "Exception" + e2.to_s
262
+ end
263
+ end # while
264
+
265
+ if (bSuccess==false)
266
+ raise "#{sError}"
267
+ end
268
+ end
269
+
270
+ #
271
+ def isLnUserAvailable(id_lnuser, need_sales_navigator=false, workflow_name='incrawl.lnsearchvariation')
272
+ nTries = 0
273
+ parsed = nil
274
+ bSuccess = false
275
+ sError = ""
276
+ ret = false
277
+
278
+ while (nTries < 5 && bSuccess == false)
279
+ begin
280
+ nTries = nTries + 1
281
+ url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/is_lnuser_available.json"
282
+ res = BlackStack::Netting::call_post(url,
283
+ {'api_key' => BlackStack::Pampa::api_key,
284
+ 'id_lnuser' => id_lnuser,
285
+ 'need_sales_navigator' => need_sales_navigator,}
286
+ )
287
+ parsed = JSON.parse(res.body)
288
+
289
+ if (parsed['status']=='success')
290
+ bSuccess = true
291
+ ret = parsed['value']
292
+ else
293
+ sError = parsed['status']
294
+ end
295
+ rescue Errno::ECONNREFUSED => e
296
+ sError = "Errno::ECONNREFUSED:" + e.to_s
297
+ rescue => e2
298
+ sError = "Alghoritm Exception" + e2.to_s + '\r\n' + e2.backtrace.join("\r\n").to_s
299
+ end
300
+ end # while
301
+
302
+ if (bSuccess==false)
303
+ raise "#{sError}"
304
+ end
305
+
306
+ return ret
307
+ end # isLnUserAvailable
308
+
309
+ #
310
+ def releaseLnUser(id_lnuser, workflow_name='incrawl.lnsearchvariation')
311
+ nTries = 0
312
+ parsed = nil
313
+ bSuccess = false
314
+ sError = ""
315
+ ret = false
316
+
317
+ while (nTries < 5 && bSuccess == false)
318
+ begin
319
+ nTries = nTries + 1
320
+ url = "#{BlackStack::Pampa::api_protocol}://#{self.ws_url}:#{self.ws_port}/api1.3/pampa/#{workflow_name}/release_lnuser.json"
321
+ res = BlackStack::Netting::call_post(url,
322
+ {'api_key' => BlackStack::Pampa::api_key, 'id_lnuser' => id_lnuser,}
323
+ )
324
+ parsed = JSON.parse(res.body)
325
+
326
+ if (parsed['status']=='success')
327
+ bSuccess = true
328
+ ret = parsed['value']
329
+ else
330
+ sError = parsed['status']
331
+ end
332
+ rescue Errno::ECONNREFUSED => e
333
+ sError = "Errno::ECONNREFUSED:" + e.to_s
334
+ rescue => e2
335
+ sError = "Exception" + e2.to_s
336
+ end
337
+ end # while
338
+
339
+ if (bSuccess==false)
340
+ raise "#{sError}"
341
+ end
342
+
343
+ return ret
344
+ end # isLnUserAvailable
345
+
346
+ end # class MyBotProcess
347
+
348
+ end # module BlackStack
@@ -0,0 +1,9 @@
1
+ module BlackStack
2
+
3
+ # es un proceso sin conexion a base de datos, que itera infinitamente.
4
+ # en cada iteracion saluda a la central (hello), obtiene parametros (get)
5
+ class MyChildProcess < BlackStack::MyProcess
6
+
7
+ end # MyChildProcess
8
+
9
+ end # module BlackStack