From 0d5dbd189ed2314a0a4f161ab1ea15a0ae26eff0 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Wed, 3 Sep 2014 13:30:23 -0500 Subject: [PATCH] Proof of concept Redis FIFO --- awx/main/queue.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 awx/main/queue.py diff --git a/awx/main/queue.py b/awx/main/queue.py new file mode 100644 index 0000000000..a99f34cc90 --- /dev/null +++ b/awx/main/queue.py @@ -0,0 +1,30 @@ +# Copyright (c) 2014, Ansible, Inc. +# All Rights Reserved. + +import json + +from redis import StrictRedis + +redis = StrictRedis('127.0.0.1') # FIXME: Don't hard-code. + + +class FifoQueue(object): + """An abstraction class implemented for a simple push/pull queue. + + Intended to allow alteration of backend details in a single, consistent + way throughout the Tower application. + """ + def __init__(self, queue_name): + """Instantiate a queue object, which is able to interact with a + particular queue. + """ + self._queue_name = queue_name + + def push(self, value): + """Push a value onto the right side of the queue.""" + redis.rpush(self._queue_name, json.dumps(value)) + + def pop(self): + """Retrieve a value from the left side of the queue.""" + return json.loads(redis.lpop(self._queue_name)) +