Skip to content

Export things back out

export_things selects things and writes their bytes into a storage resource.

{
"name": "export_things",
"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 storage — Resource#storage! raises ArgumentError otherwise.

Tool::Base::SELECTOR_SCHEMA. The same grammar search_things uses, resolved by Thing.matching:

Field Restricts to
query words to match, through the search index
kind one kind
resource_id things 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.

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

Two consequences:

  • A thing 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 thing, 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 thing and deleting the object in the resource remain two operations. Nothing in the catalog deletes a resource’s objects — see Things.