-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
44 lines (30 loc) · 757 Bytes
/
app.py
File metadata and controls
44 lines (30 loc) · 757 Bytes
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
import time
from sanic import Sanic
from sanic.response import text
from rq import Queue
from redis import Redis
redis_conn = Redis(host='queue')
q = Queue(connection=redis_conn)
app = Sanic()
def sleepear():
time.sleep(5)
def sleepear():
time.sleep(5)
@app.route('/ping')
async def ping(request):
return text('pong')
@app.route('/task', methods=['POST'])
async def create_task(request):
q.enqueue("app.sleepear")
# Kick of a redis queue task
q.enqueue('app.sleepear')
return text('runnig', status=201)
@app.route('/task')
async def list_tasks(request):
# list the pending tasks maybe
return text(
str(q.count),
status=200
)
if __name__ == '__main__':
app.run('0.0.0.0', debug=True)