Validate publication identities and completeness before bulk imports
Metadata integrity checks / metadata (push) Successful in 3s
Metadata integrity checks / metadata (push) Successful in 3s
This commit is contained in:
+6
-2
@@ -22,6 +22,7 @@ def ingest_file(db,path):
|
||||
run = c.execute('INSERT INTO ingest_runs(source_id,checkpoint_json) VALUES(?,?)',(source_id,json.dumps({'file':str(path)}))).lastrowid
|
||||
c.commit()
|
||||
count = 0
|
||||
missing_abstracts = 0
|
||||
seen = set()
|
||||
editions = set()
|
||||
try:
|
||||
@@ -30,6 +31,8 @@ def ingest_file(db,path):
|
||||
row = json.loads(line)
|
||||
if row['source'] != source_name:
|
||||
raise ValueError('Source differs from manifest')
|
||||
if any(key in manifest and manifest[key]!=row[key] for key in ('venue','year','track')):
|
||||
raise ValueError('Conference edition differs from manifest')
|
||||
external = row['external_id']
|
||||
if external in seen:
|
||||
raise ValueError('Duplicate external ID in one collected file: '+external)
|
||||
@@ -43,6 +46,7 @@ def ingest_file(db,path):
|
||||
else:
|
||||
raise ValueError('This importer requires an explicit supported decision status')
|
||||
count += 1
|
||||
missing_abstracts += not bool((row.get('abstract') or '').strip())
|
||||
if not count:
|
||||
raise ValueError('Empty metadata file')
|
||||
if len(editions) != 1:
|
||||
@@ -51,11 +55,11 @@ def ingest_file(db,path):
|
||||
expected = manifest.get('count')
|
||||
if expected is not None and expected != count:
|
||||
raise ValueError(f'Manifest count {expected} differs from records {count}')
|
||||
complete=expected==count and manifest.get('status') not in ('partial','blocked') and not manifest.get('missing_abstract_count',0)
|
||||
complete=expected==count and manifest.get('status') not in ('partial','blocked') and not manifest.get('missing_abstract_count',0) and not missing_abstracts
|
||||
c.execute('INSERT INTO edition_sources(edition_id,source_id,list_url,status,expected_count,imported_count,last_success_at) VALUES(?,?,?,?,?,?,?) ON CONFLICT(edition_id,source_id,list_url) DO UPDATE SET status=excluded.status,expected_count=excluded.expected_count,imported_count=excluded.imported_count,last_success_at=excluded.last_success_at,last_error=NULL',(edition,source_id,manifest['list_url'],'complete' if complete else 'partial',expected,count,time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime())))
|
||||
c.execute("UPDATE ingest_runs SET status='complete',finished_at=CURRENT_TIMESTAMP,records_seen=?,records_written=? WHERE id=?",(count,count,run))
|
||||
c.commit()
|
||||
print(json.dumps({'file':str(path),'status':'imported','records':count}),flush=True)
|
||||
print(json.dumps({'file':str(path),'status':'imported','records':count,'missing_abstract_count':missing_abstracts}),flush=True)
|
||||
except BaseException as exc:
|
||||
c.rollback()
|
||||
c.execute("UPDATE ingest_runs SET status='failed',finished_at=CURRENT_TIMESTAMP,error=? WHERE id=?",(str(exc),run))
|
||||
|
||||
Reference in New Issue
Block a user