Flow API - update gateway (#357)

* Altered API to incorporate Flow IDs, refactored for dynamic start/stop of flows
* Gateway: Split endpoint / dispatcher for maintainability
This commit is contained in:
cybermaggedon 2025-05-02 21:11:50 +01:00 committed by GitHub
parent 450f664b1b
commit a70ae9793a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 1206 additions and 907 deletions

View file

@ -15,17 +15,22 @@ class Publisher:
self.q = asyncio.Queue(maxsize=max_size)
self.chunking_enabled = chunking_enabled
self.running = True
self.task = None
async def start(self):
self.task = asyncio.create_task(self.run())
async def stop(self):
self.running = False
await self.task
if self.task:
await self.task
async def join(self):
await self.stop()
await self.task
if self.task:
await self.task
async def run(self):

View file

@ -19,6 +19,7 @@ class Subscriber:
self.lock = asyncio.Lock()
self.running = True
self.metrics = metrics
self.task = None
def __del__(self):
self.running = False
@ -28,11 +29,15 @@ class Subscriber:
async def stop(self):
self.running = False
await self.task
if self.task:
await self.task
async def join(self):
await self.stop()
await self.task
if self.task:
await self.task
async def run(self):
@ -45,6 +50,8 @@ class Subscriber:
try:
# FIXME: Create consumer in start method so we know
# it is definitely running when start completes
consumer = self.client.subscribe(
topic = self.topic,
subscription_name = self.subscription,

View file

@ -1,7 +1,6 @@
from pulsar.schema import JsonSchema
from .. schema import EmbeddingsRequest, EmbeddingsResponse
from .. schema import embeddings_request_queue, embeddings_response_queue
from . base import BaseClient
import _pulsar
@ -23,12 +22,6 @@ class EmbeddingsClient(BaseClient):
pulsar_api_key=None,
):
if input_queue == None:
input_queue=embeddings_request_queue
if output_queue == None:
output_queue=embeddings_response_queue
super(EmbeddingsClient, self).__init__(
log_level=log_level,
subscriber=subscriber,
@ -43,4 +36,3 @@ class EmbeddingsClient(BaseClient):
def request(self, text, timeout=300):
return self.call(text=text, timeout=timeout).vectors