aboutsummaryrefslogtreecommitdiffstats
path: root/runner
diff options
context:
space:
mode:
authorGravatar Christopher Baklid <[email protected]>2018-05-22 22:12:43 +0200
committerGravatar Christopher Baklid <[email protected]>2018-05-22 22:12:43 +0200
commitf689ce549689b3192ce1f7510804495acfd7869d (patch)
tree56ac7af58d1b9a8ea59a943e711e337a10220cdd /runner
parentDelete test.py (diff)
adds webapp and docker-compose for more proof of concept
Diffstat (limited to 'runner')
-rw-r--r--runner/config.py8
-rw-r--r--runner/consume.py68
-rw-r--r--runner/publish.py42
3 files changed, 0 insertions, 118 deletions
diff --git a/runner/config.py b/runner/config.py
deleted file mode 100644
index 75b3c28..0000000
--- a/runner/config.py
+++ /dev/null
@@ -1,8 +0,0 @@
-USERNAME = 'guest'
-PASSWORD = 'guest'
-HOST = '172.17.0.2'
-PORT = 5672
-EXCHANGE = 'exchange'
-EXCHANGE_TYPE = 'direct'
-QUEUE = 'text'
-ROUTING_KEY = 'bacon'
diff --git a/runner/consume.py b/runner/consume.py
deleted file mode 100644
index 0e4d79a..0000000
--- a/runner/consume.py
+++ /dev/null
@@ -1,68 +0,0 @@
-import pika
-import traceback
-import sys
-from io import StringIO
-
-from config import (
- USERNAME,
- PASSWORD,
- HOST,
- PORT,
- EXCHANGE,
- EXCHANGE_TYPE,
- QUEUE,
- ROUTING_KEY,
-)
-
-def execute(snippet):
- old_stdout = sys.stdout
- redirected_output = sys.stdout = StringIO()
- failed = False
- try:
- exec(snippet)
- except Exception as e:
- failed = e
- finally:
- sys.stdout = old_stdout
-
- if failed:
- return failed
- return redirected_output.getvalue()
-
-
-def message_handler(ch, method, properties, body):
- msg = body.decode('utf-8')
-
- # Execute code snippets here
- print(f"incoming: {msg}", flush=True)
- result = execute(msg)
- print(result, flush=True)
-
- ch.basic_ack(delivery_tag = method.delivery_tag)
-
-def rabbitmq_consume():
- credentials = pika.PlainCredentials(USERNAME, PASSWORD)
- connection = pika.BlockingConnection(pika.ConnectionParameters(HOST, PORT, '/', credentials))
-
- channel = connection.channel()
- channel.queue_declare(queue=QUEUE, durable=False)
- channel.basic_qos(prefetch_count=1)
- channel.basic_consume(message_handler, queue=QUEUE)
-
- try:
- print(f"""Connecting to
- host: {HOST}
- port: {PORT}
- exchange: {EXCHANGE}
- queue: {QUEUE}""", flush=True)
-
- channel.start_consuming()
-
- except Exception:
- exc = traceback.format_exc()
- print(exc, flush=True)
-
- finally:
- connection.close()
-
-rabbitmq_consume()
diff --git a/runner/publish.py b/runner/publish.py
deleted file mode 100644
index fc18d03..0000000
--- a/runner/publish.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import pika
-from config import (
- USERNAME,
- PASSWORD,
- HOST,
- PORT,
- EXCHANGE,
- EXCHANGE_TYPE,
- QUEUE,
- ROUTING_KEY,
-)
-
-def send(message):
- credentials = pika.PlainCredentials(USERNAME, PASSWORD)
- connection = pika.BlockingConnection(pika.ConnectionParameters(HOST, PORT, '/', credentials))
- properties = pika.BasicProperties(content_type='text/plain', delivery_mode=1)
-
- channel = connection.channel()
- channel.queue_declare(queue=QUEUE, durable=False)
- channel.exchange_declare(exchange=EXCHANGE, exchange_type=EXCHANGE_TYPE)
- channel.queue_bind(exchange=EXCHANGE, queue=QUEUE, routing_key=ROUTING_KEY)
-
- result = channel.basic_publish(
- exchange=EXCHANGE,
- routing_key=ROUTING_KEY,
- body=message,
- properties=properties
- )
-
- if result:
- print(f"""Connecting to
- host: {HOST}
- port: {PORT}
- exchange: {EXCHANGE}
- queue: {QUEUE}""", flush=True)
- print(f"Sent: '{message}'")
- else:
- print("not delivered")
-
- connection.close()
-
-send('print "bacon is delicious"')