fix scheduler with separate script
This commit is contained in:
@@ -21,26 +21,7 @@ services:
|
|||||||
- ./.env:/app/.env:ro
|
- ./.env:/app/.env:ro
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Vienna
|
- TZ=Europe/Vienna
|
||||||
command: >
|
command: python scheduler.py
|
||||||
python -c "
|
|
||||||
import schedule
|
|
||||||
import time
|
|
||||||
from src.main import FlatScraper
|
|
||||||
|
|
||||||
def run_scraper():
|
|
||||||
scraper = FlatScraper()
|
|
||||||
scraper.run_once()
|
|
||||||
|
|
||||||
# Schedule every 6 hours
|
|
||||||
schedule.every(6).hours.do(run_scraper)
|
|
||||||
|
|
||||||
print('Scheduler started. Running every 6 hours.')
|
|
||||||
run_scraper() # Run immediately
|
|
||||||
|
|
||||||
while True:
|
|
||||||
schedule.run_pending()
|
|
||||||
time.sleep(60)
|
|
||||||
"
|
|
||||||
# platform: linux/arm64
|
# platform: linux/arm64
|
||||||
depends_on:
|
depends_on:
|
||||||
- flat-scraper
|
- flat-scraper
|
||||||
|
|||||||
51
scheduler.py
Executable file
51
scheduler.py
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Scheduler script for Flat Scraper
|
||||||
|
Runs every 6 hours and sends notifications for new results
|
||||||
|
"""
|
||||||
|
|
||||||
|
import schedule
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
from src.main import FlatScraper
|
||||||
|
|
||||||
|
# Configure logging
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||||
|
)
|
||||||
|
|
||||||
|
def run_scraper():
|
||||||
|
"""Run the scraper once"""
|
||||||
|
try:
|
||||||
|
scraper = FlatScraper()
|
||||||
|
scraper.run_once()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Error running scraper: {e}")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main scheduler function"""
|
||||||
|
print('🕐 Scheduler started. Running every 6 hours.')
|
||||||
|
print('🏠 Flat Scraper will check for new apartments automatically.')
|
||||||
|
|
||||||
|
# Schedule every 6 hours
|
||||||
|
schedule.every(6).hours.do(run_scraper)
|
||||||
|
|
||||||
|
# Run immediately on start
|
||||||
|
print('🚀 Running initial scrape...')
|
||||||
|
run_scraper()
|
||||||
|
|
||||||
|
# Keep running
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
schedule.run_pending()
|
||||||
|
time.sleep(60) # Check every minute
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('\n👋 Scheduler stopped by user.')
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Scheduler error: {e}")
|
||||||
|
time.sleep(300) # Wait 5 minutes on error
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user