如果没有消息 ID,您可能很难找到正确的任务,除非没有提交这么多任务。
查询基于MongoDB(使用mongodb的时候是直通,sqlite实现了简单操作符的子集)。
快速总结:查询是一个字典。如果您使用文字值,它们是相等测试,但您可以将 dict 值用于比较运算符。
您可以按日期搜索任何时间戳:
- 提交:到达控制器
- 开始:到达引擎
- 已完成:在引擎上完成
例如,查找昨天提交的任务:
from datetime import date, time, timedelta, datetime
# round to midnight
today = datetime.combine(date.today(), time())
yesterday = today - timedelta(days=1)
rc.db_query({'submitted': {
'$lt': today, # less than midnight last night
'$gt': yesterday, # greater than midnight the night before
}})
或所有 1-4 小时前提交的任务:
found = rc.db_query({'submitted': {
'$lt': datetime.now() - timedelta(hours=1),
'$gt': datetime.now() - timedelta(hours=4),
}})
根据结果,您可以查看 client_uuid 之类的键来检索给定客户端实例(例如单个笔记本或脚本)提交的所有消息:
client_id = found[0]['client_uuid']
all_from_client = rc.db_query({'client_uuid': client_uuid})
由于此时您只对结果感兴趣,因此您可以指定 keys=['msg_id'] 以仅检索消息 ID。然后我们可以使用这些 msg_id 来获取单个客户端会话产生的所有结果:
# construct list of msg_ids
msg_ids = [ r['msg_id'] for r in rc.db_query({'client_uuid': client_uuid}, keys=['msg_id']) ]
# use client.get_result to retrieve the actual results:
results = rc.get_result(msg_ids)
此时,您已经获得了所有结果,但是您失去了哪些结果来自哪个执行的关联。那里没有太多信息可以帮助您,但您可以通过类型、时间戳或从给定会话中选择 9 个最终项目来判断。