# `Threadline.Export.Orchestrator`
[🔗](https://github.com/szTheory/threadline/blob/v1.2.0/lib/threadline/export/orchestrator.ex#L1)

Runs asynchronous export jobs by streaming captured rows to temporary files and storage.

# `error_reason`

```elixir
@type error_reason() ::
  atom()
  | number()
  | bitstring()
  | pid()
  | port()
  | reference()
  | function()
  | tuple()
  | maybe_improper_list(error_reason(), error_reason())
  | %{optional(error_reason()) =&gt; error_reason()}
```

Any Elixir value returned as an export orchestration error reason.

# `run_opt`

```elixir
@type run_opt() ::
  Threadline.repo_opt()
  | Threadline.storage_schema_opt()
  | {:storage_adapter, module()}
  | {:transaction_fn, function()}
  | {:completion_fn, function()}
```

An option accepted by `run/2`.

# `run_result`

```elixir
@type run_result() :: :ok | {:error, error_reason()}
```

The result of running an export job; the repository or storage adapter owns the error reason.

# `run`

```elixir
@spec run(String.t(), [run_opt()]) :: run_result()
```

Runs an export job and returns `:ok` after storing its CSV, or `{:error, reason}` on failure.

A custom `Threadline.ExportQueue` adapter can call this from its worker to
execute a claimed job. The orchestrator streams projected rows to a temporary
file, persists the file through `Threadline.Storage`, and records the terminal
job state.

## Options

- `:repo` — `Ecto.Repo` module. Defaults to the first configured Threadline repository.
- `:storage_schema` — string. Defaults to the configured Threadline storage schema.
- `:storage_adapter` — storage adapter module. Defaults to the configured adapter.
- `:transaction_fn` — function. Defaults to `repo.transaction/2`; accepts the work function and transaction options.
- `:completion_fn` — function. Defaults to the callback that marks the export job completed.

Other option keys are ignored.

## Returns

- `:ok` — the stored export was recorded as completed.
- `{:error, reason}` — the job could not be claimed, generated, stored, or finalized.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
