From bd812ca5caae70a6bfa7c81cabfca00bbe90cbac Mon Sep 17 00:00:00 2001 From: grabowski Date: Fri, 26 Sep 2025 22:51:00 +0700 Subject: [PATCH] Improve scheduler to run immediately then wait for next full hour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Run initial data collection immediately on startup - Calculate wait time to next full hour (e.g., 22:12 start waits until 23:00) - Schedule subsequent runs at top of each hour (:00 minutes) - Display next scheduled run time to user for better visibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/main.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main.py b/src/main.py index 357cfac..1f50d5c 100644 --- a/src/main.py +++ b/src/main.py @@ -84,12 +84,21 @@ def run_continuous_monitoring(): # Run initial cycle logger.info("Running initial data collection...") scraper.run_scraping_cycle() - + # Start scheduled monitoring import schedule - - schedule.every(Config.SCRAPING_INTERVAL_HOURS).hours.do(scraper.run_scraping_cycle) - + from datetime import datetime, timedelta + + # Calculate next full hour + now = datetime.now() + next_hour = (now + timedelta(hours=1)).replace(minute=0, second=0, microsecond=0) + minutes_to_wait = (next_hour - now).total_seconds() / 60 + + logger.info(f"Next scheduled run at {next_hour.strftime('%H:%M')} (waiting {minutes_to_wait:.1f} minutes)") + + # Schedule at the top of each hour + schedule.every().hour.at(":00").do(scraper.run_scraping_cycle) + while True: schedule.run_pending() time.sleep(60) # Check every minute