Link together all the containers in the example app.

This commit is contained in:
Tom Wilkie
2015-05-21 17:05:20 +00:00
parent 2dd08d632b
commit c193d69b19
9 changed files with 65 additions and 36 deletions
+2 -1
View File
@@ -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"]
+29 -3
View File
@@ -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