# Apify Run Queue (`lexis-solutions/apify-run-queue`) Actor

Apify utility to queue runs until memory is available. Workaround to memory exceeded errors on Apify. This actor will retry starting actor starts with a delay. Open source and free!

- **URL**: https://apify.com/lexis-solutions/apify-run-queue.md
- **Developed by:** [Lexis Solutions](https://apify.com/lexis-solutions) (community)
- **Categories:** Developer tools, Automation, Open source
- **Features:** Full permissions
- **Stats:** 28 total users, 2 monthly users, 100.0% runs succeeded, 12 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

A utility actor that runs a list of actors with a retry mechanism. Avoids memory limit exceeded errors on Apify due to running too many runs in parallel.

![Royston queue](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGFpvvAtASTOq9c2tKHHU_4gTV_Sq_lU0fKxweXu2SvHQR1Tq-Io78aa1zqQntoLaUGwXAV-MDjC7IQya6hYmAHfpa_MOD74yXn9i1z2WeRnNO00PMJSbxnJ5IrWxeO3Vqce4C7w/s1600/royston_queue.jpg)

### Problem Statement 🤔

You have a large number of runs you want to start on Apify. However, sometimes your memory limit is exceeded and Apify will not let you start any more runs, and you end up with a lot of failed runs.

### Solution 💡

You can use this actor to run your list of actors in parallel, and it will retry the actors that fail due to memory limit exceeded errors.

### How it works 🤖

- The actor will start running the actors one by one (ℹ️ but won't wait for them to finish). If an actor fails due to a memory limit exceeded error, the actor will wait for some time (default = 30 seconds) and retry.

- The actor will keep track of the number of retries and the total number of runs.

- Progress is saved after each start, so if Apify migrates the run to another server the queue resumes instead of starting the same jobs again.

- The actor will run until all actors have started successfully, or failed due to a non-memory limit error (bad input, etc).

### Disclaimer ⚠️

1. This actor will not return results from the actors. Use `webhooks` to get the results from the actors.

2. This actor will run until all actors have started successfully or failed due to a non-memory limit error. This means the run time can be very long. To avoid disruptions, set the actor timeout (under Actor > Settings) to a reasonable value. You can keep the memory limit low, as the actor is just doing scheduling and not processing any data.

### Input 📥

The input is a JSON array of actor calls. Each actor call is an object with the following properties:

- `invocationId`: (optional) Your custom ID for the invocation. You can use this to match input and output.
- `actorId`: The ID of the actor to run.
- `input`: The input to pass to the actor.
- `retryDelaySecs`: The delay in seconds between retries.
- `timeoutSecs`: The timeout in seconds for the actor call.
- `maxItems`: The maximum number of items to process.
- `memory`: The memory in MB to allocate for the actor call.
- `build`: The build to use for the actor call.
- `webhooks`: The webhooks to use for the actor call.
- `isTask`: Whether the actor call is a task. If true, the actorId must be the ID of a task.

### Output 📤

The output is a JSON array of actor calls. Each actor call is an object with the following properties:

- `actorId`: The ID of the actor/task to run.
- `success`: Whether the actor call was successful.
- `runId`: The ID of the run.
- `retries`: The number of retries.
- `error`: The error message. If the actor call was successful, the error is `null`.

### Example Input 📝

```json
{
  "actorCalls": [
    {
      "actorId": "apify/website-content-crawler",
      "invocationId": "my-custom-id",
      "input": {
        "startUrls": [
          {
            "url": "https://www.apify.com",
            "label": "apify.com"
          }
        ]
      },
      "retryDelaySecs": 30,
      "timeoutSecs": 300,
      "maxItems": 100,
      "memory": 2048,
      "webhooks": [
        {
          "eventTypes": ["ACTOR.RUN.SUCCEEDED", "ACTOR.RUN.FAILED"],
          "requestUrl": "https://example.com/webhook"
        }
      ]
    }
  ]
}
```

### Example Output 📤

```json
[
  {
    "invocationId": "my-custom-id",
    "actorId": "apify/website-content-crawler",
    "success": true,
    "runId": "run_123",
    "retries": 0,
    "error": null
  }
]
```

### FAQ

#### Doesn't Apify have a built-in retry mechanism?

Not yet. This actor is a workaround to avoid memory limit exceeded errors on Apify.

#### Can I use this actor for free?

Yes, you can use this actor for free. However, you will be charged for your usage on Apify.

#### How do I know how many runs I can start in parallel?

Your account is limited by how many GBs of RAM you have in your plan. Each actor consumes a set amount of RAM (configurable). You can calculate how many runs you can start in parallel by dividing your RAM by the RAM consumption of the actors you want to run.

***

Got feedback or need an extension?

Lexis Solutions is a [certified Apify Expert](https://apify.com/partners/find). We can help you with custom solutions or data extraction projects.

Contact us on our website [www.lexis.solutions](https://lexis.solutions/contact-us) or [LinkedIn](https://www.linkedin.com/company/lexis-solutions). Happy to help!

# Actor input Schema

## `actorCalls` (type: `array`):

The actor calls to run

## Actor input object example

```json
{
  "actorCalls": [
    {
      "actorId": "apify/website-content-crawler",
      "input": {
        "startUrls": [
          {
            "url": "https://docs.apify.com/academy/scraping-basics-javascript"
          }
        ],
        "crawlerType": "cheerio",
        "maxCrawlDepth": 0,
        "maxCrawlPages": 3,
        "maxResults": 3
      },
      "timeoutSecs": 300,
      "maxItems": 3
    }
  ]
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "actorCalls": [
        {
            "actorId": "apify/website-content-crawler",
            "input": {
                "startUrls": [
                    {
                        "url": "https://docs.apify.com/academy/scraping-basics-javascript"
                    }
                ],
                "crawlerType": "cheerio",
                "maxCrawlDepth": 0,
                "maxCrawlPages": 3,
                "maxResults": 3
            },
            "timeoutSecs": 300,
            "maxItems": 3
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("lexis-solutions/apify-run-queue").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "actorCalls": [{
            "actorId": "apify/website-content-crawler",
            "input": {
                "startUrls": [{ "url": "https://docs.apify.com/academy/scraping-basics-javascript" }],
                "crawlerType": "cheerio",
                "maxCrawlDepth": 0,
                "maxCrawlPages": 3,
                "maxResults": 3,
            },
            "timeoutSecs": 300,
            "maxItems": 3,
        }] }

# Run the Actor and wait for it to finish
run = client.actor("lexis-solutions/apify-run-queue").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "actorCalls": [
    {
      "actorId": "apify/website-content-crawler",
      "input": {
        "startUrls": [
          {
            "url": "https://docs.apify.com/academy/scraping-basics-javascript"
          }
        ],
        "crawlerType": "cheerio",
        "maxCrawlDepth": 0,
        "maxCrawlPages": 3,
        "maxResults": 3
      },
      "timeoutSecs": 300,
      "maxItems": 3
    }
  ]
}' |
apify call lexis-solutions/apify-run-queue --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,lexis-solutions/apify-run-queue"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/9doUWrGx8wuXIw7Jy/builds/eaGgVWwIJnFlkVG1S/openapi.json
