getting thrimshim to build and run is a minor success

pull/46/head
Christopher Usher 6 years ago
parent 57597c94cd
commit 5faa70dfc2

@ -8,7 +8,7 @@ set -eu
# Pass PUSH=true to also push the resulting images, or PUSH=latest to push them as :latest tag # Pass PUSH=true to also push the resulting images, or PUSH=latest to push them as :latest tag
# The different images we can build # The different images we can build
COMPONENTS=(downloader restreamer backfiller) COMPONENTS=(downloader restreamer backfiller thrimshim)
# Define push if not already defined # Define push if not already defined
PUSH=${PUSH:-} PUSH=${PUSH:-}

@ -1,7 +1,8 @@
FROM alpine:3.7 FROM alpine:3.7
# dependencies needed for compiling c extensions # dependencies needed for compiling c extensions
# also busybox-extras for telnet for easier use of backdoor # also busybox-extras for telnet for easier use of backdoor
RUN apk --update add py2-pip gcc python-dev musl-dev busybox-extras # plus postgres dependenices
RUN apk --update add py2-pip gcc python-dev musl-dev busybox-extras postgresql-dev postgresql-libs
# Install common lib first as it changes less # Install common lib first as it changes less
COPY common /tmp/common COPY common /tmp/common
@ -11,4 +12,4 @@ RUN pip install /tmp/common && rm -r /tmp/common
COPY thrimshim /tmp/thrimshim COPY thrimshim /tmp/thrimshim
RUN pip install /tmp/thrimshim && rm -r /tmp/thrimshim RUN pip install /tmp/thrimshim && rm -r /tmp/thrimshim
ENTRYPOINT ["python2", "-m", "thrimshim", "--base-dir", "/mnt"] ENTRYPOINT ["python2", "-m", "thrimshim"]

@ -2,6 +2,7 @@ import gevent.monkey
gevent.monkey.patch_all() gevent.monkey.patch_all()
import logging import logging
import os
import argh import argh

@ -1,18 +1,17 @@
import datetime
import json import json
import logging import logging
import signal
import gevent import gevent
import gevent.backdoor import gevent.backdoor
from gevent.pywsgi import WSGIServer from gevent.pywsgi import WSGIServer
import flask import flask
import common
from common import database from common import database
#from stats import stats, after_request
app = flask.Flask('thrimshim') app = flask.Flask('thrimshim')
#app.after_request(after_request)
def cors(app): def cors(app):
"""WSGI middleware that sets CORS headers""" """WSGI middleware that sets CORS headers"""
@ -30,22 +29,19 @@ def cors(app):
return app(environ, _start_response) return app(environ, _start_response)
return handle return handle
@app.route('/thrimshim/<uuid:key>', methods=['GET', 'POST']) @app.route('/thrimshim/<uuid:key>', methods=['GET', 'POST'])
def thrimshim(key): def thrimshim(key):
if flask.request.method == 'POST': if flask.request.method == 'POST':
row = flask.request.json row = flask.request.json
update_row(row)
else: else:
get_row(key)
def date_handler(obj):
def get_row(ident): def get_row(ident):
conn = flask.g.db_manager.get_conn() conn = app.db_manager.get_conn()
with database.transaction(conn): with database.transaction(conn):
result = database.query(conn, 'SELECT * FROM events WHERE id = %s;', ident results = database.query(conn, 'SELECT * FROM events WHERE id = %s;', ident)
row = results[0] row = results[0]
assert row.id == ident assert row.id == ident
response = row._asdict() response = row._asdict()
@ -53,53 +49,50 @@ def get_row(ident):
return json.dump(response) return json.dump(response)
def update_row(ident): #def query_database(ident):
#
# select start, end, catagory, description, notes, video_title, video_description, video_start, video_end, state, error
def query_database(ident): # from database where id is ident
#
select start, end, catagory, description, notes, video_title, video_description, video_start, video_end, state, error #def set_row(data):
from database where id is ident # to_update = unjson(data)
#
def set_row(data): # update_database(to_update)
to_update = unjson(data) #
#def update_database(ident, to_update):
update_database(to_update) #
# if state not in ['UNEDITED, EDITED, CLAIMED']:
def update_database(ident, to_update): # return 'Video already published'
#
if state not in ['UNEDITED, EDITED, CLAIMED']: # insert video_title, video_description, video_start, video_end
return 'Video already published' # #allow_holes, uploader_whitelist, upload_location
# into database where id == indent
insert video_title, video_description, video_start, video_end #
#allow_holes, uploader_whitelist, upload_location # set error to NULL
into database where id == indent # set uploader to NULL
#
set error to NULL # if upload_location:
set uploader to NULL # set state to 'DONE'
#
if upload_location: # if publish:
set state to 'DONE' # set state to 'EDITED'
# else:
if publish: # set state to 'UNEDITED'
set state to 'EDITED'
else:
set state to 'UNEDITED'
def main(host='0.0.0.0', port=8005, connection_string='', backdoor_port=0):
def main(host='0.0.0.0', port=8005, connection_string='', backdoor_port=False):
flask.g.db_manager = database.DBManager(dsn=connection_string)
server = WSGIServer((host, port), cors(app)) server = WSGIServer((host, port), cors(app))
app.db_manager = database.DBManager(dsn=connection_string)
def stop(): def stop():
logging.info("Shutting down") logging.info("Shutting down")
server.stop() server.stop()
gevent.signal(signal.SIGTERM, stop) gevent.signal(signal.SIGTERM, stop)
PromLogCountsHandler.install() common.PromLogCountsHandler.install()
install_stacksampler() common.install_stacksampler()
if backdoor_port: if backdoor_port:
gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start() gevent.backdoor.BackdoorServer(('127.0.0.1', backdoor_port), locals=locals()).start()

Loading…
Cancel
Save