mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-18 20:07:06 +00:00
Link together all the containers in the example app.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
FROM python:2.7
|
||||
MAINTAINER Weaveworks Inc <help@weave.works>
|
||||
ADD . /home/weave
|
||||
WORKDIR /home/weave
|
||||
ADD requirements.txt /home/weave/
|
||||
RUN pip install -r /home/weave/requirements.txt
|
||||
ADD app.py /home/weave/
|
||||
ENTRYPOINT ["python", "/home/weave/app.py"]
|
||||
|
||||
@@ -1,15 +1,41 @@
|
||||
import os
|
||||
|
||||
import socket
|
||||
import requests
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from flask import Flask
|
||||
from redis import Redis
|
||||
|
||||
app = Flask(__name__)
|
||||
redis = Redis(host='redis', port=6379)
|
||||
pool = ThreadPoolExecutor(max_workers=10)
|
||||
|
||||
def do_redis():
|
||||
redis.incr('hits')
|
||||
return redis.get('hits')
|
||||
|
||||
def do_qotd():
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
s.connect(("qotd", 4446))
|
||||
s.send("Hello")
|
||||
return s.recv(1024)
|
||||
finally:
|
||||
s.close()
|
||||
|
||||
def do_search():
|
||||
r = requests.get('http://goapp:8080/')
|
||||
return r.text
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
redis.incr('hits')
|
||||
return 'Hello World! I have been seen %s times.' % redis.get('hits')
|
||||
counter_future = pool.submit(do_redis)
|
||||
search_future = pool.submit(do_search)
|
||||
qotd_future = pool.submit(do_qotd)
|
||||
result = 'Hello World! I have been seen %s times.' % counter_future.result()
|
||||
result += search_future.result()
|
||||
result += qotd_future.result()
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", debug=True)
|
||||
|
||||
@@ -2,4 +2,3 @@ flask
|
||||
redis
|
||||
requests
|
||||
futures
|
||||
requests-futures
|
||||
|
||||
Reference in New Issue
Block a user