Esempio n. 1
0
  def app_main(self, config, options, args):
    logging.info("Beginning...")

    # read the db url from the config
    db_url = db.create_url_from_config(config['db'])
    # get the broker and queue config
    broker_url = message_queue.create_url_from_config(config['amqp']['broker'])
    # get the maximum priority
    max_priority = int(config['scanner']['maximum_priority'])
    min_duration = float(config['scanner']['iteration_minimum_duration'])
    min_duration = datetime.timedelta(seconds=min_duration)

    # initialize the db engine & session
    db.configure_session(db_url)
    service.initialize()
    post_type.initialize()

    # Create event processor
    self.processor = event_processor.EventProcessor(
        max_priority,
        min_duration,
        config['oauth'])

    logging.info('Queue broker URL: %s', broker_url)

    # get message broker client and store in instance -- used for both receiving and sending
    self.client = message_queue.create_message_client(broker_url)
    message_queue.create_queues_from_config(self.client, config['amqp'])

    message_queue.join(
        self.client,
        config['amqp']['queues']['processor']['queue'],
        self.handler)

    logging.info("Finished...")
Esempio n. 2
0
  def app_main(self, config, options, args):
    # TODO: deal with new user registrations by listening to amqp and schedule the rest

    observer = PythonLoggingObserver()
    observer.start()

    # initialize some important maps
    db.configure_session(db.create_url_from_config(config['db']))
    service.initialize()
    post_type.initialize()

    # Grab twitter consumer keys
    self.consumer_key = config['oauth']['twitter']['key']
    self.consumer_secret = config['oauth']['twitter']['secret']
    self.default_token_key = config['oauth']['twitter']['default_access_token']
    self.default_token_secret = config['oauth']['twitter']['default_access_token_secret']

    # Grab feed configuration
    self.wait_on_collector_query_delay = float(config['feed']['wait_on_collector_query_delay'])

    # Configure amqp
    amqp_host = config['amqp']['broker']['host']
    amqp_port = int(config['amqp']['broker']['port'])
    amqp_spec = message_queue.create_spec_path(config['amqp']['broker']['spec'])
    self.amqp_exchange = config['amqp']['exchange']['name']

    self.amqp = AmqpFactory(host=amqp_host, port=amqp_port, spec_file=amqp_spec)

    db_host = config['db']['host']
    db_user = config['db']['user']
    db_passwd = config['db']['password']
    db_database = config['db']['database']
    db_unicode = to_bool(config['db']['unicode'])

    self.db_pool = adbapi.ConnectionPool(
        'MySQLdb',
        host=db_host,
        user=db_user,
        passwd=db_passwd,
        db=db_database,
        use_unicode=db_unicode,
        cp_noisy=True)
    self._process_twitter_users()

    reactor.run()