https://github.com/amberengine/stepfunctions_activity_worker
Activity worker for performing activity tasks from AWS StepFunctions
https://github.com/amberengine/stepfunctions_activity_worker
python3 stepfunctions stepfunctions-activity
Last synced: about 1 year ago
JSON representation
Activity worker for performing activity tasks from AWS StepFunctions
- Host: GitHub
- URL: https://github.com/amberengine/stepfunctions_activity_worker
- Owner: AmberEngine
- License: mit
- Created: 2018-11-20T21:55:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-16T17:44:39.000Z (over 6 years ago)
- Last Synced: 2025-04-13T23:15:58.426Z (about 1 year ago)
- Topics: python3, stepfunctions, stepfunctions-activity
- Language: Python
- Size: 16.6 KB
- Stars: 7
- Watchers: 12
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StepFunctions Activity Worker
A worker that listens to a StepFunctions activity and executes a provided function using the inputs from the activity task.
The StepFunctions Activity Worker encapsulates all the parts of communicating with the StepFunctions API so you don't have to worry about task heartbeats or maintaining task tokens and success/failure scenarios; all you have to worry about is executing the task.
### Installation
Install from [PyPI](https://pypi.org/project/stepfunctions-activity-worker/):
```
pip install stepfunctions_activity_worker
```
### Usage
```python
from stepfunctions_activity_worker import ActivityWorker
def my_task(**task_input):
"""Perform the task based on this task's input."""
# Perform your task here!
return {"result": "done!"}
if __name__ == "__main__":
activity_arn = "PLACE YOUR ACTIVITY ARN HERE"
worker = ActivityWorker(activity_arn, my_task)
worker.listen()
```
## Warning
The `ActivityWorker` class, if not provided with a `client` argument on instantiation, will create a *properly configured* client from your default session.
However, if you are providing an already instantiated `client` to the `ActivityWorker` class, *make sure it is proply configured to make StepFunctions API calls*!
The [`GetActivityTask` API call](https://docs.aws.amazon.com/step-functions/latest/apireference/API_GetActivityTask.html) __blocks for 60 seconds__ which *matches* the [`botocore.config.Config` default `read_timeout`](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html). This means that if the API response for `GetActivityTask` is not punctual (which it often isn't) it will cause unnecessary retry-requests & eventually bubble up an HTTP exception.
```python
import boto3
import botocore
from stepfunctions_activity_worker import ActivityWorker
def my_task(**task_input):
"""Perform the task based on this task's input."""
# Perform your task here!
return {"result": "done!"}
config = botocore.config.Config(
read_timeout=70,
# Insert other custom configuration here
)
stepfunctions = boto3.client('stepfunctions', config=config)
activity_worker = ActivityWorker(activity_arn, my_task, client=stepfunctions)
```