Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MesosOperator

MesosOperator runs one container task under Apache Mesos. Its behavior follows the Airflow DockerOperator model, but execution takes place through the MesosExecutor API.

Example

from datetime import datetime

from airflow import DAG
from avmesos_airflow_provider.operators.mesos import MesosOperator

with DAG(
    dag_id="mesos_operator_example",
    schedule=None,
    start_date=datetime(2024, 1, 1),
    catchup=False,
) as dag:
    MesosOperator(
        task_id="hello_mesos",
        image="alpine:3.20",
        command="echo hello from Mesos",
        cpus=0.1,
        mem_limit="128m",
        attributes=["airflow:true"],
    )

Parameters

ParameterDescription
imageContainer image; required.
commandString or argument list. Strings are executed through /bin/sh -c.
cpusRequested CPU resources.
mem_limitRequested memory, for example 128m or a number. memlimit remains available as an alias.
diskRequested Mesos disk resources.
environmentDictionary of environment variables.
attributesList of Mesos attribute constraints.
force_pullControls whether the image should be pulled again.
network_modeDocker network mode.
userUser inside the container.
volumesVolume specifications.
airflow_scheduler_urlExecutor API URL; defaults to operator_api_url or http://localhost:11000.
poll_intervalSeconds between status requests.
startup_timeoutMaximum wait time in seconds.

Airflow standard parameters such as task_id, retries, pool, and queue are supported through BaseOperator.

Status behavior

The operator succeeds when the status is:

TASK_FINISHED

The following states raise AirflowException:

TASK_FAILED
TASK_ERROR
TASK_KILLED
TASK_LOST
TASK_UNREACHABLE

HTTP errors, invalid JSON responses, and exceeding startup_timeout are also reported as task failures.

Cancellation limitation

The current executor API has no separate kill endpoint for directly queued operator tasks. on_kill() logs this limitation. For long-running tasks, use Airflow timeouts and container commands that can be stopped in a controlled way.