# `ApifyClient.Runs`
[🔗](https://github.com/social-growth-studio/apify-client-ex/blob/v1.0.0/lib/apify_client/runs.ex#L1)

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

# `abort`

```elixir
@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?`

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

Whether the run has reached a terminal status.

# `get`

```elixir
@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?`

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

Whether the run finished successfully.

# `wait_for_finish`

```elixir
@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)

---

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