Skip to content

Commit

Permalink
Code clean up: Format job_start datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Sep 29, 2022
1 parent 14f69f9 commit 26080a3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,6 @@ Response
[
{
"job_uuid": "256dcef5-1baa-48ee-83a3-f7100123f5d2",
"time_start": 1664372983.8631873
"time_start": "2022-09-29T09:08:59"
}
]
8 changes: 6 additions & 2 deletions onadata/libs/tests/utils/test_async_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
tests for celery asyncronous task utilities
"""
from datetime import datetime
from unittest.mock import MagicMock

from celery import states
Expand Down Expand Up @@ -44,6 +45,7 @@ def test_async_status(self):
def test_get_active_tasks(self):
"""test get_active_tasks"""
xform = XForm()
time_start = 1664372983.8631873
self.assertEqual(
async_status.get_active_tasks(
['onadata.libs.utils.csv_import.submit_csv_async'], xform
Expand All @@ -57,7 +59,7 @@ def test_get_active_tasks(self):
{
'args': [None, xform.pk],
'id': '11',
'time_start': '2021-02-26T03:28:19.512875-05:00',
'time_start': time_start,
'name': 'onadata.libs.utils.csv_import.submit_csv_async',
}
]
Expand All @@ -70,5 +72,7 @@ def test_get_active_tasks(self):
['onadata.libs.utils.csv_import.submit_csv_async'], xform
),
'[{"job_uuid": "11", "time_start"'
+ ': "2021-02-26T03:28:19.512875-05:00"}]',
+ ": \""
+ datetime.fromtimestamp(time_start).strftime("%Y-%m-%dT%H:%M:%S")
+ "\"}]",
)
5 changes: 4 additions & 1 deletion onadata/libs/utils/async_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Utilities for celery asyncronous tasks
"""
import json
from datetime import datetime

from typing import List
from celery import states
Expand Down Expand Up @@ -65,7 +66,9 @@ def get_active_tasks(task_names: List[str], xform: XForm):
map(
lambda i: {
'job_uuid': gettext(i['id']),
'time_start': i['time_start'],
'time_start': datetime.fromtimestamp(i["time_start"]).strftime(
"%Y-%m-%dT%H:%M:%S"
),
},
data,
)
Expand Down

0 comments on commit 26080a3

Please sign in to comment.