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
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
Built Distribution
File details
Details for the file airflow-docker-helper-0.2.0.tar.gz
.
File metadata
- Download URL: airflow-docker-helper-0.2.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecfb25966eca750ab18042e9bad7060b3197868a895c27adc53364a827c2ece5 |
|
MD5 | f3c3cc71814dc85555375710a40e5ba2 |
|
BLAKE2b-256 | 29a593ec197ed56950de014e242b117bb5e02502445d3d7c48c7c91822fda845 |
File details
Details for the file airflow_docker_helper-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: airflow_docker_helper-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 248ce1f7bed8b59bd6fdb211fdb6802e48e01b3a62497bd1ca6855521e3d7363 |
|
MD5 | 6765d607ab4e87c0fb6b1f1639854cbe |
|
BLAKE2b-256 | 205e6a96c14637ada486fcd080ce31844453137f86381b81e898a7d30f70af70 |