Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
update app.py to provide a cache route for retrieving pdfs; updated r…
Browse files Browse the repository at this point in the history
…esource route to enable CORS; updated docker-compose to include volumes to share info cache directory between app and queue-worker
  • Loading branch information
jeffreycwitt committed Aug 29, 2019
1 parent 05c4eb3 commit 89a80c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 13 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import subprocess

from logging.config import dictConfig
from flask import Flask, request, jsonify
from flask import Flask, request, make_response, jsonify
from flask.logging import default_handler
from flask import send_from_directory

import lbp_print.core as lbp_print
import lbp_print.config as lbp_config
Expand Down Expand Up @@ -35,7 +36,7 @@
)

# App version
__VERSION__ = subprocess.check_output("git describe --tags", shell=True).decode()
#__VERSION__ = subprocess.check_output("git describe --tags", shell=True).decode()

app = Flask(__name__, instance_path=os.getcwd())

Expand All @@ -50,7 +51,7 @@ def process_resource():
resource_url = request.args.get("url")
if not resource_id and not resource_url:
error_message = {
"error": "One of the parameters 'id' and 'url' must be given. 'id' must container an SCTA resource id, e.g. scta.info/resource/lectio1. 'url' must contain an http reference to an XML file, e.g. https://raw.githubusercontent.com/scta-texts/da-49/master/da-49-l1q1/da-49-l1q1.xml"
"error": "One of the parameters 'id' and 'url' must be given. 'id' must container an SCTA resource id, e.g. scta.info/resource/lectio1. 'url' must contain an http reference to an XML file,$
}
return jsonify(error_message)
elif resource_id and resource_url:
Expand All @@ -66,10 +67,17 @@ def process_resource():
resource_value = resource_url
resource_type = "url"

response = handle_job(resource_value, resource_type)
#response = handle_job(resource_value, resource_type)
#return jsonify(response)

return jsonify(response)
response = handle_job(resource_value, resource_type)
resp = make_response(jsonify(response),200)
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp

@app.route("/api/v1/cache/<hashwithextension>", methods=['GET'])
def return_cache(hashwithextension):
return send_from_directory("cache", hashwithextension)

if __name__ == "__main__":
app.run(debug=True, port=5000)
5 changes: 4 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ services:
build: .
ports:
- 5000:5000
volumes:
- ../lbp-print-cache:/usr/src/app/cache
queue-worker:
build: .
command: python3 worker.py
depends_on:
- redis
volumes:
- ../lbp-print-cache:/usr/src/app/cache
redis:
image: "redis:alpine"

0 comments on commit 89a80c6

Please sign in to comment.