-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
75 lines (59 loc) · 1.62 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from flask import (
Flask, abort, Blueprint, flash, render_template, redirect, request,
url_for, flash, jsonify
)
from loguru import logger
from rq import Queue
import rq_dashboard
from worker import conn, redis_url
q = Queue(connection=conn)
app = Flask(__name__)
app.config['LOG_LEVEL'] = os.getenv('LOG_LEVEL', 'DEBUG')
app.config['RQ_DASHBOARD_REDIS_URL'] = redis_url
app.config.from_object(rq_dashboard.default_settings)
app.register_blueprint(
rq_dashboard.blueprint, url_prefix='/rq/'
)
jobs = []
@app.route('/upload', methods=['POST'])
def upload():
logger.info(f'upload() request.files: {request.files}')
video_file = request.files.get('file')
fname_video = video_file.filename
video_stream = video_file.read()
with open(fname_video, 'wb') as f:
f.write(video_stream)
one_week = 60 * 60 * 24 * 7
job = q.enqueue(
'vision.get_tracking_video',
args=(fname_video,),
timeout=one_week
)
job.filename = fname_video
jobs.append(job)
logger.info(f'job: {job}')
return {
'status': 200,
'mimetype': 'application/json'
}
@app.route('/test')
def test():
logger.info('test()')
one_day = 60 * 60 * 24
result = q.enqueue(
'utils.count_words_at_url',
'http://news.ycombinator.com',
job_timeout=one_day
)
logger.info(f'q: {q}')
logger.info(f'result: {result}')
return 'Enqueued'
@app.route('/')
def index():
logger.info(f'jobs: {jobs}')
# TODO: use websockets to update client without refresh
return render_template(
'index.html',
jobs=jobs
)