Deploy a custom worker on Modal

This guide shows you how to deploy a custom Arcade Worker using Modal. It takes you through setting up the environment, deploying the worker, and connecting it to the Arcade Engine.

Requirements

  • Python 3.10+
  • Modal CLI (pip install modal)

Deploy

Navigate to the directory containing your worker script and deploy it using Modal:

cd examples/serving-tools
modal deploy run-arcade-worker.py

Changing the Toolkits

To change the toolkits, edit the toolkits list in the run-arcade-worker.py file.

Example run-arcade-worker.py

import os
from modal import App, Image, asgi_app
 
# Define the FastAPI app
app = App("arcade-worker")
 
toolkits = ["arcade-google", "arcade-slack"]
 
image = (
    Image.debian_slim()
    .pip_install("arcade-ai[fastapi]")
    .pip_install(toolkits)
    .pip_install("fastapi>=0.115.3")
    .pip_install("uvicorn>=0.24.0")
)
 
@app.function(image=image)
@asgi_app()
def fastapi_app():
    from fastapi import FastAPI
    from arcade.sdk import Toolkit
    from arcade.worker.fastapi.worker import FastAPIWorker
 
    web_app = FastAPI()
 
    # Initialize app and Arcade FastAPIWorker
    worker_secret = os.environ.get("ARCADE_WORKER_SECRET", "dev")
    worker = FastAPIWorker(web_app, secret=worker_secret)
 
    # Register toolkits we've installed
    installed_toolkits = Toolkit.find_all_arcade_toolkits()
    for toolkit in toolkits:
        if toolkit in installed_toolkits:
            worker.register_toolkit(toolkit)
 
    return web_app

Connect to Arcade Engine

To connect the Arcade Engine to your worker, configure the worker URL in the engine’s configuration file. Start the engine with the appropriate configuration.

For more details, refer to the Arcade Engine configuration documentation.


Next Steps

  • Ensure your environment variables (like ARCADE_WORKER_SECRET) are set securely for production use.
  • Explore deploying your worker in different environments supported by Modal.