Esempio n. 1
0
    def __init__(self, config, ioloop=None):
        if config['system_type'] == 'twisted':
            raise NotImplemented('Twisted Matrix support is planned for the'
                                 ' future.')
        self.config = config

        # Sane defaults
        if 'mongodb' not in self.config:
            self.config['mongodb'] = {}
        if 'host' not in self.config['mongodb']:
            self.config['mongodb']['host'] = 'localhost'
        if 'dbname' not in self.config['mongodb']:
            self.config['mongodb']['dbname'] = 'skyhooks'
        if 'mongo_collection' not in self.config:
            self.config['mongodb_collection'] = 'skyhooks_webhooks'

        if ioloop is None:
            self.ioloop = IOLoop(config['system_type'])
        else:
            self.ioloop = ioloop

        if self.config['system_type'] == 'tornado':
            import motor
            db_name = self.config['mongodb'].pop('dbname')
            client = motor.MotorClient(**self.config['mongodb'])
            self.db = client[db_name]

        elif self.config['system_type'] == 'gevent':
            import pymongo
            db_name = self.config['mongodb'].pop('dbname')
            self.db = pymongo.Connection(pool_id='skyhooks',
                    use_greenlets=True,
                    **self.config['mongodb'])[db_name]

        self.collection = self.db[self.config['mongodb_collection']]
Esempio n. 2
0
    def __init__(self, config=None, **kwargs):

        self.logger = logging.getLogger('skyhooks')

        if config is None:
            config = {}
        config.update(kwargs)

        if 'url' not in config:
            raise AttributeError('Please provide a webhook URL')

        if 'system_type' not in config:
            raise AttributeError('Please set the system_type to either gevent '
                                 'or tornado')

        elif config['system_type'] == 'twisted':
            raise NotImplemented('Twisted Matrix support is planned for the'
                                 ' future')

        self.config = config
        self.url = config['url']
        self.ioloop = IOLoop(config['system_type'])

        if self.config.get('auto_renew', True):
            if 'renew_seconds' not in self.config:
                self.config['renew_seconds'] = 120

            self.queue_renew_all()