Exemplo n.º 1
0
    def setUp(self):
        """
        Create a FeedPollerService with a mock agent, TimerService,
        and cooperator that do not use the real reactor
        """
        self.handler = mock.Mock()
        self.agent = mock.Mock(Agent)
        self.timer = mock.Mock(TimerService)

        self.cooperator = Cooperator(scheduler=lambda x: x(), started=True)

        self.poller = FeedPollerService(self.agent,
                                        'http://example.com/feed',
                                        [self.handler],
                                        TimerService=self.timer,
                                        coiterate=self.cooperator.coiterate)

        self.poll = self.timer.mock_calls[0][1][1]
Exemplo n.º 2
0
def makeService(config):
    """
    Make the FeedPollerService that will polling AtomHopper.
    """
    s = MultiService()

    config = json.loads(open(config['config']).read())

    agent = Agent(reactor, pool=HTTPConnectionPool(reactor, persistent=True))

    for service_name, service_desc in config['services'].iteritems():
        for url in service_desc['urls']:
            fps = FeedPollerService(
                agent,
                str(url),
                [namedAny(h) for h in service_desc.get('event_handlers', [])],
                state_store=FileStateStore(hashlib.md5(url).hexdigest()))
            fps.setServiceParent(s)

    return s