67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
||
"""一键启动所有服务:Celery Worker + Beat + Flower"""
|
||
import subprocess
|
||
import sys
|
||
import time
|
||
import signal
|
||
import os
|
||
|
||
def start_services():
|
||
"""启动所有服务"""
|
||
processes = []
|
||
|
||
try:
|
||
print("正在启动Celery服务...")
|
||
|
||
# 启动Worker
|
||
print("1. 启动Celery Worker...")
|
||
worker_proc = subprocess.Popen([
|
||
sys.executable, 'run_worker.py'
|
||
], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||
processes.append(('Worker', worker_proc))
|
||
|
||
# 等待Worker启动
|
||
time.sleep(2)
|
||
|
||
# 启动Beat
|
||
print("2. 启动Celery Beat调度器...")
|
||
beat_proc = subprocess.Popen([
|
||
sys.executable, 'run_beat.py'
|
||
], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||
processes.append(('Beat', beat_proc))
|
||
|
||
# 等待Beat启动
|
||
time.sleep(2)
|
||
|
||
# 启动Flower
|
||
print("3. 启动Flower监控服务...")
|
||
flower_proc = subprocess.Popen([
|
||
sys.executable, 'run_flower.py'
|
||
], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||
processes.append(('Flower', flower_proc))
|
||
|
||
print("\n✅ 所有服务已启动!")
|
||
print("🌸 Flower监控地址: http://localhost:5555")
|
||
print("📋 查看定时任务状态和执行历史")
|
||
print("\n按 Ctrl+C 停止所有服务")
|
||
|
||
# 等待中断信号
|
||
while True:
|
||
time.sleep(1)
|
||
|
||
except KeyboardInterrupt:
|
||
print("\n正在停止所有服务...")
|
||
for name, proc in processes:
|
||
print(f"停止 {name}...")
|
||
proc.terminate()
|
||
proc.wait()
|
||
print("所有服务已停止")
|
||
|
||
except Exception as e:
|
||
print(f"启动服务时出错: {e}")
|
||
for name, proc in processes:
|
||
proc.terminate()
|
||
sys.exit(1)
|
||
|
||
if __name__ == '__main__':
|
||
start_services() |