OLD | NEW |
1 # Copyright 2013 The Swarming Authors. All rights reserved. | 1 # Copyright 2013 The Swarming Authors. All rights reserved. |
2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Runs a Swarming task. | 5 """Runs a Swarming task. |
6 | 6 |
7 Downloads all the necessary files to run the task, executes the command and | 7 Downloads all the necessary files to run the task, executes the command and |
8 streams results back to the Swarming server. | 8 streams results back to the Swarming server. |
9 | 9 |
10 The process exit code is 0 when the task was executed, even if the task itself | 10 The process exit code is 0 when the task was executed, even if the task itself |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 405 |
406 # This is the very last packet for this command. It if was an isolated task, | 406 # This is the very last packet for this command. It if was an isolated task, |
407 # include the output reference to the archived .isolated file. | 407 # include the output reference to the archived .isolated file. |
408 now = monotonic_time() | 408 now = monotonic_time() |
409 params['cost_usd'] = cost_usd_hour * (now - task_start) / 60. / 60. | 409 params['cost_usd'] = cost_usd_hour * (now - task_start) / 60. / 60. |
410 params['duration'] = now - start | 410 params['duration'] = now - start |
411 params['io_timeout'] = had_io_timeout | 411 params['io_timeout'] = had_io_timeout |
412 params['hard_timeout'] = had_hard_timeout | 412 params['hard_timeout'] = had_hard_timeout |
413 if isolated_result: | 413 if isolated_result: |
414 try: | 414 try: |
| 415 # See run_isolated.py for the format. |
415 with open(isolated_result, 'rb') as f: | 416 with open(isolated_result, 'rb') as f: |
416 params['outputs_ref'] = json.load(f) | 417 run_isolated_result = json.load(f) |
| 418 logging.debug('run_isolated:\n%s', run_isolated_result) |
| 419 # TODO(maruel): Grab statistics (cache hit rate, data downloaded, |
| 420 # mapping time, etc) from run_isolated and push them to the server. |
| 421 params['outputs_ref'] = run_isolated_result['outputs_ref'] |
| 422 if run_isolated_result['internal_failure']: |
| 423 must_signal_internal_failure = run_isolated_result['internal_failure'] |
| 424 logging.error('%s', must_signal_internal_failure) |
| 425 elif exit_code: |
| 426 # TODO(maruel): Grab stdout from run_isolated. |
| 427 must_signal_internal_failure = ( |
| 428 'run_isolated internal failure %d' % exit_code) |
| 429 logging.error('%s', must_signal_internal_failure) |
| 430 exit_code = run_isolated_result['exit_code'] |
417 except (IOError, OSError, ValueError) as e: | 431 except (IOError, OSError, ValueError) as e: |
418 logging.error('Swallowing error: %s' % e) | 432 logging.error('Swallowing error: %s', e) |
| 433 # TODO(maruel): Send the internal failure here instead of sending it through |
| 434 # bot_main, this causes a race condition. |
419 post_update(swarming_server, params, exit_code, stdout, output_chunk_start) | 435 post_update(swarming_server, params, exit_code, stdout, output_chunk_start) |
420 return { | 436 return { |
421 u'exit_code': exit_code, | 437 u'exit_code': exit_code, |
422 u'hard_timeout': had_hard_timeout, | 438 u'hard_timeout': had_hard_timeout, |
423 u'io_timeout': had_io_timeout, | 439 u'io_timeout': had_io_timeout, |
424 u'must_signal_internal_failure': must_signal_internal_failure, | 440 u'must_signal_internal_failure': must_signal_internal_failure, |
425 u'version': OUT_VERSION, | 441 u'version': OUT_VERSION, |
426 } | 442 } |
427 finally: | 443 finally: |
428 if isolated_result: | 444 if isolated_result: |
(...skipping 27 matching lines...) Expand all Loading... |
456 if options.start > now: | 472 if options.start > now: |
457 options.start = now | 473 options.start = now |
458 | 474 |
459 try: | 475 try: |
460 load_and_run( | 476 load_and_run( |
461 options.in_file, remote, options.cost_usd_hour, options.start, | 477 options.in_file, remote, options.cost_usd_hour, options.start, |
462 options.out_file) | 478 options.out_file) |
463 return 0 | 479 return 0 |
464 finally: | 480 finally: |
465 logging.info('quitting') | 481 logging.info('quitting') |
OLD | NEW |