def create_app(queue=None): """Returns our Flask app""" if queue is None: queue = IronMQ().queue(QUEUE_NAME) app = Flask(__name__) @app.route('/secret', methods=['GET', 'POST']) def get_secret(): """GET or POST a secret POST: escape, and submit into the queuing service GET: Return the first message from the queue """ if request.method == 'POST': queue.post(escape(request.form[FORM_FIELD])) return '', 201 elif request.method == 'GET': message = queue.get()['messages'].pop() queue.delete(message['id']) return jsonify(secret=message['body']) return app
def get_ironmq_queue_count(active_queues): if not IronMQ: return print("iron_mq not loaded, not getting queue count") assert(settings.IRON_MQ_PROJECT_ID) assert(settings.IRON_MQ_TOKEN) assert(settings.IRON_MQ_HOST) lock = redis.StrictRedis( host=settings.proc_scalar_lock_url.hostname, port=int(settings.proc_scalar_lock_url.port), db=int(settings.proc_scalar_lock_url.path[1:]), password=settings.proc_scalar_lock_url.password ) queue = IronMQ( host=settings.IRON_MQ_HOST, project_id=settings.IRON_MQ_PROJECT_ID, token=settings.IRON_MQ_TOKEN ) if not active_queues: active_queues = {} data = {} for queuename, procname in PROC_MAP.iteritems(): details = {} try: details = queue.getQueueDetails(queuename) print(repr(details)) length = details["size"] except (HTTPException, requests.exceptions.HTTPError): length = 0 if not procname in data: key = "DISABLE_CELERY_%s" % procname lock_type = lock.get(key) if not lock_type == 0: lock_type = 0 data[procname] = {'count': length, 'active': 0, 'deploy_lock': lock_type} else: data[procname]['count'] += length if procname in active_queues: data[procname]['active'] += active_queues[procname] return data
from iron_mq import IronMQ import os project_id = os.getenv("IRON_PROJECT_ID") token = os.getenv("IRON_TOKEN") ironmq = IronMQ(project_id=project_id, token=token) queue = ironmq.queue("requests") # Warning to all... this is probably the worst possible way to # enque a bunch of inorder numbers... you have been warned. # Queue ALL THE THINGS l = range(500000) # but do it in small batches n = 3000 list_of_messages = [l[i:i + n] for i in range(0, len(l), n)] for ls in list_of_messages: # unpack and post the array of #s queue.post(*[str(i) for i in ls])
def get_connection(list_key=Conf.PREFIX): ironmq = IronMQ(name=None, **Conf.IRON_MQ) return ironmq.queue(queue_name=list_key)
from iron_mq import IronMQ ironmq = IronMQ(project_id="", token="") queue = ironmq.queue("requests") # Warning to all... this is probably the worst possible way to # enque a bunch of inorder numbers... you have been warned. # Queue ALL THE THINGS l = range(500000) # but do it in small batches n = 3000 list_of_messages = [l[i:i + n] for i in range(0, len(l), n)] for ls in list_of_messages: # unpack and post the array of #s queue.post(*[str(i) for i in ls])
import sendgrid from iron_helper import WorkerArgs from iron_mq import IronMQ import json args = WorkerArgs() username = args.config["username"] password = args.config["password"] queue_name = args.config["queue"] s = sendgrid.Sendgrid(username, password, secure=True) mq = IronMQ() queue = mq.queue(queue_name) def getMessage(): resp = queue.get() if "messages" not in resp: return None if len(resp["messages"]) < 1: return None return resp["messages"][0] msg = getMessage() print msg while msg is not None: msg["body"] = json.loads(msg["body"]) from_address = None from_name = None if isinstance(msg["body"]["from"], basestring): from_address = msg["body"]["from"]