Tolerate empty files in tasks
This commit is contained in:
parent
c1275e3cad
commit
d2321c241a
@ -1,4 +1,5 @@
|
||||
|
||||
import errno
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@ -42,12 +43,26 @@ def load_task(task_path, cached_task=None, now=None):
|
||||
return cached_task
|
||||
|
||||
info_path = os.path.join(task_path, 'info.json')
|
||||
|
||||
try:
|
||||
mtime = os.path.getmtime(info_path)
|
||||
ctime = os.path.getmtime(os.path.join(task_path, 'task', 'id'))
|
||||
st = os.stat(info_path)
|
||||
except OSError as ex:
|
||||
if ex.errno == errno.ENOENT:
|
||||
LOG.debug("Failed to load %s: %s", info_path, ex)
|
||||
return cached_task
|
||||
else:
|
||||
raise
|
||||
|
||||
if st.st_size == 0:
|
||||
LOG.debug("Ignoring empty file: %s", info_path)
|
||||
return cached_task
|
||||
|
||||
try:
|
||||
mtime = st.st_mtime
|
||||
if cached_task and mtime < cached_task.get('load_time', 0):
|
||||
return cached_task
|
||||
|
||||
ctime = os.path.getmtime(os.path.join(task_path, 'task', 'id'))
|
||||
with open(info_path) as f:
|
||||
data = json.load(f)
|
||||
# hack(iv@): sometimes info.json is moved before the state
|
||||
|
Loading…
Reference in New Issue
Block a user