Activity Block Wrapper
Overview
This project includes a setup to wrap a user-defined block.py file into an activity block that runs within a managed worker environment. The setup uses entrypoint.py as a wrapper to dynamically load and execute the logic defined in block.py and make it available as an activity block.
This README explains the purpose and functionality of entrypoint.py, the activity_block_wrapper base image, and how it all comes together within the Dockerfile to create a production-ready, deployable worker.
Files
1. entrypoint.py
entrypoint.py is the main entry script for the activity block wrapper. It provides the following functionality:
- Dynamic Loading: Imports
block.pyand retrieves its__main__function dynamically. This function is wrapped and managed within the worker environment. - Logging and Error Handling: Includes logging and error handling to ensure issues are properly recorded and managed, which is essential for production environments.
- Worker Management: Starts a worker instance that manages the execution of the activity block, making the
block.pylogic available as an activity in the specified task queue and namespace.
Configuration
TASK_QUEUE: The task queue name for the worker. Set via environment variable.NAMESPACE: The namespace for the worker to operate within. Set via environment variable.
Example Usage
To configure and run entrypoint.py in your environment:
- Set the
TASK_QUEUEandNAMESPACEenvironment variables. - Run
entrypoint.py, and it will automatically wrapblock.pyas an activity block within the worker.
2. Dockerfile
The Dockerfile is structured to create an image that:
- Uses
activity_block_wrapperas a base, which includesentrypoint.pyand pre-installed dependencies. - Copies the user’s
block.pyand other project-specific files into the container. - Creates a symbolic link to
entrypoint.pyasblock.py, making it appear as ifblock.pyis the entry point, while actually runningentrypoint.pyto manage the activity block.
Key Dockerfile Commands
- FROM activity_block_wrapper:latest: Builds on top of the
activity_block_wrapperimage, which includes the necessary runtime environment andentrypoint.py. - COPY: Copies the user’s
block.pyand other related files into the container. - RUN ln -s /app/entrypoint.py /app/block.py: Creates a symbolic link from
entrypoint.pytoblock.py, allowingentrypoint.pyto manage the activity block while maintainingblock.pyas the visible entry point.
Example Usage with Docker
- Build the Base Image:
docker build -f Dockerfile.base -t activity_block_wrapper:latest .
Description