Pipe
Pipe is an Android library for building pipelines for executing background tasks.
- Declarative: Uses a Kotlin DSL or builder to declare pipeline schematics.
- Powerful: Supports both simple steps and complex synchronization structures like barriers and aggregators.
- Resilient: Pipe has resiliency baked-in. Has support for step retries in case of failures.
- Android arch-friendly: The API is designed with the Android architecture components in mind, making integration into your apps easy.
Example
Consider a use case where we want to construct the following pipeline:
- Wait for a UI signal to start the pipeline (i.e., button click to lift the manual barrier)
- Download an image from the given URL
- Rotate the downloaded image by 90 degrees
- Scale the image to a 400px x 400px size
- Overdraw the scaled image on top if its sibling
Pipe uses a Kotlin DSL to declare pipeline schematics. We can express the above pipeline as:
We can then use this factory function to create an instance of the pipeline:
And then schedule jobs into it:
We can subscribe to these jobs' state changes in our activities/fragments via LiveData
:
See the state machine for the details.
We can also fetch any ongoing jobs from the repository (e.g., if the fragment is re-created):
And finally, we can start the pipeline when a UI button is clicked:
State machine
The progress of a job is encoded via a state machine: