Last active
December 27, 2020 17:24
-
-
Save DhruvaDave/f0f71094a3d0b2980c4f7a5a0390d4a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
import pika | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return 'OK' | |
@app.route('/create-job/<msg>') | |
def add(cmd): | |
try: | |
connection = pika.BlockingConnection(pika.ConnectionParameters(host="rabbitmq")) | |
except pika.exceptions.AMQPConnectionError as exc: | |
print("Failed to connect to RabbitMQ service. Message wont be sent.") | |
return | |
channel = connection.channel() | |
channel.queue_declare(queue='task_queue', durable=True) | |
channel.basic_publish( | |
exchange='', | |
routing_key='task_queue', | |
body=cmd, | |
properties=pika.BasicProperties( | |
delivery_mode=2, # make message persistent | |
)) | |
connection.close() | |
return " ___ Sent: %s" % cmd | |
if __name__ == '__main__': | |
app.run(debug=True, host='0.0.0.0') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:18.04 | |
RUN apt-get update -y && \ | |
apt-get install -y python3-pip python3-dev | |
COPY ./requirements.txt /app/requirements.txt | |
WORKDIR /app | |
RUN pip3 install pika && \ | |
pip3 install -r requirements.txt | |
COPY . /app | |
ENTRYPOINT [ "python3" ] | |
CMD [ "app.py" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Flask==1.1.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment