generated from coulomb/repo-seed
first ingestion/normalization slice
This commit is contained in:
@@ -15,6 +15,8 @@ from kontextual_engine.core import (
|
||||
ContextEntity,
|
||||
CoreRelationship,
|
||||
IdempotencyRecord,
|
||||
IngestionJob,
|
||||
IngestionJobStatus,
|
||||
KnowledgeAsset,
|
||||
LifecycleState,
|
||||
MetadataRecord,
|
||||
@@ -381,6 +383,51 @@ class SQLiteAssetRegistryRepository:
|
||||
return None
|
||||
return IdempotencyRecord.from_dict(_loads(row["payload"]))
|
||||
|
||||
def save_ingestion_job(self, job: IngestionJob) -> IngestionJob:
|
||||
with self._connect() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
insert into ingestion_jobs (id, status, actor_id, correlation_id, created_at, updated_at, payload)
|
||||
values (?, ?, ?, ?, ?, ?, ?)
|
||||
on conflict(id) do update set
|
||||
status=excluded.status,
|
||||
actor_id=excluded.actor_id,
|
||||
correlation_id=excluded.correlation_id,
|
||||
updated_at=excluded.updated_at,
|
||||
payload=excluded.payload
|
||||
""",
|
||||
(
|
||||
job.job_id,
|
||||
job.status.value,
|
||||
job.actor_id,
|
||||
job.correlation_id,
|
||||
job.created_at,
|
||||
job.updated_at,
|
||||
_json(job.to_dict()),
|
||||
),
|
||||
)
|
||||
return job
|
||||
|
||||
def get_ingestion_job(self, job_id: str) -> IngestionJob:
|
||||
row = self._one("select payload from ingestion_jobs where id = ?", (job_id,))
|
||||
if row is None:
|
||||
raise NotFoundError("Ingestion job not found", details={"job_id": job_id})
|
||||
return IngestionJob.from_dict(_loads(row["payload"]))
|
||||
|
||||
def list_ingestion_jobs(
|
||||
self,
|
||||
*,
|
||||
status: IngestionJobStatus | None = None,
|
||||
) -> list[IngestionJob]:
|
||||
if status is None:
|
||||
rows = self._all("select payload from ingestion_jobs order by created_at, id", ())
|
||||
else:
|
||||
rows = self._all(
|
||||
"select payload from ingestion_jobs where status = ? order by created_at, id",
|
||||
(status.value,),
|
||||
)
|
||||
return [IngestionJob.from_dict(_loads(row["payload"])) for row in rows]
|
||||
|
||||
def _initialize(self) -> None:
|
||||
with self._connect() as conn:
|
||||
conn.executescript(
|
||||
@@ -449,6 +496,15 @@ class SQLiteAssetRegistryRepository:
|
||||
status text not null,
|
||||
payload text not null
|
||||
);
|
||||
create table if not exists ingestion_jobs (
|
||||
id text primary key,
|
||||
status text not null,
|
||||
actor_id text not null,
|
||||
correlation_id text not null,
|
||||
created_at text not null,
|
||||
updated_at text not null,
|
||||
payload text not null
|
||||
);
|
||||
create index if not exists idx_assets_lifecycle on assets(lifecycle);
|
||||
create index if not exists idx_representations_asset on representations(asset_id);
|
||||
create index if not exists idx_metadata_asset on metadata_records(asset_id);
|
||||
@@ -458,6 +514,8 @@ class SQLiteAssetRegistryRepository:
|
||||
create index if not exists idx_versions_asset on asset_versions(asset_id);
|
||||
create index if not exists idx_audit_target on audit_events(target);
|
||||
create index if not exists idx_audit_correlation on audit_events(correlation_id);
|
||||
create index if not exists idx_ingestion_jobs_status on ingestion_jobs(status);
|
||||
create index if not exists idx_ingestion_jobs_correlation on ingestion_jobs(correlation_id);
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user