我正在尝试通过时间戳(小于某个值)过滤Django查询集。但是,筛选器似乎允许通过的记录不少于指定的时间戳。这是一个示例函数:
def check_jobs_status_3():
current_time = datetime.utcnow()
time_threshold = current_time - timedelta(seconds=60)
print("$$$$$$$$$$$$ current_time = {}, timedelta = {}, time_threshold = {}".format(current_time,timedelta(seconds=60),time_threshold))
stuck_jobs_qs = Job.objects.filter(last_updated__lt=time_threshold)
for stuck_job in stuck_jobs_qs:
print("############################## Job #{} (last_updated = {}) no encoding status after {} seconds. Re-enqueueing.".format(stuck_job.id,stuck_job.last_updated,get_video_encoding_timeout_seconds()))
以下是输出:
$$$$$$$$$$$$ current_time = 2019-03-14 20:54:15.221554, timedelta = 0:01:00, time_threshold = 2019-03-14 20:53:15.221554
############################## Job #20 (last_updated = 2019-03-14 20:54:15.221264+00:00) no encoding status after 60 seconds. Re-enqueueing.
如您所见,我收到的记录的last_updated设置为2019-03-14 20:54:15,该记录不小于2019-03-14 20:53:15的过滤器值
这是last_updated字段的定义:
last_updated = models.DateTimeField(auto_now=True)
可能是什么问题?