endpoint suffixes passed to stream processor
This commit is contained in:
parent
8c1ad64464
commit
1d09337378
@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import flask
|
||||||
from flask import Flask, jsonify, request
|
from flask import Flask, jsonify, request
|
||||||
from funcy import compose, flatten
|
from funcy import compose, flatten
|
||||||
|
|
||||||
@ -33,12 +34,14 @@ class RestOndDemandProcessor(OnDemandProcessor):
|
|||||||
class RestStreamProcessor(RestOndDemandProcessor):
|
class RestStreamProcessor(RestOndDemandProcessor):
|
||||||
"""Wraps an on-demand-processor. Combine with a webserver that provides the endpoints 'submit' and 'pickup'."""
|
"""Wraps an on-demand-processor. Combine with a webserver that provides the endpoints 'submit' and 'pickup'."""
|
||||||
|
|
||||||
def __init__(self, fn):
|
def __init__(self, fn, submit_suffix="submit", pickup_suffix="pickup"):
|
||||||
super(RestStreamProcessor, self).__init__(fn=fn)
|
super(RestStreamProcessor, self).__init__(fn=fn)
|
||||||
|
self.submit_suffix = submit_suffix
|
||||||
|
self.pickup_suffix = pickup_suffix
|
||||||
|
|
||||||
def submit(self, request, **kwargs):
|
def submit(self, request, **kwargs):
|
||||||
super(RestStreamProcessor, self).submit(request)
|
super(RestStreamProcessor, self).submit(request)
|
||||||
return jsonify(f"{request.base_url.replace('/submit', '')}/pickup")
|
return jsonify(request.base_url.replace(self.submit_suffix, self.pickup_suffix))
|
||||||
|
|
||||||
def pickup(self):
|
def pickup(self):
|
||||||
result = self.compute_next()
|
result = self.compute_next()
|
||||||
@ -64,7 +67,7 @@ def valid(result):
|
|||||||
|
|
||||||
def set_up_processing_server(process_fn):
|
def set_up_processing_server(process_fn):
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
stream = RestStreamProcessor(process_fn)
|
stream = RestStreamProcessor(process_fn, submit_suffix="submit", pickup_suffix="pickup")
|
||||||
|
|
||||||
@app.route("/ready", methods=["GET"])
|
@app.route("/ready", methods=["GET"])
|
||||||
def ready():
|
def ready():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user