Skip to content

Commit 29b507f

Browse files
authored
Add created/updated job fields (#1907)
1 parent 3d88f7d commit 29b507f

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

pygeoapi/api/processes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ def get_jobs(api: API, request: APIRequest,
319319
'message': job_['message'],
320320
'progress': job_['progress'],
321321
'parameters': job_.get('parameters'),
322+
'created': job_['created'],
322323
'started': job_['started'],
323-
'finished': job_['finished']
324+
'finished': job_['finished'],
325+
'updated': job_['updated']
324326
}
325327

326328
# TODO: translate

pygeoapi/process/manager/base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
# =================================================================
3333

3434
import collections
35-
from datetime import datetime
3635
import json
3736
import logging
3837
from multiprocessing import dummy
@@ -50,7 +49,7 @@
5049
UnknownProcessError,
5150
)
5251
from pygeoapi.util import (
53-
DATETIME_FORMAT,
52+
get_current_datetime,
5453
JobStatus,
5554
ProcessExecutionMode,
5655
RequestedProcessExecutionMode,
@@ -284,6 +283,7 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
284283
}
285284

286285
self.update_job(job_id, {
286+
'updated': get_current_datetime(),
287287
'status': current_status.value,
288288
'message': 'Writing job output',
289289
'progress': 95
@@ -305,8 +305,8 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
305305
current_status = JobStatus.successful
306306

307307
job_update_metadata = {
308-
'finished': datetime.utcnow().strftime(
309-
DATETIME_FORMAT),
308+
'finished': get_current_datetime(),
309+
'updated': get_current_datetime(),
310310
'status': current_status.value,
311311
'location': str(job_filename),
312312
'mimetype': jfmt,
@@ -336,8 +336,8 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
336336
}
337337
LOGGER.exception(err)
338338
job_metadata = {
339-
'finished': datetime.utcnow().strftime(
340-
DATETIME_FORMAT),
339+
'finished': get_current_datetime(),
340+
'updated': get_current_datetime(),
341341
'status': current_status.value,
342342
'location': None,
343343
'mimetype': 'application/octet-stream',
@@ -432,7 +432,8 @@ def execute_process(
432432
'type': 'process',
433433
'identifier': job_id,
434434
'process_id': process_id,
435-
'started': datetime.utcnow().strftime(DATETIME_FORMAT),
435+
'created': get_current_datetime(),
436+
'started': get_current_datetime(),
436437
'finished': None,
437438
'status': current_status.value,
438439
'location': None,

pygeoapi/util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import functools
3636
from functools import partial
3737
from dataclasses import dataclass
38-
from datetime import date, datetime, time
38+
from datetime import date, datetime, time, timezone
3939
from decimal import Decimal
4040
from enum import Enum
4141
import json
@@ -302,6 +302,11 @@ def format_datetime(value: str, format_: str = DATETIME_FORMAT) -> str:
302302
return dateutil.parser.isoparse(value).strftime(format_)
303303

304304

305+
def get_current_datetime(tz: timezone = timezone.utc,
306+
format_: str = DATETIME_FORMAT) -> str:
307+
return datetime.now(tz).strftime(format_)
308+
309+
305310
def file_modified_iso8601(filepath: Path) -> str:
306311
"""
307312
Provide a file's ctime in ISO8601

tests/data/postgres_manager_full_structure.backup.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ CREATE TABLE public.jobs (
3434
type character varying DEFAULT 'process'::character varying NOT NULL,
3535
identifier character varying NOT NULL,
3636
process_id character varying NOT NULL,
37+
created timestamp without time zone,
3738
started timestamp without time zone,
3839
finished timestamp without time zone,
40+
updated timestamp without time zone,
3941
status character varying NOT NULL,
4042
location character varying,
4143
mimetype character varying,

tests/test_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ def test_get_job_result_binary(config):
8484
"type": "process",
8585
"identifier": job_id,
8686
"process_id": "dummy",
87+
"created": "2024-08-22T12:00:00.000000Z",
8788
"started": "2024-08-22T12:00:00.000000Z",
8889
"finished": "2024-08-22T12:00:01.000000Z",
90+
"updated": "2024-08-22T12:00:01.000000Z",
8991
"status": "successful",
9092
"location": nc_file,
9193
"mimetype": "application/x-netcdf",

0 commit comments

Comments
 (0)