Environment-based task configuration
Dynamically modify task configuration based on the environment.
To configure a task differently based on the environment, you can use the environment variable
AIRPLANE_ENV_SLUG
, which is populated with the slug of the environment that the task is being
deployed to. (You can find the slug of your environment(s) in the
Environments settings page.)Because Airplane tasks are configured with code (see JavaScript and
Python for details), you can switch on
AIRPLANE_ENV_SLUG
to dynamically configure
schedules, constraints, and more.Change the name of a task depending on environment
In this example, we interpolate the environment variable directly into the task name.
javascriptCopied1import airplane from "airplane";23export default airplane.task(4{5slug: "hello_world",6name: `Hello world in environment ${process.env.AIRPLANE_ENV_SLUG}`,7},8async () => {9return "Hello, world!";10}11);
pythonCopied1import airplane23@airplane.task(4slug="hello_world",5name=f"Hello world in environment {os.environ.get('AIRPLANE_ENV_SLUG')}",6)7def hello_world():8return "Hello, world!"
Set different schedules depending on environment
Here, we use the environment variable to set a different schedule object.
javascriptCopied1import airplane from "airplane";23export default airplane.task(4{5slug: "hello_world",6name: "Hello World",7schedules:8process.env.AIRPLANE_ENV_SLUG === "prod"9? {10prod_midnight_daily: {11cron: "0 0 * * *",12},13}14: {15dev_weekly: {16cron: "0 0 * * 1",17},18},19},20() => {21return "Hello, world!";22}23);
pythonCopied1import airplane23@airplane.task(4slug="hello_world",5name="Hello World",6schedules=[(7airplane.Schedule(8slug="prod_midnight_daily",9cron="0 0 * * *",10)11if os.environ.get("AIRPLANE_ENV_SLUG") == "prod"12else airplane.Schedule(13slug="dev_weekly",14cron="0 0 * * 1",15)16)],17)18def hello_world():19return "Hello, world!"