ApifyClient.API.Runs (apify_client v1.0.0)

Copy Markdown View Source

Provides API endpoints related to api/runs

Summary

Functions

Abort Actor run

Charge events in Actor run

Delete Actor run

Get Actor run

Get list of user's Actor runs

Get log of an Actor run

Metamorph Actor run

Reboot Actor run

Resurrect Actor run

Types

charge_201_json_resp()

@type charge_201_json_resp() :: %{}

get_200_json_resp()

@type get_200_json_resp() :: %{data: ApifyClient.Schemas.Run.t() | nil}

list_200_json_resp()

@type list_200_json_resp() :: %{data: ApifyClient.Schemas.ListOfRuns.t() | nil}

resurrect_200_json_resp()

@type resurrect_200_json_resp() :: %{data: ApifyClient.Schemas.Run.t() | nil}

Functions

abort(run_id, opts \\ [])

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

Abort Actor run

Aborts an Actor run and returns an object that contains all the details about the run.

Only runs that are starting or running are aborted. For runs with status FINISHED, FAILED, ABORTING and TIMED-OUT this call does nothing.

Options

  • gracefully: If true passed, the Actor run will abort gracefully. It will send aborting and persistState event into run and force-stop the run after 30 seconds. It is helpful in cases where you plan to resurrect the run later.

charge(run_id, body, opts \\ [])

@spec charge(
  run_id :: String.t(),
  body :: map() | ApifyClient.Schemas.ChargeRunRequest.t(),
  opts :: keyword()
) :: {:ok, charge_201_json_resp()} | {:error, ApifyClient.Error.t()}

Charge events in Actor run

Charge for events in the run of your pay-per-event Actor. The event you are charging for must be one of the configured events in your Actor. If the Actor is not set up as pay per event, or if the event is not configured, the endpoint will return an error. The endpoint must be called from the Actor run itself, with the API token provided to the run at startup in the APIFY_TOKEN environment variable.

To charge a request to a multi-tenant Server Actor, set requestId to the request's X-Actor-Request-ID header value. See Charge for a request.

Request Body

Content Types: application/json

Define which event, and how many times, you want to charge for.

delete(run_id, opts \\ [])

@spec delete(run_id :: String.t(), opts :: keyword()) ::
  :ok | {:error, ApifyClient.Error.t()}

Delete Actor run

Delete the run. Only finished runs can be deleted. Only the person or organization that initiated the run can delete it.

get(run_id, opts \\ [])

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

Get Actor run

This is not a single endpoint, but an entire group of endpoints that lets you retrieve the run or any of its default storages.

Convenience endpoints for Actor run default storages

Gets an object that contains all the details about a specific run of an Actor.

By passing the optional waitForFinish parameter the API endpoint will synchronously wait for the run to finish. This is useful to avoid periodic polling when waiting for Actor run to complete. Note that the first response after completion can still show preliminary stats, costs, and event counts. For stable figures, wait about 10 seconds and call the endpoint again.

This endpoint does not require the authentication token. Instead, calls are authenticated using a hard-to-guess ID of the run. However, if you access the endpoint without the token, certain attributes, such as usageUsd and usageTotalUsd, will be hidden.

Options

  • wait_for_finish: The maximum number of seconds the server waits for the run to finish. By default it is 0, the maximum value is 60. <!-- MAX_ACTOR_JOB_ASYNC_WAIT_SECS --> If the run finishes in time then the returned run object will have a terminal status (e.g. SUCCEEDED), otherwise it will have a transitional status (e.g. RUNNING).

list(opts \\ [])

@spec list(opts :: keyword()) ::
  {:ok, ApifyClient.Schemas.ListOfRuns.t()} | {:error, ApifyClient.Error.t()}

Get list of user's Actor runs

Gets a list of all runs for a user. The response is a list of objects, where each object contains basic information about a single Actor run.

The endpoint supports pagination using the limit and offset parameters and it will not return more than 1000 array elements.

By default, the records are sorted by the startedAt field in ascending order. Therefore, you can use pagination to incrementally fetch all records while new ones are still being created. To sort the records in descending order, use desc=1 parameter. You can also filter runs by startedAt`` andstatus` fields ([available statuses](https://docs.apify.com/platform/actors/running/runs-and-builds#lifecycle)). ## Options *offset: Number of items that should be skipped at the start. The default value is0. *limit: Maximum number of items to return. The default value as well as the maximum is1000. *desc: Iftrueor1then the objects are sorted by thestartedAtfield in descending order. By default, they are sorted in ascending order. *status: Single status or comma-separated list of statuses, see ([available statuses](https://docs.apify.com/platform/actors/running/runs-and-builds#lifecycle)). Used to filter runs by the specified statuses only. *started_after: Filter runs that started after the specified date and time (inclusive). The value must be a valid ISO 8601 datetime string (UTC). *started_before: Filter runs that started before the specified date and time (inclusive). The value must be a valid ISO 8601 datetime string (UTC). *deployment: Single Actor Standby deployment or comma-separated list of deployments (SINGLE_TENANT,MULTI_TENANT_FREE_USERS,MULTI_TENANT_PAYING_USERSorMULTI_TENANT_OWNER_PAID). Used to filter Actor Standby runs by the pool that serves them. Requires thestatusparameter with only non-terminal statuses (READY,RUNNING,TIMING-OUTorABORTING`).

log(run_id, opts \\ [])

@spec log(run_id :: String.t(), opts :: keyword()) ::
  {:ok, String.t()} | {:error, ApifyClient.Error.t()}

Get log of an Actor run

Retrieves Actor run's logs.

This endpoint is a shortcut for getting the run's log. Same as Get Actor build or run log endpoint.

Options

  • stream: If true or 1 then the logs will be streamed as long as the run or build is running.

  • download: If true or 1 then the web browser will download the log file rather than open it in a tab.

  • raw: If true or 1, the logs will be kept verbatim. By default, the API removes ANSI escape codes from the logs, keeping only printable characters.

metamorph(run_id, opts \\ [])

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

Metamorph Actor run

Transforms an Actor run into a run of another Actor with a new input.

This is useful if you want to use another Actor to finish the work of your current Actor run, without the need to create a completely new run and waiting for its finish.

For the users of your Actors, the metamorph operation is transparent, they will just see your Actor got the work done.

Internally, the system stops the Docker container corresponding to the Actor run and starts a new container using a different Docker image.

All the default storages are preserved and the new input is stored under the INPUT-METAMORPH-1 key in the same default key-value store.

For more information, see the Actor docs.

Options

  • target_actor_id: ID of a target Actor that the run should be transformed into.

  • build: Optional build of the target Actor.

    It can be either a build tag or build number. By default, the run uses the build specified in the default run configuration for the target Actor (typically latest).

reboot(run_id, opts \\ [])

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

Reboot Actor run

Reboots an Actor run and returns an object that contains all the details about the rebooted run.

Only runs that are running, i.e. runs with status RUNNING can be rebooted.

The run's container will be restarted, so any data not persisted in the key-value store, dataset, or request queue will be lost.

resurrect(run_id, opts \\ [])

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

Resurrect Actor run

Resurrects a finished Actor run and returns an object that contains all the details about the resurrected run. Only finished runs, that is, runs with status SUCCEEDED, FAILED, ABORTED and TIMED-OUT can be resurrected. Run status will be updated to RUNNING and its container will be restarted with the same storages (the same behaviour as when the run gets migrated to the new server).

For more information, see the Actor docs.

Options

  • build: Specifies the Actor build to run. It can be either a build tag or build number. By default, the run is resurrected with the same build it originally used. Specifically, if a run was first started with the latest tag, which resolves to version 0.0.3 at the time, a run resurrected without this parameter will continue running with 0.0.3, even if latest already points to a newer build.

  • timeout: Optional timeout for the run, in seconds. By default, the run uses the timeout specified in the run that is being resurrected.

  • memory: Memory limit for the run, in megabytes. The amount of memory can be set to a power of 2 with a minimum of 128. By default, the run uses the memory limit specified in the run that is being resurrected.

  • max_items: Specifies the maximum number of dataset items that will be charged for pay-per-result Actors. This does NOT guarantee that the Actor will return only this many items. It only ensures you won't be charged for more than this number of items. Only works for pay-per-result Actors. Value can be accessed in the actor run using ACTOR_MAX_PAID_DATASET_ITEMS environment variable.

  • max_total_charge_usd: Specifies the maximum total cost of the run. Use it to cap the total amount charged for all pricing models. You can access the maximum cost in your Actor by using the ACTOR_MAX_TOTAL_CHARGE_USD environment variable.

  • restart_on_error: Determines whether the resurrected run will be restarted if it fails. By default, the resurrected run uses the same setting as before.

update(run_id, body, opts \\ [])

@spec update(run_id :: String.t(), body :: map(), opts :: keyword()) ::
  {:ok, ApifyClient.Schemas.Run.t()} | {:error, ApifyClient.Error.t()}

Update Actor run

This endpoint can be used to update both the run's status message and to configure its general resource access level.

Status message:

You can set a single status message on your run that will be displayed in the Apify Console UI. During an Actor run, you will typically do this in order to inform users of your Actor about the Actor's progress.

The request body must contain runId and statusMessage properties. The isStatusMessageTerminal property is optional and it indicates if the status message is the very last one. In the absence of a status message, the platform will try to substitute sensible defaults.

General resource access:

You can also update the run's general resource access setting, which determines who can view the run and its related data.

Allowed values:

  • FOLLOW_USER_SETTING - The run inherits the general access setting from the account level.
  • ANYONE_WITH_ID_CAN_READ - The run can be viewed anonymously by anyone who has its ID.
  • RESTRICTED - Only users with explicit access to the resource can access the run.

When a run is accessible anonymously, all of the run's default storages and logs also become accessible anonymously.

Request Body

Content Types: application/json