コード例 #1
0
 def test_call_later_cancel(self):
     self.called = 0
     reactor = Clock()
     call = CallLaterOnce(self.call_function, reactor=reactor)
     call.schedule(delay=1)
     call.cancel()
     reactor.advance(1)
     assert self.called == 0
コード例 #2
0
ファイル: test_utils_async.py プロジェクト: zhodj/frontera
 def test_call_later_cancel(self):
     self.called = 0
     reactor = Clock()
     call = CallLaterOnce(self.call_function, reactor=reactor)
     call.schedule(delay=1)
     call.cancel()
     reactor.advance(1)
     assert self.called == 0
コード例 #3
0
ファイル: db.py プロジェクト: hybridious/frontera
class Slot(object):
    def __init__(self, new_batch, consume_incoming, consume_scoring,
                 no_batches, no_scoring_log, new_batch_delay, no_spider_log):
        self.new_batch = CallLaterOnce(new_batch)
        self.new_batch.setErrback(self.error)

        self.consumption = CallLaterOnce(consume_incoming)
        self.consumption.setErrback(self.error)

        self.scheduling = CallLaterOnce(self.schedule)
        self.scheduling.setErrback(self.error)

        self.scoring_consumption = CallLaterOnce(consume_scoring)
        self.scoring_consumption.setErrback(self.error)

        self.no_batches = no_batches
        self.no_scoring_log = no_scoring_log
        self.no_spider_log = no_spider_log
        self.new_batch_delay = new_batch_delay

    def error(self, f):
        logger.exception(f.value)
        return f

    def schedule(self, on_start=False):
        if on_start and not self.no_batches:
            self.new_batch.schedule(0)

        if not self.no_spider_log:
            self.consumption.schedule()
        if not self.no_batches:
            self.new_batch.schedule(self.new_batch_delay)
        if not self.no_scoring_log:
            self.scoring_consumption.schedule()
        self.scheduling.schedule(5.0)

    def cancel(self):
        self.scheduling.cancel()
        self.scoring_consumption.cancel()
        self.new_batch.cancel()
        self.consumption.cancel()