85 lines
3.1 KiB
Python
85 lines
3.1 KiB
Python
|
|
import time
|
|||
|
|
|
|||
|
|
startTime = time.time()
|
|||
|
|
currentIndex = 0
|
|||
|
|
currentState = 0
|
|||
|
|
date_format = "%Y-%m-%d %H:%M:%S"
|
|||
|
|
|
|||
|
|
def toTime(target_time_str):
|
|||
|
|
target_time = time.mktime(time.strptime(target_time_str, date_format))
|
|||
|
|
current_time = time.time()
|
|||
|
|
#更新时间进度
|
|||
|
|
updateTime(startTime, current_time, target_time)
|
|||
|
|
if current_time > target_time:
|
|||
|
|
return True
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
def toDay(days):
|
|||
|
|
target_time = startTime + float(days) * 86400 # 将天数转换为秒并加到startTime上
|
|||
|
|
current_time = time.time()
|
|||
|
|
updateTime(startTime, current_time, target_time)
|
|||
|
|
return current_time > target_time
|
|||
|
|
|
|||
|
|
def toHour(hours):
|
|||
|
|
target_time = startTime + float(hours) * 3600 # 将小时转换为秒并加到startTime上
|
|||
|
|
current_time = time.time()
|
|||
|
|
updateTime(startTime, current_time, target_time)
|
|||
|
|
return current_time > target_time
|
|||
|
|
|
|||
|
|
def toMinute(minutes):
|
|||
|
|
target_time = startTime + float(minutes) * 60 # 将分钟转换为秒并加到startTime上
|
|||
|
|
current_time = time.time()
|
|||
|
|
updateTime(startTime, current_time, target_time)
|
|||
|
|
return current_time > target_time
|
|||
|
|
|
|||
|
|
def toSecond(seconds):
|
|||
|
|
target_time = startTime + float(seconds) # 将秒直接加到startTime上
|
|||
|
|
current_time = time.time()
|
|||
|
|
updateTime(startTime, current_time, target_time)
|
|||
|
|
return current_time > target_time
|
|||
|
|
|
|||
|
|
def start():
|
|||
|
|
pass
|
|||
|
|
|
|||
|
|
def callBack(completed_state):
|
|||
|
|
global currentIndex, currentState
|
|||
|
|
currentState = completed_state #0: 进入任务; 1:执行任务; 2:执行指令; 3:等待指令锁解除; 4: 指令循环
|
|||
|
|
#log(f"completed_state ={completed_state} , currentIndex = {currentIndex}, taskProcessFlag = {taskProcessFlag}")
|
|||
|
|
if loop == 0:
|
|||
|
|
if currentIndex == 0: #首次进入队列
|
|||
|
|
log(f"Initializing here.")
|
|||
|
|
currentIndex += 1
|
|||
|
|
time.sleep(1)
|
|||
|
|
|
|||
|
|
log(f"completed_state ={completed_state}")
|
|||
|
|
# 任务循环次数=0 时可用
|
|||
|
|
#if toTime("2024-01-05 20:00:00"):
|
|||
|
|
# finish()
|
|||
|
|
#if toDay(1):
|
|||
|
|
# finish()
|
|||
|
|
#if toHour(1):
|
|||
|
|
# finish()
|
|||
|
|
if toMinute(1):
|
|||
|
|
finish()
|
|||
|
|
#if toSecond(30):
|
|||
|
|
# finish()
|
|||
|
|
else:
|
|||
|
|
match completed_state:
|
|||
|
|
case 0: #进入队列
|
|||
|
|
if currentIndex == 0: #首次进入队列
|
|||
|
|
log(f"Initializing here.")
|
|||
|
|
time.sleep(5)
|
|||
|
|
log(f"completed_state ={completed_state}")
|
|||
|
|
|
|||
|
|
case 1: #执行队列
|
|||
|
|
log(f"completed_state ={completed_state}")
|
|||
|
|
|
|||
|
|
case 2: #执行指令
|
|||
|
|
log(f"completed_state ={completed_state}")
|
|||
|
|
|
|||
|
|
def next(): #队列单次执行完毕后调用
|
|||
|
|
global currentIndex, currentState
|
|||
|
|
currentIndex = currentIndex + 1
|
|||
|
|
if currentIndex >= loop: #此时任务执行完毕
|
|||
|
|
log('Cleaning up here.')
|
|||
|
|
finish()
|