Skip to content

Commit 0ff0f5a

Browse files
feat (endpoints): return last harvest date with endpoints config
1 parent c02d50a commit 0ff0f5a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/transform.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ class EndpointConfig(BaseModel):
7979
harvest_params: HarvestParams
8080
code: str
8181
protocol: str
82-
82+
from_date: Optional[datetime]
83+
until_date: Optional[datetime]
84+
started_at: Optional[datetime]
85+
completed_at: Optional[datetime]
8386

8487
class Config(BaseModel):
8588
endpoints_configs: list[EndpointConfig]
@@ -310,9 +313,22 @@ def get_config_from_db() -> list[EndpointConfig]:
310313
e.harvest_url,
311314
e.harvest_params,
312315
e.protocol,
313-
r.code
316+
r.code,
317+
hr_latest.from_date,
318+
hr_latest.until_date,
319+
hr_latest.started_at,
320+
hr_latest.completed_at
314321
FROM endpoints e
315322
JOIN repositories r ON e.repository_id = r.id
323+
JOIN harvest_runs hr ON hr.endpoint_id = e.id
324+
LEFT JOIN LATERAL (
325+
SELECT until_date, from_date, started_at, completed_at
326+
FROM harvest_runs
327+
WHERE endpoint_id = e.id
328+
AND status = 'closed'
329+
ORDER BY started_at DESC
330+
LIMIT 1
331+
) hr_latest ON true
316332
""")
317333
for doc in cur.fetchall():
318334
endpoints.append(
@@ -322,7 +338,7 @@ def get_config_from_db() -> list[EndpointConfig]:
322338
metadata_prefix=doc['harvest_params'].get('metadata_prefix'),
323339
set=doc['harvest_params'].get('set'),
324340
additional_metadata_params=doc['harvest_params'].get(
325-
'additional_metadata_params'))))
341+
'additional_metadata_params')), from_date=doc['from_date'], until_date=doc['until_date'], started_at=doc['started_at'], completed_at=doc['completed_at']))
326342

327343
return endpoints
328344
except JSONDecodeError as e:

0 commit comments

Comments
 (0)