background task

This commit is contained in:
2025-08-11 19:26:40 -07:00
parent cc1523cbb2
commit e9c976619a
15 changed files with 1474 additions and 2 deletions

View File

@@ -32,3 +32,33 @@ def setup_dev():
print("Docker Compose not found. Please install Docker and Docker Compose.")
sys.exit(1)
@app.cli.command("start-scheduler")
@click.option('--interval', default=5, help='Interval in minutes between processing runs (default: 5)')
@with_appcontext
def start_scheduler(interval):
"""Start the background email processing scheduler."""
if not hasattr(app, 'scheduler'):
print("Scheduler not available. Make sure app/scheduler.py exists and is properly imported.")
sys.exit(1)
print(f"Starting email processing scheduler with {interval} minute interval...")
print("Press Ctrl+C to stop")
try:
# Start the scheduler
app.scheduler.start()
# Keep the main thread alive
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nShutting down scheduler...")
app.scheduler.stop()
except Exception as e:
print(f"Error starting scheduler: {e}")
sys.exit(1)
# Import at the top of the file (add this import if not already present)
import time