Class: Liri::Manager
- Inherits:
-
Object
- Object
- Liri::Manager
- Defined in:
- lib/manager/manager.rb,
lib/manager/credential.rb
Defined Under Namespace
Classes: Credential
Class Method Summary collapse
- .print_detailed_failures ⇒ Object
- .print_detailed_table ⇒ Object
- .print_summary_failures ⇒ Object
- .print_summary_table ⇒ Object
-
.run(source_code_folder_path, stop = false) ⇒ Object
Inicia la ejecución del Manager.
- .show_batch_run_column ⇒ Object
- .show_failed_files_column ⇒ Object
- .show_files_load_column ⇒ Object
- .show_finish_in_column ⇒ Object
- .show_share_source_code_column ⇒ Object
- .show_share_source_code_progress_bar ⇒ Object
- .test_files_by_runner ⇒ Object
- .udp_request_delay ⇒ Object
Instance Method Summary collapse
- #build_tests_batches(all_tests) ⇒ Object
-
#initialize(udp_port, tcp_port, all_tests, tests_result) ⇒ Manager
constructor
A new instance of Manager.
- #print_detailed_table ⇒ Object
- #print_results ⇒ Object
- #print_summary_table ⇒ Object
- #process_tests_result(agent_ip_address, hardware_specs, tests_result, run_tests_batch_time_start) ⇒ Object
- #processed_tests_batches_by_agents ⇒ Object
- #processing ⇒ Object
- #register_agent(agent_ip_address) ⇒ Object
- #registered_agent?(agent_ip_address) ⇒ Boolean
-
#start_client_socket_to_search_agents(manager_data) ⇒ Object
Inicia un cliente udp que hace un broadcast en toda la red para iniciar una conexión con los Agent que estén escuchando.
-
#start_server_socket_to_process_tests(search_agents_thread) ⇒ Object
Inicia un servidor tcp para procesar los pruebas después de haberse iniciado la conexión a través de udp.
- #start_share_source_code_progress_bar(hardware_specs, msg) ⇒ Object
- #start_tests_running_progress_bar ⇒ Object
- #stop_share_source_code_progress_bar(hardware_specs, share_source_code_progress_bar) ⇒ Object
- #summary_footer ⇒ Object
- #tests_batch(agent_ip_address, hardware_specs, share_source_code_time_end) ⇒ Object
- #to_duration(value) ⇒ Object
- #update_agents_bar ⇒ Object
- #update_connected_agents(agent_ip_address) ⇒ Object
- #update_working_agents(agent_ip_address) ⇒ Object
Constructor Details
#initialize(udp_port, tcp_port, all_tests, tests_result) ⇒ Manager
Returns a new instance of Manager.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/manager/manager.rb', line 159 def initialize(udp_port, tcp_port, all_tests, tests_result) @udp_port = udp_port @udp_socket = UDPSocket.new @tcp_port = tcp_port @batch_num = 0 @tests_batches = {} @tests_files_count = 0 build_tests_batches(all_tests) @files_processed = 0 @agents = {} @connected_agents = {} @working_agents = {} @tests_result = tests_result @semaphore = Mutex.new @tests_processing_bar = TTY::ProgressBar::Multi.new("Tests Running Progress") @tests_running_progress_bar = @tests_processing_bar.register("Tests files processed :current/:total |:bar| :percent | Time: :time", total: @tests_files_count, width: 80, bar_format: :box) @agents_bar = @tests_processing_bar.register("Agents: Connected: :connected, Working: :working") @tests_result_bar = @tests_processing_bar.register("Examples: :examples, Passed: :passed, Failures: :failures") @tests_processing_bar.start # Se inicia la multi barra de progreso # Se establece el estado inicial de las barras @tests_running_progress_bar.use(Common::TtyProgressbar::TimeFormatter) # Se configura el uso de un nuevo token llamado time para mostrar el tiempo de ejcución @tests_running_progress_bar.advance(0) # Esto obliga a que esta barra se muestre antes que los siguientes @tests_running_progress_bar.pause @agents_bar.advance(0, connected: "0", working: "0") @tests_result_bar.advance(0, examples: "0", passed: "0", failures: "0") end |
Class Method Details
.print_detailed_failures ⇒ Object
76 77 78 |
# File 'lib/manager/manager.rb', line 76 def print_detailed_failures Liri.setup.manager.print.failures.detailed end |
.print_detailed_table ⇒ Object
68 69 70 |
# File 'lib/manager/manager.rb', line 68 def print_detailed_table Liri.setup.manager.print.table.detailed end |
.print_summary_failures ⇒ Object
72 73 74 |
# File 'lib/manager/manager.rb', line 72 def print_summary_failures Liri.setup.manager.print.failures.summary end |
.print_summary_table ⇒ Object
64 65 66 |
# File 'lib/manager/manager.rb', line 64 def print_summary_table Liri.setup.manager.print.table.summary end |
.run(source_code_folder_path, stop = false) ⇒ Object
Inicia la ejecución del Manager
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/manager/manager.rb', line 15 def run(source_code_folder_path, stop = false) return unless valid_project setup_manager = Liri.set_setup(source_code_folder_path, :manager, manager_tests_results_folder_time: DateTime.now.strftime("%d_%m_%y_%H_%M_%S")) manager_folder_path = setup_manager.manager_folder_path manager_tests_results_folder_path = setup_manager.manager_tests_results_folder_path Liri.set_logger(setup_manager.logs_folder_path, 'lirimanager.log') Liri.logger.info('Manager process started', true) Liri.logger.info("Press Ctrl + c to finish Manager process manually\n", true) user, password = get_credentials(setup_manager.setup_folder_path) source_code = compress_source_code(source_code_folder_path, manager_folder_path) manager_data = get_manager_data(user, password, manager_tests_results_folder_path, source_code) all_tests = get_all_tests(source_code) tests_result = Common::TestsResult.new(manager_tests_results_folder_path) manager = Manager.new(Liri.udp_port, Liri.tcp_port, all_tests, tests_result) threads = [] threads << manager.start_client_socket_to_search_agents(manager_data) # Enviar peticiones broadcast a toda la red para encontrar Agents unless stop # Esperar y enviar los test unitarios a los Agents manager.start_server_socket_to_process_tests(threads[0]) end Liri.init_exit(stop, threads) rescue SignalException # Liri.logger.info("\nManager process finished manually", true) ensure # Siempre se ejecutan estos comandos, haya o no excepción Liri.kill(threads) if threads&.any? manager&.print_results source_code&.delete_compressed_file Liri.logger.info("Manager process finished", true) end |
.show_batch_run_column ⇒ Object
92 93 94 |
# File 'lib/manager/manager.rb', line 92 def show_batch_run_column Liri.setup.manager.print.column.batch_run end |
.show_failed_files_column ⇒ Object
80 81 82 |
# File 'lib/manager/manager.rb', line 80 def show_failed_files_column Liri.setup.manager.print.column.failed_files end |
.show_files_load_column ⇒ Object
84 85 86 |
# File 'lib/manager/manager.rb', line 84 def show_files_load_column Liri.setup.manager.print.column.files_load end |
.show_finish_in_column ⇒ Object
88 89 90 |
# File 'lib/manager/manager.rb', line 88 def show_finish_in_column Liri.setup.manager.print.column.finish_in end |
.show_share_source_code_column ⇒ Object
96 97 98 |
# File 'lib/manager/manager.rb', line 96 def show_share_source_code_column Liri.setup.manager.print.column.share_source_code end |
.show_share_source_code_progress_bar ⇒ Object
60 61 62 |
# File 'lib/manager/manager.rb', line 60 def Liri.setup.manager..share_source_code end |
Instance Method Details
#build_tests_batches(all_tests) ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/manager/manager.rb', line 317 def build_tests_batches(all_tests) while all_tests.any? @batch_num += 1 # Se numera cada lote samples = all_tests.sample!(Manager.test_files_by_runner) # Se obtiene algunos tests samples_keys = samples.keys # Se obtiene la clave asignada a los tests files_count = samples.size status = "pending" @tests_files_count += files_count # Se construye el lote a enviar tests_batch = { batch_num: @batch_num, tests_batch_keys: samples_keys, msg: "process_tests", files_count: files_count, status: status, files_status: "#{files_count} #{status}", agent_ip_address: "", examples: 0, passed: 0, failures: 0, pending: 0, failed_files: "", files_load: 0, finish_in: 0, batch_run: 0, share_source_code: 0, tests_runtime: 0, hardware_specs: "" } @tests_batches[@batch_num] = tests_batch end @unfinished_tests_batches = @batch_num end |
#print_detailed_table ⇒ Object
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'lib/manager/manager.rb', line 508 def print_detailed_table rows = @tests_batches.values.map do |value| value.remove!(:tests_batch_keys, :msg, :files_count, :status, :agent_ip_address, :pending) value.remove!(:failed_files) unless Manager.show_failed_files_column value.remove!(:files_load) unless Manager.show_files_load_column value.remove!(:finish_in) unless Manager.show_finish_in_column value.remove!(:batch_run) unless Manager.show_batch_run_column value.remove!(:share_source_code) unless Manager.show_share_source_code_column value[:files_load] = to_duration(value[:files_load]) if value[:files_load] value[:finish_in] = to_duration(value[:finish_in]) if value[:finish_in] value[:batch_run] = to_duration(value[:batch_run]) if value[:batch_run] value[:share_source_code] = to_duration(value[:share_source_code]) if value[:share_source_code] value[:tests_runtime] = to_duration(value[:tests_runtime]) value.values end rows << Array.new(rows.size) # Se agrega una linea vacia antes de mostrar los totales rows << .values header = @tests_batches.values.first.keys table = Terminal::Table.new title: 'Detailed Summary', headings: header, rows: rows table.style = { padding_left: 3, border_x: '=', border_i: 'x' } Liri.logger.info("\n#{table}", true) end |
#print_results ⇒ Object
440 441 442 443 444 445 446 |
# File 'lib/manager/manager.rb', line 440 def print_results @tests_processing_bar&.stop print_summary_table if Manager.print_summary_table print_detailed_table if Manager.print_detailed_table @tests_result.print_summary_failures if Manager.print_summary_failures @tests_result.print_detailed_failures if Manager.print_detailed_failures end |
#print_summary_table ⇒ Object
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/manager/manager.rb', line 448 def print_summary_table processed_tests_batches_by_agent = processed_tests_batches_by_agents rows = processed_tests_batches_by_agent.values.map do |value| value[:files_load] = to_duration(value[:files_load]) if value[:files_load] value[:finish_in] = to_duration(value[:finish_in]) if value[:finish_in] value[:batch_run] = to_duration(value[:batch_run]) if value[:batch_run] value[:share_source_code] = to_duration(value[:share_source_code]) if value[:share_source_code] value[:tests_runtime] = to_duration(value[:tests_runtime]) if value[:tests_runtime] value.values end rows << Array.new(rows.size) # Se agrega una linea vacia antes de mostrar los totales rows << .remove(:batch_num).values header = processed_tests_batches_by_agent.values.first.keys table = Terminal::Table.new title: 'Summary', headings: header, rows: rows table.style = { padding_left: 3, border_x: '=', border_i: 'x'} Liri.logger.info("\n#{table}", true) end |
#process_tests_result(agent_ip_address, hardware_specs, tests_result, run_tests_batch_time_start) ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/manager/manager.rb', line 399 def process_tests_result(agent_ip_address, hardware_specs, tests_result, run_tests_batch_time_start) # Se inicia un semáforo para evitar que varios hilos actualicen variables compartidas @semaphore.synchronize do batch_num = tests_result['batch_num'] tests_result_file_name = tests_result['tests_result_file_name'] status = "processed" # Sólo se procesan las pruebas en estado sent o resent, caso contrario no se avanza con el procesamiento return if (["pending", status]).include?(@tests_batches[batch_num][:status]) tests_result = @tests_result.process(tests_result_file_name) return if tests_result.empty? @unfinished_tests_batches -= 1 files_count = @tests_batches[batch_num][:files_count] @files_processed += files_count batch_runtime = Time.now - run_tests_batch_time_start @tests_running_progress_bar.advance(files_count) @tests_result_bar.advance(1, examples: @tests_result.examples.to_s, passed: @tests_result.passed.to_s, failures: @tests_result.failures.to_s) @tests_running_progress_bar.stop if @unfinished_tests_batches.zero? @tests_batches[batch_num][:status] = status @tests_batches[batch_num][:files_status] = "#{files_count} #{status}" @tests_batches[batch_num][:agent_ip_address] = agent_ip_address @tests_batches[batch_num][:examples] = tests_result[:examples] @tests_batches[batch_num][:passed] = tests_result[:passed] @tests_batches[batch_num][:failures] = tests_result[:failures] @tests_batches[batch_num][:pending] = tests_result[:pending] @tests_batches[batch_num][:failed_files] = tests_result[:failed_files] @tests_batches[batch_num][:files_load] = tests_result[:files_load] @tests_batches[batch_num][:finish_in] = tests_result[:finish_in] @tests_batches[batch_num][:batch_run] = batch_runtime @tests_batches[batch_num][:tests_runtime] = @tests_batches[batch_num][:batch_run] + @tests_batches[batch_num][:share_source_code] @tests_batches[batch_num][:hardware_specs] = hardware_specs Liri.logger.info("Processed unit tests by Agent: #{agent_ip_address}: #{files_count}") end end |
#processed_tests_batches_by_agents ⇒ Object
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'lib/manager/manager.rb', line 469 def processed_tests_batches_by_agents tests_batches = {} files_count = {} @tests_batches.each_value do |processed_test_batch| agent_ip_address = processed_test_batch[:agent_ip_address] status = processed_test_batch[:status] key = "#{agent_ip_address}#{status}" if tests_batches[key] files_count[key] += processed_test_batch[:files_count] tests_batches[key][:files_status] = "#{files_count[key]} #{status}" tests_batches[key][:examples] += processed_test_batch[:examples] tests_batches[key][:passed] += processed_test_batch[:passed] tests_batches[key][:failures] += processed_test_batch[:failures] tests_batches[key][:failed_files] += processed_test_batch[:failed_files] if Manager.show_failed_files_column tests_batches[key][:files_load] += processed_test_batch[:files_load] if Manager.show_files_load_column tests_batches[key][:finish_in] += processed_test_batch[:finish_in] if Manager.show_finish_in_column tests_batches[key][:batch_run] += processed_test_batch[:batch_run] if Manager.show_batch_run_column tests_batches[key][:share_source_code] += processed_test_batch[:share_source_code] if Manager.show_share_source_code_column tests_batches[key][:tests_runtime] += processed_test_batch[:tests_runtime] else files_count[key] = processed_test_batch[:files_count] _processed_test_batch = processed_test_batch.clone # Clone to change values in other hash _processed_test_batch.remove!(:batch_num, :tests_batch_keys, :msg, :files_count, :status, :agent_ip_address, :pending) _processed_test_batch.remove!(:failed_files) unless Manager.show_failed_files_column _processed_test_batch.remove!(:files_load) unless Manager.show_files_load_column _processed_test_batch.remove!(:finish_in) unless Manager.show_finish_in_column _processed_test_batch.remove!(:batch_run) unless Manager.show_batch_run_column _processed_test_batch.remove!(:share_source_code) unless Manager.show_share_source_code_column _processed_test_batch[:files_status] = "#{files_count[key]} #{status}" tests_batches[key] = _processed_test_batch end end tests_batches end |
#processing ⇒ Object
311 312 313 314 315 |
# File 'lib/manager/manager.rb', line 311 def processing @semaphore.synchronize do @unfinished_tests_batches.positive? end end |
#register_agent(agent_ip_address) ⇒ Object
557 558 559 560 |
# File 'lib/manager/manager.rb', line 557 def register_agent(agent_ip_address) @agents[agent_ip_address] = agent_ip_address Liri.logger.info("\nStarted connection with Agent: #{agent_ip_address} in TCP port: #{@tcp_port}") end |
#registered_agent?(agent_ip_address) ⇒ Boolean
553 554 555 |
# File 'lib/manager/manager.rb', line 553 def registered_agent?(agent_ip_address) @agents[agent_ip_address] end |
#start_client_socket_to_search_agents(manager_data) ⇒ Object
Inicia un cliente udp que hace un broadcast en toda la red para iniciar una conexión con los Agent que estén escuchando
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/manager/manager.rb', line 194 def start_client_socket_to_search_agents(manager_data) # El cliente udp se ejecuta en bucle dentro de un hilo, esto permite realizar otras tareas mientras este hilo sigue sondeando # la red para obtener mas Agents. Una vez que los tests terminan de ejecutarse, este hilo será finalizado. Thread.new do Liri.logger.info('Searching agents... Wait') Liri.logger.info("Sending UDP broadcast each #{Manager.udp_request_delay} seconds in UDP port: #{@udp_port}") while processing @udp_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true) @udp_socket.send(manager_data.to_h.to_json, 0, '<broadcast>', @udp_port) sleep(Manager.udp_request_delay) # Se pausa un momento antes de efectuar nuevamente la petición broadcast end end end |
#start_server_socket_to_process_tests(search_agents_thread) ⇒ Object
Inicia un servidor tcp para procesar los pruebas después de haberse iniciado la conexión a través de udp
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/manager/manager.rb', line 209 def start_server_socket_to_process_tests(search_agents_thread) begin tcp_socket = TCPServer.new(@tcp_port) # se hace un bind al puerto dado rescue Errno::EADDRINUSE => e Liri.logger.error("Exception(#{e}) Busy UDP port #{@tcp_port}.") Thread.kill(search_agents_thread) return end Liri.logger.info("Waiting Agents connection in TCP port: #{@tcp_port}") # El siguiente bucle permite que varios clientes es decir Agents se conecten # De: http://www.w3big.com/es/ruby/ruby-socket-programming.html while processing Thread.start(tcp_socket.accept) do |client| agent_ip_address = client.remote_address.ip_address hardware_specs = nil run_tests_batch_time_start = nil share_source_code_time_start = nil = nil while line = client.gets client_data = JSON.parse(line.chop) msg = client_data['msg'] if msg == 'get_source_code' if registered_agent?(agent_ip_address) client.puts({ msg: 'already_connected' }.to_json) client.close break else register_agent(agent_ip_address) update_connected_agents(agent_ip_address) hardware_specs = client_data['hardware_specs'] msg = processing ? 'proceed_get_source_code' : 'no_exist_tests' share_source_code_time_start = Time.now = (hardware_specs, msg) client.puts({ msg: msg }.to_json) end end if msg == 'get_source_code_fail' (hardware_specs, ) client.puts({ msg: 'finish_agent' }.to_json) client.close break end # Primera ejecucion de pruebas if msg == 'get_tests_files' (hardware_specs, ) share_source_code_time_end = Time.now - share_source_code_time_start Liri.logger.info("Running unit tests. Agent: #{agent_ip_address}. Wait... ", false) run_tests_batch_time_start = Time.now update_working_agents(agent_ip_address) tests_batch = tests_batch(agent_ip_address, hardware_specs, share_source_code_time_end) if tests_batch.empty? client.puts({ msg: 'no_exist_tests' }.to_json) client.close break else client.puts(tests_batch.to_json) # Se envia el lote de tests end end # Segunda ejecucion de pruebas y las siguientes ejecuciones if msg == 'processed_tests' tests_result = client_data Liri.logger.debug("Agent response #{agent_ip_address}: #{tests_result}") process_tests_result(agent_ip_address, hardware_specs, tests_result, run_tests_batch_time_start) run_tests_batch_time_start = Time.now tests_batch = tests_batch(agent_ip_address, hardware_specs, 0) if tests_batch.empty? client.puts({ msg: 'no_exist_tests' }.to_json) client.close break else client.puts(tests_batch.to_json) # Se envia el lote de tests end end end Thread.kill(search_agents_thread) rescue Errno::EPIPE => e # Esto al parecer se da cuando el Agent ya cerró las conexiones y el Manager intenta contactar Liri.logger.error("Exception(#{e}) Agent #{agent_ip_address} already finished connection") # Si el Agente ya no responde es mejor terminar el hilo. Aunque igual quedará colgado el Manager # mientras sigan pruebas pendientes Thread.exit end end end |
#start_share_source_code_progress_bar(hardware_specs, msg) ⇒ Object
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/manager/manager.rb', line 580 def (hardware_specs, msg) if msg == 'proceed_get_source_code' && Manager. = @tests_processing_bar.register("Sharing source code |:bar| :percent | Time: :time | Agent: [:agent ]", total: nil, width: 20, bar_format: :box) .start .use(Common::TtyProgressbar::TimeFormatter) Thread.new do animation_count = 0 while !.stopped? .advance(1, agent: hardware_specs) .update(unknown: Common::TtyProgressbar::ANIMATION2[animation_count]) animation_count += 1 animation_count = 0 if animation_count == 3 sleep(0.1) end end end end |
#start_tests_running_progress_bar ⇒ Object
608 609 610 611 612 613 614 615 616 617 618 619 620 |
# File 'lib/manager/manager.rb', line 608 def @semaphore.synchronize do # Es importante hacer un reset acá osino va a contar desde que se instancia y no desde que se inicia la ejecución # del primer test. Solo se resetea si esta paused para evitar que al conectarse con cada Agent se vuelva a resetear @tests_running_progress_bar.reset if @tests_running_progress_bar.paused? Thread.new do while !@tests_running_progress_bar.stopped? @tests_running_progress_bar.advance(0) sleep(0.1) # Es importante que las otras barras tambien tengan el mismo sleep para que sean mas consistentes en sus resultados end end end end |
#stop_share_source_code_progress_bar(hardware_specs, share_source_code_progress_bar) ⇒ Object
601 602 603 604 605 606 |
# File 'lib/manager/manager.rb', line 601 def (hardware_specs, ) if Manager. .update(total: 1, agent: hardware_specs) .stop end end |
#summary_footer ⇒ Object
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/manager/manager.rb', line 536 def hash = {} hash[:batch_num] = "" hash[:files_status] = "#{@tests_files_count} in total" hash[:examples] = @tests_result.examples hash[:passed] = @tests_result.passed hash[:failures] = @tests_result.failures hash[:failed_files] = "" if Manager.show_failed_files_column hash[:files_load] = "" if Manager.show_files_load_column hash[:finish_in] = "" if Manager.show_finish_in_column hash[:batch_run] = "" if Manager.show_batch_run_column hash[:share_source_code] = "" if Manager.show_share_source_code_column hash[:tests_runtime] = "" hash[:hardware_specs] = "" hash end |
#tests_batch(agent_ip_address, hardware_specs, share_source_code_time_end) ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/manager/manager.rb', line 352 def tests_batch(agent_ip_address, hardware_specs, share_source_code_time_end) # Se inicia un semáforo para evitar que varios hilos actualicen variables compartidas @semaphore.synchronize do return {} if @unfinished_tests_batches.zero? tests_batch = {} pending_tests_batch = {} sent_tests_batch = {} @tests_batches.each_value do |batch| if batch[:status] == "pending" pending_tests_batch = batch break elsif batch[:status] == "sent" sent_tests_batch = batch # Es importante que este no tenga un break para guardar el ultimo enviado # el cual tiene menos probabilidades de terminar de ejecutarse rapido end end # Es importante setear el status y el hardware_spec solo si los hashes no estan vacios # Porque si estan vacios significa que ya no hay tests que ejecutar, y si seteamos algun valor en el hash # estando este vacio entonces se tratara de ejecutar algo sin los datos suficientes y fallara if pending_tests_batch.any? tests_batch = pending_tests_batch tests_batch[:status] = "sent" tests_batch[:agent_ip_address] = agent_ip_address tests_batch[:hardware_specs] = hardware_specs elsif sent_tests_batch.any? tests_batch = sent_tests_batch tests_batch[:status] = "resent" tests_batch[:agent_ip_address] = agent_ip_address tests_batch[:hardware_specs] = hardware_specs end return {} if tests_batch.empty? tests_batch[:agent_ip_address] = agent_ip_address tests_batch[:share_source_code] = share_source_code_time_end Liri.logger.debug("Tests batches sent to Agent #{agent_ip_address}: #{tests_batch}") # se devuelve el hash con los datos que se enviarán al agente, por eso, primero se remueven los datos innecesarios tests_batch.remove(:files_count, :status, :files_status, :agent_ip_address, :examples, :passed, :failures, :pending, :failed_files, :files_load, :finish_in, :batch_run, :share_source_code, :tests_runtime, :hardware_specs) end end |
#to_duration(value) ⇒ Object
622 623 624 |
# File 'lib/manager/manager.rb', line 622 def to_duration(value) Common::Duration.humanize(value, times_round: Liri.times_round, times_round_type: Liri.times_round_type) end |
#update_agents_bar ⇒ Object
576 577 578 |
# File 'lib/manager/manager.rb', line 576 def @agents_bar.advance(1, connected: @connected_agents.size.to_s, working: @working_agents.size.to_s) end |
#update_connected_agents(agent_ip_address) ⇒ Object
562 563 564 565 566 567 |
# File 'lib/manager/manager.rb', line 562 def update_connected_agents(agent_ip_address) unless @connected_agents[agent_ip_address] @connected_agents[agent_ip_address] = agent_ip_address end end |
#update_working_agents(agent_ip_address) ⇒ Object
569 570 571 572 573 574 |
# File 'lib/manager/manager.rb', line 569 def update_working_agents(agent_ip_address) unless @working_agents[agent_ip_address] @working_agents[agent_ip_address] = agent_ip_address end end |