background task
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user