ApifyClient.Runs (apify_client v1.0.0)

Copy Markdown View Source

Actor runs: fetch, wait for and abort them.

Functions take the connection options described in ApifyClient.Client (:token, :config, ...) next to their own. For everything else about runs, see ApifyClient.API.Runs.

{:ok, run} = ApifyClient.Actors.start("apify/web-scraper", input)
{:ok, run} = ApifyClient.Runs.wait_for_finish(run.id, wait_secs: 600)

if ApifyClient.Runs.finished?(run) do
  {:ok, items} = ApifyClient.Datasets.list_items(run.default_dataset_id)
end

Summary

Functions

Whether the run has reached a terminal status.

Whether the run finished successfully.

Waits until the run reaches a terminal status (SUCCEEDED, FAILED, ABORTED, TIMED-OUT) and returns it.

Functions

abort(run_id, opts \\ [])

@spec abort(String.t(), keyword()) ::
  {:ok, ApifyClient.Schemas.Run.t()} | {:error, ApifyClient.Error.t()}

Aborts a run.

Options

  • :gracefully - let the run finish its current work and persist its state before stopping (it gets the aborting event and 30 seconds)

finished?(run)

@spec finished?(ApifyClient.Schemas.Run.t()) :: boolean()

Whether the run has reached a terminal status.

get(run_id, opts \\ [])

@spec get(String.t(), keyword()) ::
  {:ok, ApifyClient.Schemas.Run.t()} | {:error, ApifyClient.Error.t()}

Gets a run.

Options

  • :wait_for_finish - seconds (at most 60) the API waits for the run to finish before responding

succeeded?(run)

@spec succeeded?(ApifyClient.Schemas.Run.t()) :: boolean()

Whether the run finished successfully.

wait_for_finish(run_id, opts \\ [])

@spec wait_for_finish(String.t(), keyword()) ::
  {:ok, ApifyClient.Schemas.Run.t()} | {:error, ApifyClient.Error.t()}

Waits until the run reaches a terminal status (SUCCEEDED, FAILED, ABORTED, TIMED-OUT) and returns it.

The API holds each request open for up to 60 seconds, so this doesn't poll in a tight loop.

Options

  • :wait_secs - stop waiting after this many seconds and return the run as it is then; check it with finished?/1. Default: wait as long as it takes.
  • :poll_interval_ms - minimum time between two requests, in case the API answers before the run finishes without holding the request (default: 1000)