28 lines
911 B
Python
28 lines
911 B
Python
import schedule
|
|
import time
|
|
import datetime
|
|
import core.logger as logging
|
|
import subprocess
|
|
import os
|
|
|
|
logger = logging.logger
|
|
# 定义要执行的任务
|
|
def run_script():
|
|
start_time = time.time()
|
|
logger.info(f"Executing script at: {datetime.datetime.now()}")
|
|
output_file = r'./output/auto_schedule.txt'
|
|
with open(output_file, 'a') as f:
|
|
f.write(f"Task ran at {datetime.datetime.now()}\n")
|
|
python_path = r"D:\miniconda3\envs\okx\python.exe"
|
|
script_path = r"D:\python_projects\crypto_quant\monitor_schedule.py"
|
|
subprocess.run([python_path, script_path])
|
|
end_time = time.time()
|
|
logger.info(f"Script execution time: {end_time - start_time} seconds")
|
|
# 设置每20秒运行一次
|
|
schedule.every(20).seconds.do(run_script)
|
|
|
|
# 保持程序运行并检查调度
|
|
logger.info("Scheduler started. Press Ctrl+C to stop.")
|
|
while True:
|
|
schedule.run_pending()
|
|
time.sleep(1) |