Start the bot process.
(bot_command)
| 47 | |
| 48 | |
| 49 | def start_bot(bot_command): |
| 50 | """Start the bot process.""" |
| 51 | command = shell.get_command(bot_command) |
| 52 | |
| 53 | # Wait until the process terminates or until run timed out. |
| 54 | run_timeout = environment.get_value('RUN_TIMEOUT') |
| 55 | if run_timeout and run_timeout > MAX_SUBPROCESS_TIMEOUT: |
| 56 | logs.error( |
| 57 | 'Capping RUN_TIMEOUT to max allowed value: %d' % MAX_SUBPROCESS_TIMEOUT) |
| 58 | run_timeout = MAX_SUBPROCESS_TIMEOUT |
| 59 | |
| 60 | try: |
| 61 | result = subprocess.run( |
| 62 | command, |
| 63 | timeout=run_timeout, |
| 64 | stdout=subprocess.PIPE, |
| 65 | stderr=subprocess.STDOUT, |
| 66 | check=False) |
| 67 | exit_code = result.returncode |
| 68 | output = result.stdout |
| 69 | except subprocess.TimeoutExpired as e: |
| 70 | exit_code = 0 |
| 71 | output = e.stdout |
| 72 | except Exception: |
| 73 | logs.error('Unable to start bot process (%s).' % bot_command) |
| 74 | return 1 |
| 75 | |
| 76 | if output: |
| 77 | output = output.decode('utf-8', errors='ignore') |
| 78 | log_message = f'Command: {command} (exit={exit_code})\n{output}' |
| 79 | |
| 80 | if exit_code == 0: |
| 81 | logs.info(log_message) |
| 82 | elif exit_code == 1: |
| 83 | # Anecdotally, exit=1 means there's a fatal Python exception. |
| 84 | logs.error(log_message) |
| 85 | else: |
| 86 | logs.warning(log_message) |
| 87 | |
| 88 | return exit_code |
| 89 | |
| 90 | |
| 91 | def sleep(seconds): |
no test coverage detected