diff --git a/backend/tuber/api/emails.py b/backend/tuber/api/emails.py index 15e1f18..59de230 100644 --- a/backend/tuber/api/emails.py +++ b/backend/tuber/api/emails.py @@ -121,6 +121,7 @@ def stream_emails(): "Content-Disposition": "attachment; filename=emails.csv", } return Response(stream_with_context(stream_emails()), headers=headers) +email_csv.generator = True @app.route('/api/event//email//trigger', methods=['POST']) def api_email_trigger(event, email): @@ -158,4 +159,5 @@ def stream_emails(): "Content-Type": "application/json", "Content-Disposition": "attachment; filename=emails.json", } - return Response(stream_with_context(stream_emails()), headers=headers) \ No newline at end of file + return Response(stream_with_context(stream_emails()), headers=headers) +api_email_trigger.generator = True \ No newline at end of file diff --git a/backend/tuber/backgroundjobs.py b/backend/tuber/backgroundjobs.py index c2f8b67..7cfd626 100644 --- a/backend/tuber/backgroundjobs.py +++ b/backend/tuber/backgroundjobs.py @@ -4,6 +4,7 @@ import json import uuid import time +from werkzeug.routing import RequestRedirect from tuber import config from tuber.database import db, r from tuber.models import * @@ -59,7 +60,31 @@ def __del__(self): self.pool.close() self.pool.terminate() + def get_view_function(self, path, method): + adapter = self.application.url_map.bind('localhost') + + try: + match = adapter.match(path, method=method) + except RequestRedirect as e: + # recursively match redirects + return self.get_view_function(e.new_url, method) + except: + # no match + return None + + try: + # return the view function and arguments + return app.view_functions[match[0]], match[1] + except KeyError: + # no view is associated with the endpoint + return None + def __call__(self, environ, start_response): + # If the function says it's a generator then we just return it immediately + func, args = self.get_view_function(environ['PATH_INFO'], environ['REQUEST_METHOD']) + if func and hasattr(func, "generator") and getattr(func, "generator"): + return self.application(environ, start_response) + if environ['PATH_INFO'].startswith("/api/job/"): job_id = environ['PATH_INFO'].split("/api/job/")[1] if r: