Esempio n. 1
0
    def process(self, baton):
        value = util.dict_get_path(baton, self.counter_path)
        delta = util.dict_get_path(baton, self.delta_path)
        rate = value / delta

        log_string = self.format % dict(rate=rate, delta=delta, value=value)
        if(rate != 0 or self.report_zero):
            log.info(log_string)
        return baton
Esempio n. 2
0
    def processEnded(self, reason):
        if reason.value == error.ProcessDone:
            log.info('Process %s terminated normally.'%self.process_name)
        else:
            log.warn('Process %s terminated with exit code %s.'%(self.process_name, reason.value.exitCode))

        for protocol in self.stdout_protocol, self.stderr_protocol, self.stdin_protocol:
            protocol.processEnded(reason)

        if self.restart:
            reactor.callLater(self.restart_wait, self.spawn_process)
Esempio n. 3
0
    def keep_connecting(self):
        self.retries = 0
        self.delay = self.initial_delay

        while self.running:
            try:
                yield self.client.connect(self)
            except error.ConnectError as e:
                pass
            else:
                self._connecting = None
                break

            self.retries += 1
            if self.max_retries is not None and (self.retries > self.max_retries):
                log.info("Abandoning %s after %d retries." %(self.client, self.retries))
                break

            self.delay = min(self.delay * self.factor, self.max_delay)
            if self.jitter:
                self.delay = random.normalvariate(self.delay, self.delay * self.jitter)

            log.info("%s will retry in %d seconds" % (self.client, self.delay,))
            yield util.wait(self.delay)
Esempio n. 4
0
            return

        self._should_reflect = reflect

        self._configure_driver()
        self._make_metadata(existing_metadata)

        try:
            self._try_connecting()
        except sa.exc.SQLAlchemyError, e:
            log.error('Could not connect to database "%s": %s' % (self.database_name, e))
            reactor.callFromThread(self.on_connection_failed, failure.Failure())
            raise
        else:
            self.is_connected = True
            log.info('Connected to database "%s"' % self.database_name)
            reactor.callFromThread(self.on_connection_established, self.metadata)

    def _configure_driver(self):
        if self.protocol == 'postgresql':
            self._configure_postgres()
        else:
            self._configure_mysql()

    def _configure_mysql(self):
        """ Configure a MySQL engine. """
        self.port = self.database_configuration.get('port', 3306)

        self.dbapi_options.setdefault('connect_timeout', self.timeout)

        # Unicode dammit! :)
Esempio n. 5
0
 def _configure_connects(self):
     for socket, connect_specs in self._sockets_to_connect:
         for connect_spec in connect_specs:
             log.info('Connecting %s to %s.'%(self._name_by_socket[socket], connect_spec))
             socket.connect(connect_spec)
     self._sockets_to_connect = []
Esempio n. 6
0
 def _configure_binds(self):
     for socket, bind_specs in self._sockets_to_bind:
         for bind_spec in bind_specs:
             log.info('Binding %s to %s.'%(self._name_by_socket[socket], bind_spec))
             socket.bind(bind_spec)
     self._sockets_to_bind = []
Esempio n. 7
0
 def connectionMade(self):
     log.info('Process %s has started.'%self.process_name)
     for protocol in self.stdout_protocol, self.stderr_protocol, self.stdin_protocol:
         protocol.connectionMade()