Proof of concept Redis FIFO

This commit is contained in:
Luke Sneeringer 2014-09-03 13:30:23 -05:00
parent c3cc163702
commit 0d5dbd189e

30
awx/main/queue.py Normal file
View File

@ -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))