Skip to content

Commit

Permalink
add queueing and multi process support (#48)
Browse files Browse the repository at this point in the history
* add queueing and multi process

* fix some stuff

* fix status

* fix some failure cases

* prevent spurious exception

* add worker id to logs

* fix tests

* some cleanups

* some cleanups, improved test coverage

* fix integration issue

* update version
  • Loading branch information
Peddle authored Dec 12, 2023
1 parent f21f811 commit 5d7ffe1
Show file tree
Hide file tree
Showing 11 changed files with 890 additions and 220 deletions.
25 changes: 24 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time
from potassium import Potassium, Request, Response
from transformers import pipeline
import torch
import os

app = Potassium("my_app")

Expand Down Expand Up @@ -28,5 +30,26 @@ def handler(context: dict, request: Request) -> Response:
status=200
)

@app.background("/background")
def background(context: dict, request: Request):
time.sleep(5)
print('hi')


@app.handler("/stream")
def stream(context: dict, request: Request):
def stream():
for i in range(100):
yield f"{i}\n"
time.sleep(1)


return Response(
body=stream(),
status=200,
headers={"Content-Type": "text/plain"}
)


if __name__ == "__main__":
app.serve()
app.serve()
3 changes: 2 additions & 1 deletion potassium/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .potassium import *
from .hooks import *
from .store import Store, RedisConfig
from .store import Store, RedisConfig
from .types import Request, Response
10 changes: 10 additions & 0 deletions potassium/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class InvalidEndpointTypeException(Exception):
def __init__(self):
super().__init__("Invalid endpoint type. Must be 'handler' or 'background'")


class RouteAlreadyInUseException(Exception):
def __init__(self):
super().__init__("Route already in use")


Loading

0 comments on commit 5d7ffe1

Please sign in to comment.