Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Add timestamp data for every task
Browse files Browse the repository at this point in the history
  • Loading branch information
zteeed committed Sep 16, 2019
1 parent 54fc06b commit 7b98ceb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions worker/worker/redis_interface/challenges.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from multiprocessing.pool import ThreadPool
from datetime import datetime

from worker import app, log
from worker.constants import URL
Expand Down Expand Up @@ -29,9 +30,14 @@ async def set_all_challenges():
with ThreadPool(len(categories)) as tp:
response = tp.map(retrieve_category_info, categories)

timestamp = json.dumps({'timestamp': str(datetime.now())})

await app.redis.set('challenges', json.dumps(response))
await app.redis.set('challenges.timestamp', timestamp)
await app.redis.set('categories', json.dumps(categories))
await app.redis.set('categories.timestamp', timestamp)
for category_data in response:
await app.redis.set(f'categories.{category_data[0]["name"]}', json.dumps(category_data))
await app.redis.set(f'categories.{category_data[0]["name"]}.timestamp', timestamp)

log.debug('set_all_challenges_success')
4 changes: 4 additions & 0 deletions worker/worker/redis_interface/contributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from functools import partial
from multiprocessing.pool import ThreadPool
from datetime import datetime

from worker import app, log
from worker.constants import URL
Expand Down Expand Up @@ -73,8 +74,11 @@ async def set_user_contributions(username):
'solutions': solutions_contributions
}
}]
timestamp = json.dumps({'timestamp': str(datetime.now())})
if challenges_contributions is not None:
await app.redis.set(f'{username}.contributions.challenges', json.dumps(challenges_contributions))
await app.redis.set(f'{username}.contributions.challenges.timestamp', timestamp)
if solutions_contributions is not None:
await app.redis.set(f'{username}.contributions.solutions', json.dumps(solutions_contributions))
await app.redis.set(f'{username}.contributions.solutions.timestamp', timestamp)
await app.redis.set(f'{username}.contributions', json.dumps(response))
4 changes: 4 additions & 0 deletions worker/worker/redis_interface/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from functools import partial
from multiprocessing.pool import ThreadPool
from datetime import datetime

from worker import app, log
from worker.constants import URL
Expand Down Expand Up @@ -47,5 +48,8 @@ async def set_user_ctf(username):
'description': description,
'ctfs': ctfs,
}]

timestamp = json.dumps({'timestamp': str(datetime.now())})
await app.redis.set(f'{username}.ctfs', json.dumps(response))
await app.redis.set(f'{username}.ctfs.timestamp', timestamp)
log.debug('set_user_ctf_success', username=username)
3 changes: 3 additions & 0 deletions worker/worker/redis_interface/details.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from datetime import datetime

from worker import app, log
from worker.constants import URL
Expand Down Expand Up @@ -32,5 +33,7 @@ async def set_user_details(username):
'categories': categories,
}]

timestamp = json.dumps({'timestamp': str(datetime.now())})
await app.redis.set(f'{username}.details', json.dumps(response))
await app.redis.set(f'{username}.details.timestamp', timestamp)
log.debug('set_user_details_success', username=username)
4 changes: 4 additions & 0 deletions worker/worker/redis_interface/profile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from datetime import datetime

from worker import app, log
from worker.constants import URL
Expand All @@ -18,7 +19,10 @@ async def set_user_profile(username):
'pseudo': pseudo,
'score': score,
}]
timestamp = json.dumps({'timestamp': str(datetime.now())})
await app.redis.set(f'{username}', json.dumps(response))
await app.redis.set(f'{username}.timestamp', timestamp)
await app.redis.set(f'{username}.profile', json.dumps(response))
await app.redis.set(f'{username}.profile.timestamp', timestamp)

log.debug('set_user_profile_success', username=username)
3 changes: 3 additions & 0 deletions worker/worker/redis_interface/stats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from datetime import datetime

from worker import app, log
from worker.constants import URL
Expand All @@ -21,5 +22,7 @@ async def set_user_stats(username):
'solved_challenges': solved_challenges,
}

timestamp = json.dumps({'timestamp': str(datetime.now())})
await app.redis.set(f'{username}.stats', json.dumps(response))
await app.redis.set(f'{username}.stats.timestamp', timestamp)
log.debug('set_user_stats_success', username=username)

0 comments on commit 7b98ceb

Please sign in to comment.