first commit
This commit is contained in:
40
scheduler.py
Normal file
40
scheduler.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import time
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from cve_handler import update_all_vendors
|
||||
import config
|
||||
|
||||
logging.basicConfig(
|
||||
level=config.LOG_LEVEL,
|
||||
format=config.LOG_FORMAT
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def run_scheduler():
|
||||
logger.info("CVE Update Scheduler started")
|
||||
logger.info(f"Update interval: {config.UPDATE_INTERVAL_HOURS} hours")
|
||||
logger.info(f"Auto-update enabled: {config.ENABLE_AUTO_UPDATE}")
|
||||
|
||||
time.sleep(120)
|
||||
|
||||
while True:
|
||||
if config.ENABLE_AUTO_UPDATE:
|
||||
try:
|
||||
logger.info(f"Starting scheduled update at {datetime.now()}")
|
||||
updated, failed = update_all_vendors()
|
||||
logger.info(f"Update completed: {updated} successful, {failed} failed")
|
||||
except Exception as e:
|
||||
logger.error(f"Error in scheduled update: {e}", exc_info=True)
|
||||
else:
|
||||
logger.debug("Auto-update is disabled, skipping")
|
||||
|
||||
sleep_seconds = config.UPDATE_INTERVAL_HOURS * 3600
|
||||
next_update = datetime.now().timestamp() + sleep_seconds
|
||||
logger.info(f"Next update scheduled at {datetime.fromtimestamp(next_update)}")
|
||||
time.sleep(sleep_seconds)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_scheduler()
|
||||
Reference in New Issue
Block a user