Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Swarming bot main process. | 5 """Swarming bot main process. |
| 6 | 6 |
| 7 This is the program that communicates with the Swarming server, ensures the code | 7 This is the program that communicates with the Swarming server, ensures the code |
| 8 is always up to date and executes a child process to run tasks and upload | 8 is always up to date and executes a child process to run tasks and upload |
| 9 results back. | 9 results back. |
| 10 | 10 |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 def poll_server(botobj, quit_bit): | 511 def poll_server(botobj, quit_bit): |
| 512 """Polls the server to run one loop. | 512 """Polls the server to run one loop. |
| 513 | 513 |
| 514 Returns True if executed some action, False if server asked the bot to sleep. | 514 Returns True if executed some action, False if server asked the bot to sleep. |
| 515 """ | 515 """ |
| 516 # Access to a protected member _XXX of a client class - pylint: disable=W0212 | 516 # Access to a protected member _XXX of a client class - pylint: disable=W0212 |
| 517 start = time.time() | 517 start = time.time() |
| 518 resp = botobj.remote.url_read_json( | 518 resp = botobj.remote.url_read_json( |
| 519 '/swarming/api/v1/bot/poll', data=botobj._attributes) | 519 '/swarming/api/v1/bot/poll', data=botobj._attributes) |
| 520 if not resp: | 520 if not resp: |
| 521 # Back off on failure. | |
| 522 time.sleep(min(1, max(60, botobj.state.get('sleep_streak', 10) * 2))) | |
|
Vadim Sh.
2016/07/26 17:56:13
this will always be time.sleep(1)
M-A Ruel
2016/07/28 15:26:04
Apologies for making you go through this. Fixed.
| |
| 521 return False | 523 return False |
| 522 logging.debug('Server response:\n%s', resp) | 524 logging.debug('Server response:\n%s', resp) |
| 523 | 525 |
| 524 cmd = resp['cmd'] | 526 cmd = resp['cmd'] |
| 525 if cmd == 'sleep': | 527 if cmd == 'sleep': |
| 526 quit_bit.wait(resp['duration']) | 528 quit_bit.wait(resp['duration']) |
| 527 return False | 529 return False |
| 528 | 530 |
| 529 if cmd == 'terminate': | 531 if cmd == 'terminate': |
| 530 quit_bit.set() | 532 quit_bit.set() |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 | 872 |
| 871 error = None | 873 error = None |
| 872 if len(args) != 0: | 874 if len(args) != 0: |
| 873 error = 'Unexpected arguments: %s' % args | 875 error = 'Unexpected arguments: %s' % args |
| 874 try: | 876 try: |
| 875 return run_bot(error) | 877 return run_bot(error) |
| 876 finally: | 878 finally: |
| 877 call_hook(bot.Bot(None, None, None, None, os.path.dirname(THIS_FILE), None), | 879 call_hook(bot.Bot(None, None, None, None, os.path.dirname(THIS_FILE), None), |
| 878 'on_bot_shutdown') | 880 'on_bot_shutdown') |
| 879 logging.info('main() returning') | 881 logging.info('main() returning') |
| OLD | NEW |