예제 #1
0
def start_heartbeat(heartbeat_command):
  """Start the heartbeat (in another process)."""
  global _heartbeat_handle
  if _heartbeat_handle:
    # If heartbeat is already started, no work to do. Bail out.
    return

  try:
    command, arguments = shell.get_command_and_arguments(heartbeat_command)
    process_handle = mozprocess.ProcessHandlerMixin(command, arguments)
    process_handler.start_process(process_handle)
  except Exception:
    logs.log_error(
        'Unable to start heartbeat process (%s).' % heartbeat_command)
    return

  # If heartbeat is successfully started, set its handle now.
  _heartbeat_handle = process_handle

  # Artificial delay to let heartbeat's start time update first.
  sleep(HEARTBEAT_START_WAIT_TIME)
예제 #2
0
def start_bot(bot_command):
    """Start the bot process."""
    command, arguments = shell.get_command_and_arguments(bot_command)
    store_output = mozprocess.processhandler.StoreOutput()

    try:
        process_handle = mozprocess.ProcessHandlerMixin(
            command,
            arguments,
            kill_on_timeout=True,
            processOutputLine=[store_output])
        process_handler.start_process(process_handle)
    except Exception:
        logs.log_error('Unable to start bot process (%s).' % bot_command)
        return 1

    # Wait until the process terminates or until run timed out.
    run_timeout = environment.get_value('RUN_TIMEOUT')
    exit_code = process_handle.wait(timeout=run_timeout)
    try:
        process_handle.kill()
    except Exception:
        pass

    log_message = (
        'Command: %s %s (exit=%s)\n%s' %
        (command, arguments, exit_code, '\n'.join(store_output.output)))

    if exit_code == 0:
        logs.log(log_message)
    elif exit_code == 1:
        # Anecdotally, exit=1 means there's a fatal Python exception.
        logs.log_error(log_message)
    else:
        logs.log_warn(log_message)

    return exit_code