def start(self, interval=defaults.START_INTERVAL, timeout=defaults.START_TIMEOUT, delete_amqp_queue=defaults.DELETE_AMQP_QUEUE_BEFORE_START): """ Starts the daemon process. :param interval: the interval in seconds to sleep when waiting for the daemon to be ready. :param timeout: the timeout in seconds to wait for the daemon to be ready. :param delete_amqp_queue: delete any queues with the name of the current daemon queue in the broker. :raise DaemonStartupTimeout: in case the agent failed to start in the given amount of time. :raise DaemonException: in case an error happened during the agent startup. """ if delete_amqp_queue: self._logger.debug('Deleting AMQP queues') self._delete_amqp_queues() start_command = self.start_command() self._logger.info( 'Starting daemon with command: {0}'.format(start_command)) self._runner.run(start_command) end_time = time.time() + timeout while time.time() < end_time: self._logger.debug('Querying daemon {0} registered tasks'.format( self.name)) if self._is_agent_registered(): # make sure the status command recognizes the daemon is up status = self.status() if status: self._logger.debug('Daemon {0} has started'.format( self.name)) return self._logger.debug('Daemon {0} has not started yet. ' 'Sleeping for {1} seconds...'.format( self.name, interval)) time.sleep(interval) self._logger.debug('Verifying there were no un-handled ' 'exception during startup') self._verify_no_celery_error() raise exceptions.DaemonStartupTimeout(timeout, self.name)
def start(self, interval=defaults.START_INTERVAL, timeout=defaults.START_TIMEOUT, delete_amqp_queue=defaults.DELETE_AMQP_QUEUE_BEFORE_START): """ Starts the daemon process. :param interval: the interval in seconds to sleep when waiting for the daemon to be ready. :param timeout: the timeout in seconds to wait for the daemon to be ready. :param delete_amqp_queue: delete any queues with the name of the current daemon queue in the broker. :raise DaemonStartupTimeout: in case the agent failed to start in the given amount of time. :raise DaemonException: in case an error happened during the agent startup. """ if delete_amqp_queue: self._logger.warning('Deprecation warning:\n' 'The `delete_amqp_queue` param is no ' 'longer used, and it is only left for ' 'backwards compatibility') start_command = self.start_command() self._logger.info( 'Starting daemon with command: {0}'.format(start_command)) self._runner.run(start_command) end_time = time.time() + timeout while time.time() < end_time: if self._is_daemon_running(): return self._logger.debug('Daemon {0} is still not running. ' 'Sleeping for {1} seconds...'.format( self.name, interval)) time.sleep(interval) self._verify_no_error() raise exceptions.DaemonStartupTimeout(timeout, self.name)