def main(config): logging.basicConfig(level=logging.INFO) if isinstance(config, str): config = ConfigEngine(config) # Schedule configured periodic tasks periodic_tasks_names = [ x for x in config.get_sections() if x.startswith("PeriodicTask_") ] for p_task in periodic_tasks_names: if not config.get_boolean(p_task, "Enabled"): continue task_name = config.get_section_dict(p_task).get("Name") if task_name == "metrics": logger.info("Metrics enabled!") schedule.every().day.at("00:01").do(compute_daily_metrics, config=config) schedule.every().hour.at(":01").do(compute_hourly_metrics, config=config) live_interval = int( config.get_section_dict(p_task).get("LiveInterval", 10)) schedule.every(live_interval).minutes.do( compute_live_metrics, config=config, live_interval=live_interval) else: raise ValueError(f"Not supported periodic task named: {task_name}") # Schedule daily/weekly reports for sources and areas sources = config.get_video_sources() areas = config.get_areas() for src in sources: if src['daily_report']: schedule.every().day.at(src['daily_report_time']).do( send_daily_report_notification, config=config, entity_info=src) for area in areas: if area['daily_report']: schedule.every().day.at(area['daily_report_time']).do( send_daily_report_notification, config=config, entity_info=area) if config.get_boolean("App", "DailyGlobalReport"): schedule.every().day.at( config.get_section_dict("App")["GlobalReportTime"]).do( send_daily_global_report, config=config, sources=sources, areas=areas) if config.get_boolean("App", "WeeklyGlobalReport"): schedule.every(7).days.at( config.get_section_dict("App")["GlobalReportTime"]).do( send_weekly_global_report, config=config, sources=sources, areas=areas) while True: schedule.run_pending() time.sleep(10)
def main(config): logging.basicConfig(level=logging.INFO) if isinstance(config, str): config = ConfigEngine(config) if not config.get_boolean('Logger', 'EnableReports'): logger.info("Reporting disabled!") else: logger.info("Reporting enabled!") schedule.every().day.at("00:01").do(create_daily_report, config=config) sources = config.get_video_sources() areas = config.get_areas() for src in sources: if src['daily_report']: schedule.every().day.at(src['daily_report_time']).do( send_daily_report_notification, config=config, entity_info=src) for area in areas: if area['daily_report']: schedule.every().day.at(area['daily_report_time']).do( send_daily_report_notification, config=config, entity_info=area) while True: schedule.run_pending() time.sleep(10)