Ejemplo n.º 1
0
    def start(self) -> None:
        self.title()
        self.readConfiguration()
        (Stream.of(self.modules.values()).sorted(
            key=lambda task: task.priority).each(lambda task: self.every(
                task.name,
                self.configuration('immediately',
                                   name=task.name,
                                   default=task.immediately),
                self.configuration('interval',
                                   name=task.name,
                                   default=task.interval,
                                   convert=lambda v: Stream.ifelse(
                                       v, alternator=task.interval)), task.
                priority, task(self), ())))

        def configurator() -> bool:
            self.readConfiguration()
            return True

        def stopper() -> bool:
            while self.control.running:
                if self.wait() is None:
                    break
            if not self.control.running and not self.deferred:
                self.stop()
                return False
            return True

        self.every('reload', False, '1h', 0, configurator, ())
        self.every('restart', False, '24h', 0, stopper, ())
        super().start()
Ejemplo n.º 2
0
 def readConfiguration(self) -> None:
     ccfg = CompanyConfig()
     ccfg.read()
     self.config = (Stream(
         ccfg.scan_config(
             class_names=['generate'],
             single_value=True)).map(lambda cv: (cv.name, cv.value)).dict())
     self.companies = self.configuration(
         'companies', convert=lambda v: Stream.ifelse(Range(v)))
     if self.companies:
         logger.info('Limit operations on these companies: %s' %
                     self.companies)