ApifyClient.Tasks (apify_client v1.0.0)

Copy Markdown View Source

Run Actor tasks.

A task is a saved configuration of an Actor: the Actor, its input and run settings. Tasks can be referred to by ID or by name, as "username/task-name" or "username~task-name".

# Run with the task's saved input
{:ok, run} = ApifyClient.Tasks.start("jane/linkedin-search")

# Override some input fields for this run, and wait for it to finish
{:ok, run} = ApifyClient.Tasks.call("jane/linkedin-search", %{"keyword" => "homeoffice"})

Input fields you don't pass keep the task's saved values (and then the Actor's input schema defaults).

Functions take the connection options described in ApifyClient.Client (:token, :config, ...) next to their own. To create, update or inspect tasks, see ApifyClient.API.Tasks and the modules below it.

Summary

Functions

Starts a task and waits for the run to finish.

Converts a task name to the form used in API paths: "username/task-name" becomes "username~task-name". IDs are returned unchanged.

Starts a task and returns the run without waiting for it to finish.

Functions

call(task_id, input \\ nil, opts \\ [])

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

Starts a task and waits for the run to finish.

Takes the options of start/3, plus:

  • :wait_secs - stop waiting after this many seconds and return the run as it is then; check it with ApifyClient.Runs.finished?/1. Default: wait as long as it takes.

The run is returned whatever its final status; use ApifyClient.Runs.succeeded?/1 to check it.

get(task_id, opts \\ [])

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

Gets a task.

safe_id(task_id)

@spec safe_id(String.t()) :: String.t()

Converts a task name to the form used in API paths: "username/task-name" becomes "username~task-name". IDs are returned unchanged.

iex> ApifyClient.Tasks.safe_id("jane/linkedin-search")
"jane~linkedin-search"

start(task_id, input \\ nil, opts \\ [])

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

Starts a task and returns the run without waiting for it to finish.

input overrides fields of the task's saved input: a map (sent as JSON with the keys as given), a binary with :content_type, or nil to use the saved input as it is.

Options

The run options of ApifyClient.Actors.start/3: :build, :memory, :timeout, :max_items, :max_total_charge_usd, :restart_on_error, :wait_for_finish, :webhooks and :content_type. They override the task's settings for this run.