Skip to main content

A light sdk to be used by the operators in airflow-docker and in task code to participate in host/container communication.

Project description

Airflow Docker Helper

CircleCI Codacy Badge codecov

Description

A light sdk to be used by the operators in airflow-docker and in task code to participate in host/container communication.

Installation

pip install airflow-docker-helper

Usage

Sensor

from airflow_docker_helper import client

if sensed:
    client.sensor(True)
else:
    client.sensor(False)

Short Circuit

from airflow_docker_helper import client

if should_short_circuit:
    client.short_circuit()

Branching

You can pass a list...

from airflow_docker_helper import client

branch_to_task_ids = ['foo', 'bar']

client.branch_to_tasks(branch_to_task_ids)

... or a string.

from airflow_docker_helper import client

client.branch_to_tasks('some-other-task')

Testing

This library ships with a test client that mocks out all io and filesystem calls. This client also provides all of the relevant mocked out files to allow for assertions around the io.

Some higher level assertions are provided. These assertions are based on the lower level file mocks.

from airflow_docker_helper.testing import test_client
client = test_client()
client.assert_not_short_circuited()  # Passes

client.short_circuit()
client.assert_short_circuited()  # Passes

client.sensor(True)

client.assert_sensor_called_with(True)          # Passes
client.assert_sensor_called_with(False)         # Fails

client.assert_branched_to_tasks([])             # Passes

client.branch_to_tasks(['foo', 'bar'])
client.assert_branched_to_tasks(['bar', 'foo']) # Passes

For power users, the mocks may be used directly:

>>> from airflow_docker_helper.testing import test_client
>>> client = test_client()
>>> client.branch_to_tasks(['foo', 'bar'])
>>> client._mock_branch_to_tasks_file.mock_calls
[call('./__AIRFLOW_META__/branch_operator.txt', 'wb'),
 call().__enter__(),
 call().write(b'["foo", "bar"]'),
 call().__exit__(None, None, None)]
>>> client.short_circuit()
>>> client._mock_short_circuit_file.mock_calls
[call('./__AIRFLOW_META__/short_circuit.txt', 'wb'),
 call().__enter__(),
 call().write(b'false'),
 call().__exit__(None, None, None)]
>>> client.sensor(True)
>>> client._mock_sensor_file.mock_calls
[call('./__AIRFLOW_META__/sensor.txt', 'wb'),
 call().__enter__(),
 call().write(b'true'),
 call().__exit__(None, None, None)] 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airflow-docker-helper-0.2.0.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

airflow_docker_helper-0.2.0-py2.py3-none-any.whl (8.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page