Skip to content

Commit

Permalink
Add created/updated job fields (#1907)
Browse files Browse the repository at this point in the history
  • Loading branch information
vprivat-ads authored Jan 21, 2025
1 parent 3d88f7d commit 29b507f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pygeoapi/api/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ def get_jobs(api: API, request: APIRequest,
'message': job_['message'],
'progress': job_['progress'],
'parameters': job_.get('parameters'),
'created': job_['created'],
'started': job_['started'],
'finished': job_['finished']
'finished': job_['finished'],
'updated': job_['updated']
}

# TODO: translate
Expand Down
15 changes: 8 additions & 7 deletions pygeoapi/process/manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
# =================================================================

import collections
from datetime import datetime
import json
import logging
from multiprocessing import dummy
Expand All @@ -50,7 +49,7 @@
UnknownProcessError,
)
from pygeoapi.util import (
DATETIME_FORMAT,
get_current_datetime,
JobStatus,
ProcessExecutionMode,
RequestedProcessExecutionMode,
Expand Down Expand Up @@ -284,6 +283,7 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
}

self.update_job(job_id, {
'updated': get_current_datetime(),
'status': current_status.value,
'message': 'Writing job output',
'progress': 95
Expand All @@ -305,8 +305,8 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
current_status = JobStatus.successful

job_update_metadata = {
'finished': datetime.utcnow().strftime(
DATETIME_FORMAT),
'finished': get_current_datetime(),
'updated': get_current_datetime(),
'status': current_status.value,
'location': str(job_filename),
'mimetype': jfmt,
Expand Down Expand Up @@ -336,8 +336,8 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
}
LOGGER.exception(err)
job_metadata = {
'finished': datetime.utcnow().strftime(
DATETIME_FORMAT),
'finished': get_current_datetime(),
'updated': get_current_datetime(),
'status': current_status.value,
'location': None,
'mimetype': 'application/octet-stream',
Expand Down Expand Up @@ -432,7 +432,8 @@ def execute_process(
'type': 'process',
'identifier': job_id,
'process_id': process_id,
'started': datetime.utcnow().strftime(DATETIME_FORMAT),
'created': get_current_datetime(),
'started': get_current_datetime(),
'finished': None,
'status': current_status.value,
'location': None,
Expand Down
7 changes: 6 additions & 1 deletion pygeoapi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import functools
from functools import partial
from dataclasses import dataclass
from datetime import date, datetime, time
from datetime import date, datetime, time, timezone
from decimal import Decimal
from enum import Enum
import json
Expand Down Expand Up @@ -302,6 +302,11 @@ def format_datetime(value: str, format_: str = DATETIME_FORMAT) -> str:
return dateutil.parser.isoparse(value).strftime(format_)


def get_current_datetime(tz: timezone = timezone.utc,
format_: str = DATETIME_FORMAT) -> str:
return datetime.now(tz).strftime(format_)


def file_modified_iso8601(filepath: Path) -> str:
"""
Provide a file's ctime in ISO8601
Expand Down
2 changes: 2 additions & 0 deletions tests/data/postgres_manager_full_structure.backup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ CREATE TABLE public.jobs (
type character varying DEFAULT 'process'::character varying NOT NULL,
identifier character varying NOT NULL,
process_id character varying NOT NULL,
created timestamp without time zone,
started timestamp without time zone,
finished timestamp without time zone,
updated timestamp without time zone,
status character varying NOT NULL,
location character varying,
mimetype character varying,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def test_get_job_result_binary(config):
"type": "process",
"identifier": job_id,
"process_id": "dummy",
"created": "2024-08-22T12:00:00.000000Z",
"started": "2024-08-22T12:00:00.000000Z",
"finished": "2024-08-22T12:00:01.000000Z",
"updated": "2024-08-22T12:00:01.000000Z",
"status": "successful",
"location": nc_file,
"mimetype": "application/x-netcdf",
Expand Down

0 comments on commit 29b507f

Please sign in to comment.