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
# The different images we can build
COMPONENTS=(downloader restreamer backfiller)
COMPONENTS=(downloader restreamer backfiller thrimshim)
# Define push if not already defined
PUSH=${PUSH:-}

@ -1,7 +1,8 @@
FROM alpine:3.7
# dependencies needed for compiling c extensions
# 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
COPY common /tmp/common
@ -11,4 +12,4 @@ RUN pip install /tmp/common && rm -r /tmp/common
COPY thrimshim /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()
import logging
import os
import argh

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

Loading…
Cancel
Save