Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Side by Side Diff: appengine/swarming/swarming_bot/bot_code/bot_main.py

Issue 2181343002: swarming: Back off requests on poll failure. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: Math is hard Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(max(1, min(60, botobj.state.get('sleep_streak', 10) * 2)))
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
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')
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698