Threadline.Export.Orchestrator (Threadline v1.0.0)

Copy Markdown View Source

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

Summary

Types

Any Elixir value returned as an export orchestration error reason.

An option accepted by run/2.

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

Functions

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

Types

error_reason()

@type error_reason() ::
  atom()
  | number()
  | bitstring()
  | pid()
  | port()
  | reference()
  | function()
  | tuple()
  | maybe_improper_list(error_reason(), error_reason())
  | %{optional(error_reason()) => error_reason()}

Any Elixir value returned as an export orchestration error reason.

run_opt()

@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()

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

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

Functions

run(job_id, opts \\ [])

@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.