Skip to content

Export items back out

export_items selects items and writes their bytes into a storage resource.

{
"name": "export_items",
"arguments": {
"destination_id": "...",
"query": "invoice",
"kind": "pdf",
"since": "2024-01-01"
}
}

destination_id defaults to Resource.default_storage!, and must name a resource whose capabilities include storageResource#storage! raises ArgumentError otherwise.

Tool::Base::SELECTOR_SCHEMA. The same grammar search_items uses, resolved by Item.matching:

Field Restricts to
query words to match, through the search index
kind one kind
resource_id items referenced by one resource
folder a prefix of the locator key: 2024/invoices
since / before created_at bounds

folder matches the exact key or <prefix>/%, escaped with sanitize_sql_like. A since or before that will not parse raises ArgumentError.

ExportItemsJob#each_iteration finds a source reference on another resource, writes the bytes, and records the copy with Reference.record! — another reference on the same item, carrying source_version.

Two consequences:

  • An item already copied is skipped unless copy.stale_against?(source), so re-running an export resumes rather than duplicates.
  • The copy is findable. It is the same item, now living in one more place.

The job includes JobIteration::Iteration, so an export interrupted by a deploy continues at its cursor.

{ "name": "list_runs", "arguments": { "kind": "export" } }

cancel_run sets the run’s status; the iteration reads it on its next halted? check. Whatever was copied stays copied and catalogued.

Resource::Failed is retried five times with polynomial backoff, then fails the run.

Once the bytes are somewhere you control, destroying the item and deleting the object in the resource remain two operations. Nothing in the catalog deletes a resource’s objects — see Items.