PaperForge.Concurrent (PaperForge v1.3.0)

Copy Markdown View Source

Concurrent, backpressured execution for independent PDF render jobs.

Phoenix applications should place a Task.Supervisor in their supervision tree and pass its name to stream/4 or through the :supervisor option of run/3.

Summary

Functions

Cancels a task, allowing a graceful shutdown before forcing termination.

Executes all jobs and returns their isolated results.

Starts one supervised job and returns its task handle.

Returns a lazy, backpressured stream of render results.

Types

option()

@type option() ::
  {:supervisor, Supervisor.supervisor()}
  | {:max_concurrency, pos_integer()}
  | {:timeout, timeout()}
  | {:ordered, boolean()}
  | {:job_id, (term(), non_neg_integer() -> term())}
  | {:on_result, (PaperForge.Concurrent.Result.t() -> term())}
  | {:max_attempts, pos_integer()}
  | {:retry_delay, non_neg_integer()}
  | {:retry_on, [PaperForge.Concurrent.Result.status()]}
  | {:max_memory_bytes, pos_integer() | :infinity}
  | {:max_reductions, pos_integer() | :infinity}

Functions

cancel(task, shutdown_timeout \\ 5000)

@spec cancel(Task.t(), timeout()) :: {:ok, term()} | {:exit, term()} | nil

Cancels a task, allowing a graceful shutdown before forcing termination.

run(jobs, renderer, options \\ [])

@spec run(Enumerable.t(), (term() -> term()), [option()]) :: [
  PaperForge.Concurrent.Result.t()
]

Executes all jobs and returns their isolated results.

When no supervisor is supplied, PaperForge starts and stops a private Task.Supervisor for the duration of the call.

start_job(supervisor, job, renderer, options \\ [])

@spec start_job(
  Supervisor.supervisor(),
  term(),
  (term() -> term()),
  keyword()
) :: Task.t()

Starts one supervised job and returns its task handle.

stream(supervisor, jobs, renderer, options \\ [])

@spec stream(Supervisor.supervisor(), Enumerable.t(), (term() -> term()), [option()]) ::
  Enumerable.t()

Returns a lazy, backpressured stream of render results.

The supplied supervisor should normally be owned by the calling application's supervision tree.