tasks: use time.time() instead of datetime
This commit is contained in:
parent
bfb28137c7
commit
d807cf47da
@ -3,9 +3,9 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
|
||||
from port_stats import utils
|
||||
|
||||
@ -29,10 +29,13 @@ def task_pathes(prefix):
|
||||
|
||||
|
||||
def load_task(path):
|
||||
now = time.time()
|
||||
with open(os.path.join(path, 'info.json')) as f:
|
||||
data = json.load(f)
|
||||
mtime = os.path.getmtime(path)
|
||||
data['task_path'] = path
|
||||
data['task_time'] = utils.file_time_str(path)
|
||||
data['load_time'] = now
|
||||
data['task_time'] = utils.format_timestamp(mtime)
|
||||
data.setdefault('subtasks', {})
|
||||
data.setdefault('try', 0)
|
||||
return data
|
||||
@ -49,7 +52,7 @@ def load_tasks(prefixes, repo=None):
|
||||
LOG.info("Found %s task dirs", len(task_dirs))
|
||||
|
||||
tasks = []
|
||||
started_at = datetime.now()
|
||||
started_at = time.time()
|
||||
for path in task_dirs:
|
||||
try:
|
||||
info = load_task(path)
|
||||
@ -58,10 +61,10 @@ def load_tasks(prefixes, repo=None):
|
||||
path, exc_info=True)
|
||||
else:
|
||||
tasks.append(info)
|
||||
if (datetime.now() - started_at).total_seconds() > 15:
|
||||
if time.time() - started_at > 15:
|
||||
LOG.info("Still loading tasks, now at %s of %s (%s)",
|
||||
len(tasks) + 1, len(task_dirs), path)
|
||||
started_at = datetime.now()
|
||||
started_at = time.time()
|
||||
|
||||
if repo:
|
||||
tasks = (t for t in tasks if t.get('repo') == repo)
|
||||
|
@ -5,9 +5,9 @@ import json
|
||||
import os
|
||||
|
||||
|
||||
def file_time_str(path):
|
||||
return datetime.datetime.fromtimestamp(
|
||||
os.path.getmtime(path)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
def format_timestamp(ts, fmt='%Y-%m-%d %H:%M:%S'):
|
||||
dt = datetime.datetime.fromtimestamp(ts)
|
||||
return dt.strftime(fmt)
|
||||
|
||||
|
||||
def maybe_int(value):
|
||||
|
Loading…
x
Reference in New Issue
Block a user