async def spawn_job(app): scheduler = get_scheduler_from_app(self.cbpi.app) for method in [ getattr(obj, f) for f in dir(obj) if callable(getattr(obj, f)) and hasattr(getattr(obj, f), "background_task") ]: name = method.__getattribute__("name") interval = method.__getattribute__("interval") job = await scheduler.spawn( job_loop(self.app, name, interval, method), name, "background")
async def init_sensor(self, sensor): if sensor.type in self.types: cfg = sensor.config.copy() cfg.update(dict(cbpi=self.cbpi, id=sensor.id, name=sensor.name)) clazz = self.types[sensor.type]["class"]; self.cache[sensor.id].instance = clazz(**cfg) self.cache[sensor.id].instance.init() scheduler = get_scheduler_from_app(self.cbpi.app) self.cache[sensor.id].instance.job = await scheduler.spawn(self.cache[sensor.id].instance.run(self.cbpi), sensor.name, "sensor") await self.cbpi.bus.fire(topic="sensor/%s/initialized" % sensor.id, id=sensor.id) else: self.logger.error("Sensor type '%s' not found (Available Sensor Types: %s)" % (sensor.type, ', '.join(self.types.keys())))
def get_all_jobs(self, request): """ --- description: Get all running Jobs tags: - System responses: "200": description: successful operation """ scheduler = get_scheduler_from_app(self.cbpi.app) result = [] for j in scheduler: try: result.append(dict(name=j.name, type=j.type, time=j.start_time)) except: pass return web.json_response(data=result)
async def start_job(self, method, name, type): scheduler = get_scheduler_from_app(self.cbpi.app) return await scheduler.spawn(method, name, type)
def _is_logic_running(self, kettle_id): scheduler = get_scheduler_from_app(self.cbpi.app)