Skip to content

Commit

Permalink
publish package to pip (#6)
Browse files Browse the repository at this point in the history
* Update pyproject.toml

* Create release-to-pypi.yaml

* rename to async processor

* update the name of package

* fix tests
  • Loading branch information
nikp1172 authored Aug 30, 2023
1 parent 9033638 commit 7d0acd2
Show file tree
Hide file tree
Showing 21 changed files with 319 additions and 261 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/release-to-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish pip package to Packagr
on:
push:
tags:
- v*

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install poetry
run: pip install poetry poetry-dynamic-versioning

- name: Set version
run: poetry-dynamic-versioning

- name: Build project
run: poetry build

- name: Publish distribution 📦 to Packagr
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
user: __token__
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

## Install
```console
pip install "async_service[sqs] @ git+https://github.com/truefoundry/async_service.git@main"
pip install "async_processor[sqs] @ git+https://github.com/truefoundry/async_processor.git@main"
```

## Quick start

### Write the Processor
#### `app.py`
```python
from async_service import (
from async_processor import (
InputMessage,
Processor,
WorkerConfig,
Expand Down Expand Up @@ -77,7 +77,7 @@ Output:
import json
import uuid

from async_service import InputMessage, OutputMessage, ProcessStatus
from async_processor import InputMessage, OutputMessage, ProcessStatus
import boto3


Expand Down
8 changes: 4 additions & 4 deletions async_service/__init__.py → async_processor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from async_service.app import ProcessorApp
from async_service.function_service import FunctionAsyncExecutor
from async_service.processor import Processor
from async_service.types import (
from async_processor.app import ProcessorApp
from async_processor.function_service import FunctionAsyncExecutor
from async_processor.processor import Processor
from async_processor.types import (
AWSAccessKeyAuth,
Input,
InputConfig,
Expand Down
13 changes: 9 additions & 4 deletions async_service/app.py → async_processor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
from fastapi.responses import Response
from prometheus_client import CollectorRegistry, make_asgi_app, multiprocess

from async_service.logger import logger
from async_service.types import InputMessage, OutputMessage, ProcessStatus, WorkerConfig
from async_service.worker import Worker
from async_processor.logger import logger
from async_processor.types import (
InputMessage,
OutputMessage,
ProcessStatus,
WorkerConfig,
)
from async_processor.worker import Worker

if TYPE_CHECKING:
from async_service.processor import Processor
from async_processor.processor import Processor


def _json_serializer(obj: Any) -> bytes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Install
```console
pip install "async_service[nats] @ git+https://github.com/truefoundry/async_service.git@main"
pip install "async_processor[nats] @ git+https://github.com/truefoundry/async_processor.git@main"
```

## Quick start
Expand Down Expand Up @@ -30,7 +30,7 @@ Note: Currently only the following types are supported as arguments - `int`, `st
### Create the FastAPI applications
### `main.py`
```python
from async_service import (
from async_processor import (
WorkerConfig,
FunctionAsyncExecutor,
NATSInputConfig,
Expand Down
5 changes: 5 additions & 0 deletions async_processor/function_service/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from async_processor.function_service.async_function_deployment import (
FunctionAsyncExecutor,
)

__all__ = ["FunctionAsyncExecutor"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

from fastapi import FastAPI, HTTPException

from async_service.function_service.utils import (
from async_processor.function_service.utils import (
INTERNAL_FUNCTION_NAME,
AsyncOutputResponse,
async_wrapper_func,
get_functions_dict_with_input_signatures,
validate_function_name,
)
from async_service.processor import Processor
from async_service.types import (
from async_processor.processor import Processor
from async_processor.types import (
InputMessage,
OutputMessage,
OutputMessageFetchTimeoutError,
Expand All @@ -37,7 +37,7 @@ class FunctionAsyncExecutor:
build_worker_app: Build and return an asynchronous worker application for executing functions.
Usage Example:
from async_service import (
from async_processor import (
WorkerConfig,
FunctionAsyncExecutor,
SQSInputConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pydantic
from pydantic import BaseModel

from async_service.types import Input, InputMessage
from async_processor.types import Input, InputMessage

INTERNAL_FUNCTION_NAME = "internal_func_name"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
)
from nats.js.errors import BadRequestError

from async_service.logger import logger
from async_service.types import (
from async_processor.logger import logger
from async_processor.types import (
Input,
InputFetchAckFailure,
InputMessageFetchFailure,
Expand Down
4 changes: 2 additions & 2 deletions async_service/processor.py → async_processor/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import orjson
from fastapi import FastAPI

from async_service.app import ProcessorApp
from async_service.types import InputMessage, OutputMessage, WorkerConfig
from async_processor.app import ProcessorApp
from async_processor.types import InputMessage, OutputMessage, WorkerConfig


class Processor(abc.ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@

from prometheus_client import Counter, Gauge

from async_service.logger import logger
from async_service.types import (
from async_processor.logger import logger
from async_processor.types import (
InputFetchAckFailure,
InputMessageFetchFailure,
ProcessStatus,
)

_MESSAGES_IN_PROCESS = Gauge(
"tfy_async_service_messages_in_process",
"tfy_async_processor_messages_in_process",
"Number of messages currently being processed by the worker",
multiprocess_mode="livesum",
)

_MESSAGES_PROCESSED = Counter(
"tfy_async_service_messages_processed",
"tfy_async_processor_messages_processed",
"Number of messages processed by the worker",
["status"],
)

_MESSAGE_PROCESSING_TIME_MS = Gauge(
"tfy_async_service_processing_time_ms",
"tfy_async_processor_processing_time_ms",
"Time taken to process a single message in milliseconds",
multiprocess_mode="livemax",
)

_OUTPUT_MESSAGE_PUBLISH_TIME_MS = Gauge(
"tfy_async_service_output_message_publish_time_ms",
"tfy_async_processor_output_message_publish_time_ms",
"Time taken to publish output message in milliseconds",
multiprocess_mode="livemax",
)

_OUTPUT_MESSAGE_PUBLISH_FAILURES = Counter(
"tfy_async_service_output_message_publish_failures",
"tfy_async_processor_output_message_publish_failures",
"Number of times output message publish has failed",
)

_INPUT_MESSAGE_FETCH_FAILURES = Counter(
"tfy_async_service_input_message_fetch_failures",
"tfy_async_processor_input_message_fetch_failures",
"Number of times input message fetching has failed",
)

_INPUT_MESSAGE_FETCH_ACK_FAILURES = Counter(
"tfy_async_service_input_message_fetch_ack_failures",
"tfy_async_processor_input_message_fetch_ack_failures",
"Number of times input message acking has failed",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import boto3
from starlette.concurrency import run_in_threadpool

from async_service.logger import logger
from async_service.types import (
from async_processor.logger import logger
from async_processor.types import (
Input,
InputFetchAckFailure,
InputMessageFetchFailure,
Expand Down
8 changes: 4 additions & 4 deletions async_service/types.py → async_processor/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SQSInputConfig(InputConfig):
wait_time_seconds: conint(ge=1, le=20) = 19

def to_input(self) -> Input:
from async_service.sqs_pub_sub import SQSInput
from async_processor.sqs_pub_sub import SQSInput

return SQSInput(self)

Expand All @@ -96,7 +96,7 @@ class NATSInputConfig(InputConfig):
wait_time_seconds: confloat(ge=1) = 5

def to_input(self) -> Input:
from async_service.nats_pub_sub import NATSInput
from async_processor.nats_pub_sub import NATSInput

return NATSInput(self)

Expand Down Expand Up @@ -131,7 +131,7 @@ class SQSOutputConfig(OutputConfig):
auth: Optional[AWSAccessKeyAuth] = None

def to_output(self) -> Output:
from async_service.sqs_pub_sub import SQSOutput
from async_processor.sqs_pub_sub import SQSOutput

return SQSOutput(self)

Expand All @@ -143,7 +143,7 @@ class NATSOutputConfig(OutputConfig):
root_subject: str

def to_output(self) -> Output:
from async_service.nats_pub_sub import NATSOutput
from async_processor.nats_pub_sub import NATSOutput

return NATSOutput(self)

Expand Down
13 changes: 9 additions & 4 deletions async_service/worker.py → async_processor/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@

from starlette.concurrency import run_in_threadpool

from async_service.logger import logger
from async_service.prometheus_metrics import (
from async_processor.logger import logger
from async_processor.prometheus_metrics import (
collect_input_message_fetch_metrics,
collect_output_message_publish_metrics,
collect_total_message_processing_metrics,
)
from async_service.types import InputMessage, OutputMessage, ProcessStatus, WorkerConfig
from async_processor.types import (
InputMessage,
OutputMessage,
ProcessStatus,
WorkerConfig,
)

if TYPE_CHECKING:
from async_service.processor import Processor
from async_processor.processor import Processor


class Worker:
Expand Down
5 changes: 0 additions & 5 deletions async_service/function_service/__init__.py

This file was deleted.

Loading

0 comments on commit 7d0acd2

Please sign in to comment.