Sync updates¶
Use this procedure to keep a local copy of a document type up to date.
Procedure¶
- Do a full read. Save each document and the latest
last_modifiedvalue. With the default sort, this is the value of the first document. - At a later time, read with
modified_afterset to the saved value. - Save the new and changed documents. Replace documents that have the same
guid. - Save the new latest
last_modifiedvalue. - Do steps 2 to 4 again.
from faa_drs import DRSClient, DocType
def sync(drs: DRSClient, store, checkpoint=None):
latest = checkpoint
for doc in drs.iter_documents(DocType.SAIB, modified_after=checkpoint):
store.upsert(doc.guid, doc.model_dump_json())
if doc.last_modified and (latest is None or doc.last_modified > latest):
latest = doc.last_modified
return latest
Rules¶
modified_afterreturns documents that changed after the time. It does not include the time.modified_afterdoes not return documents that have nolast_modifiedvalue. A full read gets these documents.- If a read stops, continue from the last completed page offset. See Resume a read. Do not continue from the last
last_modifiedvalue:modified_afterdoes not include that time, so you can skip documents that have the same value. - Keep the default sort,
"DESC". If DRS updates during a long read, a later read withmodified_aftergets the documents that the first read missed. With"ASC", a read can skip documents that did not change, andmodified_afterdoes not find them. See Sort order. - DRS updates every 24 hours. Do not sync more frequently than this.
Warning
Many documents have no last_modified value. For example, 585 of 1,338 SAIBs. Do a full read again from time to time to find changes to these documents.