forked from symus/devops1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
37 lines (28 loc) · 1.07 KB
/
app.py
File metadata and controls
37 lines (28 loc) · 1.07 KB
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
import os, pika
from flask import Flask, request, jsonify, render_template
app = Flask(__name__)
host = os.getenv("RABBITMQ_HOST", "localhost")
port = os.getenv("RABBITMQ_PORT", 5672)
queue = os.getenv("RABBITMQ_QUEUE", "hello")
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
flavour=request.form.get("flavour")
app.logger.info(flavour)
enqueue(flavour)
return render_template("landing.html")
@app.route('/health', methods=['GET'])
def health():
return jsonify({"status": "ok"})
def enqueue(value):
app.logger.info("Received message: %s", value)
params = pika.ConnectionParameters(host=host, port=port)
connection = pika.BlockingConnection(params)
channel = connection.channel()
channel.queue_declare(queue=queue)
channel.basic_publish(exchange='', routing_key=queue, body=value)
connection.close()
app.logger.info("Enqueued message on host %s:%s queue %s: %s", host, port,
queue, value)
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=8000)