Skip to content

Commit

Permalink
Use asyncio.gather instead of TaskGroup to avoid consumer crashes (#8)
Browse files Browse the repository at this point in the history
* Add debug logging statements

* Use asyncio.gather instead of TaskGroup

* Remove debug log statements

* Bump version from 1.0.1 -> 1.0.1

---------

Co-authored-by: TheByronHimes <TheByronHimes@gmail.com>
  • Loading branch information
TheByronHimes and TheByronHimes authored May 21, 2024
1 parent 322b61d commit 87215f0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nos"
version = "1.0.0"
version = "1.0.1"
description = "The Notification Orchestration Service controls the creation of notification events."
dependencies = [
"typer >= 0.9.0",
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ We recommend using the provided Docker container.

A pre-build version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/notification-orchestration-service):
```bash
docker pull ghga/notification-orchestration-service:1.0.0
docker pull ghga/notification-orchestration-service:1.0.1
```

Or you can build the container yourself from the [`./Dockerfile`](./Dockerfile):
```bash
# Execute in the repo's root dir:
docker build -t ghga/notification-orchestration-service:1.0.0 .
docker build -t ghga/notification-orchestration-service:1.0.1 .
```

For production-ready deployment, we recommend using Kubernetes, however,
for simple use cases, you could execute the service using docker
on a single server:
```bash
# The entrypoint is preconfigured:
docker run -p 8080:8080 ghga/notification-orchestration-service:1.0.0 --help
docker run -p 8080:8080 ghga/notification-orchestration-service:1.0.1 --help
```

If you prefer not to use containers, you may install the service from source:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
"Intended Audience :: Developers",
]
name = "nos"
version = "1.0.0"
version = "1.0.1"
description = "The Notification Orchestration Service controls the creation of notification events."
dependencies = [
"typer >= 0.9.0",
Expand Down
22 changes: 8 additions & 14 deletions src/nos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""Top-level functions for the service"""

import asyncio
import asyncio.taskgroups

from hexkit.log import configure_logging

Expand All @@ -29,16 +28,11 @@ async def consume_events(run_forever: bool = True):
config = Config() # type: ignore

configure_logging(config=config)

async with asyncio.taskgroups.TaskGroup() as tg:
# Run the event consumer
async with prepare_event_subscriber(config=config) as event_subscriber:
tg.create_task(
event_subscriber.run(forever=run_forever), name="events_task"
)

# Run the outbox consumer
async with prepare_outbox_subscriber(config=config) as outbox_subscriber:
tg.create_task(
outbox_subscriber.run(forever=run_forever), name="outbox_task"
)
async with (
prepare_event_subscriber(config=config) as event_subscriber,
prepare_outbox_subscriber(config=config) as outbox_subscriber,
):
await asyncio.gather(
event_subscriber.run(forever=run_forever),
outbox_subscriber.run(forever=run_forever),
)

0 comments on commit 87215f0

Please sign in to comment.