-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a Docker container for taskworkers (#110)
When testing in sandboxes, it's helpful to have a worker image that can be scaled up and down easily, and that can be configured with different failure modes. Add a new docker image for a simple worker that can be set to fail randomly a certain percentage of times. The failure can be an actual task failure, or simply never returning a status for a task, causing it to "timeout".
- Loading branch information
Showing
6 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.11-slim | ||
|
||
# Set the working directory in the container | ||
WORKDIR /app | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . /app | ||
COPY requirements-dev.txt /app/requirements-dev.txt | ||
|
||
# Install any needed dependencies specified in requirements.txt | ||
RUN pip install --no-cache-dir -r requirements-dev.txt | ||
|
||
# Run app.py when the container launches | ||
CMD ["python", "integration_tests/runner.py"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
from worker import ConfigurableTaskWorker, TaskWorkerClient | ||
|
||
|
||
def main() -> None: | ||
print("Starting worker") | ||
grpc_host = os.getenv("SENTRY_TASKWORKER_GRPC_HOST", "127.0.0.1") | ||
grpc_port = os.getenv("SENTRY_TASKWORKER_GRPC_PORT", "50051") | ||
namespace = os.getenv("SENTRY_TASKWORKER_NAMESPACE", "test") | ||
failure_rate = float(os.getenv("SENTRY_TASKWORKER_FAILURE_RATE", "0.0")) | ||
timeout_rate = float(os.getenv("SENTRY_TASKWORKER_TIMEOUT_RATE", "0.0")) | ||
|
||
if not (0 <= failure_rate <= 1) or not (0 <= timeout_rate <= 1): | ||
raise ValueError("Failure rate and timeout rate must be between 0 and 1") | ||
|
||
worker = ConfigurableTaskWorker( | ||
client=TaskWorkerClient(f"{grpc_host}:{grpc_port}"), | ||
namespace=namespace, | ||
failure_rate=failure_rate, | ||
timeout_rate=timeout_rate, | ||
) | ||
|
||
while True: | ||
task = worker.fetch_task() | ||
if task: | ||
worker.process_task(task) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters