def create_queue_entries_for_match(match): """ Create all required queue entries for the supplied match. """ # Increment work_item = { "created": time.time(), "data": json.dumps(match) } queue_name = config.HALO_QUEUE_MATCH work_queue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=queue_name) work_queue.enqueue(json.dumps(work_item))
def enqueue(): queue = request.form['queue'] msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=queue) msg = request.form['message'] msgQueue.enqueue(msg) response = { "result": "success", "message": msg, "queue": queue, "storage_account": config.AZURE_STORAGE_ACCOUNT_NAME } return jsonify(response)
def enqueue(): queue = request.form['queue'] msgQueue = Queue(account_name=config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=queue) msg = request.form['message'] msgQueue.enqueue(msg) response = { "result": "success", "message": msg, "queue": queue, "storage_account": config.AZURE_STORAGE_ACCOUNT_NAME } return jsonify(response)
def simulate(): log = Log() hostname = socket.gethostname() msgQueue = Queue(account_name = config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.AZURE_STORAGE_QUEUE_NAME) if int(config.SIMULATION_ACTIONS) > 0: msg = hostname + ': Attempting to simulate ' + str(config.SIMULATION_ACTIONS) + ' actions' log.debug(msg) notify.info(msg) else: msg = hostname + ': Simulating until stopped' log.debug(msg) notify.info(msg) temp = 70; _actions = 0 while int(config.SIMULATION_ACTIONS) == 0 or int(config.SIMULATION_ACTIONS) - _actions > 0: change = random.randint(-1, 1) if temp <= _too_cold: change = 1 elif temp >= _too_hot: change = -1 msgQueue.enqueue("Change since last reading: " + str(change), level="INFO") temp = temp + change msgQueue.enqueue("Current temperature: " + str(temp), level="INFO") if temp == _just_right: msgQueue.enqueue("That's perfect", level="INFO") elif temp < _just_right and temp > _too_cold: msgQueue.enqueue('Getting a little chilly', level="WARNING") elif temp > _just_right and temp < _too_hot: msgQueue.enqueue('Getting a touch warm', level="WARNING") elif temp <= _too_cold: msgQueue.enqueue('Too cold, how did this happen?', level="ERROR") elif temp >= _too_hot: msgQueue.enqueue('Too hot, how did this happen?', level="ERROR") else: msgQueue.enqueue('Can''t tell if it''s hot or cold', level="ERROR") msgQueue.close() _actions = _actions + 1 time.sleep(int(config.SIMULATION_DELAY)) msg = hostname + ": Simulated " + str(config.SIMULATION_ACTIONS) + " actions and added them to the queue" log.debug(msg) notify.info(msg)
def simulate(): log = Log() hostname = socket.gethostname() msgQueue = Queue(account_name=config.AZURE_STORAGE_ACCOUNT_NAME, account_key=config.AZURE_STORAGE_ACCOUNT_KEY, queue_name=config.AZURE_STORAGE_QUEUE_NAME) if int(config.SIMULATION_ACTIONS) > 0: msg = hostname + ': Attempting to simulate ' + str( config.SIMULATION_ACTIONS) + ' actions' log.debug(msg) notify.info(msg) else: msg = hostname + ': Simulating until stopped' log.debug(msg) notify.info(msg) temp = 70 _actions = 0 while int(config.SIMULATION_ACTIONS) == 0 or int( config.SIMULATION_ACTIONS) - _actions > 0: change = random.randint(-1, 1) if temp <= _too_cold: change = 1 elif temp >= _too_hot: change = -1 msgQueue.enqueue("INFO - Change since last reading: " + str(change)) temp = temp + change msgQueue.enqueue("INFO - Current temperature: " + str(temp)) if temp == _just_right: msgQueue.enqueue("INFO - That's perfect") elif temp < _just_right and temp > _too_cold: msgQueue.enqueue('WARNING - Getting a little chilly') elif temp > _just_right and temp < _too_hot: msgQueue.enqueue('WARNING - Getting a touch warm') elif temp <= _too_cold: msgQueue.enqueue('ERROR - Too cold, how did this happen?') elif temp >= _too_hot: msgQueue.enqueue('ERROR - Too hot, how did this happen?') else: msgQueue.enqueue('ERROR - Can' 't tell if it' 's hot or cold') msgQueue.close() _actions = _actions + 1 time.sleep(int(config.SIMULATION_DELAY)) msg = hostname + ": Simulated " + str( config.SIMULATION_ACTIONS) + " actions and added them to the queue" log.debug(msg) notify.info(msg)