renaming
This commit is contained in:
parent
40777ae609
commit
092a0e2964
@ -25,7 +25,7 @@ def make_streamable_and_wrap_in_packing_logic(fn, batched):
|
||||
return fn
|
||||
|
||||
|
||||
class QueuedFunction:
|
||||
class QueuedStreamFunction:
|
||||
def __init__(self, fn):
|
||||
self.queue = Queue()
|
||||
self.fn = fn
|
||||
@ -39,17 +39,17 @@ class QueuedFunction:
|
||||
|
||||
|
||||
class LazyRestProcessor:
|
||||
def __init__(self, queued_function: QueuedFunction, submit_suffix="submit", pickup_suffix="pickup"):
|
||||
def __init__(self, queued_stream_function: QueuedStreamFunction, submit_suffix="submit", pickup_suffix="pickup"):
|
||||
self.submit_suffix = submit_suffix
|
||||
self.pickup_suffix = pickup_suffix
|
||||
self.queued_function = queued_function
|
||||
self.queued_stream_function = queued_stream_function
|
||||
|
||||
def push(self, request):
|
||||
self.queued_function.push(request.json)
|
||||
self.queued_stream_function.push(request.json)
|
||||
return jsonify(request.base_url.replace(self.submit_suffix, self.pickup_suffix))
|
||||
|
||||
def pop(self):
|
||||
result = self.queued_function.pop() or Nothing
|
||||
result = self.queued_stream_function.pop() or Nothing
|
||||
|
||||
if not valid(result):
|
||||
logger.error(f"Received invalid result: {result}")
|
||||
@ -70,9 +70,9 @@ def valid(result):
|
||||
return isinstance(result, dict) or result is Nothing
|
||||
|
||||
|
||||
def set_up_processing_server(queued_function: QueuedFunction):
|
||||
def set_up_processing_server(queued_stream_function: QueuedStreamFunction):
|
||||
app = Flask(__name__)
|
||||
processor = LazyRestProcessor(queued_function, submit_suffix="submit", pickup_suffix="pickup")
|
||||
processor = LazyRestProcessor(queued_stream_function, submit_suffix="submit", pickup_suffix="pickup")
|
||||
|
||||
@app.route("/ready", methods=["GET"])
|
||||
def ready():
|
||||
|
||||
6
test/fixtures/server.py
vendored
6
test/fixtures/server.py
vendored
@ -10,7 +10,7 @@ from funcy import retry, first, compose
|
||||
from waitress import serve
|
||||
|
||||
from pyinfra.server.bufferizer.lazy_bufferizer import FlatStreamBuffer
|
||||
from pyinfra.server.server import set_up_processing_server, make_streamable_and_wrap_in_packing_logic, QueuedFunction
|
||||
from pyinfra.server.server import set_up_processing_server, make_streamable_and_wrap_in_packing_logic, QueuedStreamFunction
|
||||
from pyinfra.utils.func import starlift
|
||||
from test.utils.image import image_to_bytes
|
||||
|
||||
@ -39,8 +39,8 @@ def url(host, port):
|
||||
@pytest.fixture
|
||||
def server(processor_fn, buffer_size):
|
||||
flat_stream_buffer = FlatStreamBuffer(processor_fn, buffer_size=buffer_size)
|
||||
queued_function = QueuedFunction(compose(first, flat_stream_buffer))
|
||||
return set_up_processing_server(queued_function)
|
||||
queued_stream_function = QueuedStreamFunction(compose(first, flat_stream_buffer))
|
||||
return set_up_processing_server(queued_stream_function)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@ -3,7 +3,7 @@ from funcy import repeatedly, takewhile, notnone, lmap, lmapcat
|
||||
|
||||
from pyinfra.server.bufferizer.lazy_bufferizer import FlatStreamBuffer, StreamBuffer
|
||||
from pyinfra.server.dispatcher.dispatcher import Nothing
|
||||
from pyinfra.server.server import QueuedFunction
|
||||
from pyinfra.server.server import QueuedStreamFunction
|
||||
from pyinfra.utils.func import lift, foreach
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ def test_flat_stream_buffer(func, inputs, outputs, buffer_size):
|
||||
|
||||
def test_queued_function(func, inputs, outputs):
|
||||
|
||||
lazy_processor = QueuedFunction(lift(func))
|
||||
lazy_processor = QueuedStreamFunction(lift(func))
|
||||
|
||||
foreach(lazy_processor.push, inputs)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user