示例#1
0
文件: api.py 项目: mrj0/chimney
    def process_changes(self, reload_patterns=None, restart_patterns=None):
        batch = self.changes
        self.changes = []
        for obs in set(batch):
            if obs.type in ('created', 'deleted',):
                for p in restart_patterns or []:
                    if fnmatch.fnmatch(obs.path, p):
                        return Maker.EXIT

                if reload_patterns is None:
                    log.info(u'File %s: %s, reloading', obs.type, obs.path)
                    return Maker.RELOAD

                for p in reload_patterns:
                    if fnmatch.fnmatch(obs.path, p):
                        log.info(u'File %s: %s, reloading', obs.type, obs.path)
                        return Maker.RELOAD

            if obs.type != 'modified':
                continue

            for task in (self.by_source.get(os.path.abspath(obs.path)) or []):
                log.info('Detected %s: %s', obs.type, obs.path)
                runner = Runner(task)
                runner.schedule(self.executor)

        return None
示例#2
0
def test_runner():
    """
    verify that runners depending on other runners works as expected
    """
    executor = MockExecutor()
    runner_a = Runner(Mock())
    runner_b = Runner(Mock())
    runner_c = Runner(Mock())

    runner_b.waiting_for.append(runner_a)
    runner_c.waiting_for.append(runner_a)
    runner_c.waiting_for.append(runner_b)

    runner_c.schedule(executor)
    assert not runner_c.future.done(), 'c should not have run yet'

    runner_b.schedule(executor)
    assert not runner_b.future.done(), 'b should not have run yet'

    runner_a.schedule(executor)
    assert runner_a.future.done(), 'a should have run'
    runner_b.schedule(executor)
    assert runner_b.future.done(), 'b should have run'
    runner_c.schedule(executor)
    assert runner_c.future.done(), 'c should have run'