-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
55 lines (38 loc) · 1.4 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
import json
import os
import time
import redis
from flask import Flask, jsonify, render_template
from flask_socketio import SocketIO, disconnect, emit
from rq import Queue
from rq.job import Job
from util import download_data
from worker import conn
q = Queue(connection=conn)
async_mode = None
app = Flask(__name__)
socketio = SocketIO( app, async_mode=async_mode )
@app.route('/', methods=['GET', 'POST'])
def index():
return render_template('index.html', async_mode = socketio.async_mode)
@socketio.on('search', namespace='/tasks')
def article_search(article):
job = q.enqueue_call(func=download_data, args=(article['data'],), timeout=50)
emit('job_id', {'data': str(job.get_id())})
@socketio.on('status', namespace='/tasks')
def status(data):
job = Job.fetch(data['job_id'], connection=conn)
emit('fetching', {'data': str(job.is_finished),
'article': ( json.dumps(job.return_value) if job.is_finished else None) } )
@socketio.on('back', namespace='/tasks')
def back():
id = '14lalKFVdeeRh1ORz0ddRNRetb52Qi80J'
job = q.enqueue_call(func=download_data, args=(id,), timeout=50)
emit('job_id', {'data': str(job.get_id())})
@socketio.on('connect', namespace='/tasks')
def connect():
id = '14lalKFVdeeRh1ORz0ddRNRetb52Qi80J'
job = q.enqueue_call(func=download_data, args=(id,), timeout=50)
emit('job_id', {'data': str(job.get_id())})
if __name__ == '__main__':
socketio.run(app)