def fetch_update_hints(settings, lock): hints = {} logging.info("Getting and processing hints...") try: messages = _fetch_all_messages(settings) except Exception, error: raise JensMessagingError("Could not retrieve messages (%s)" % error)
def purge_queue(): settings = Settings() try: queue = Queue(settings.MESSAGING_QUEUEDIR, schema=MSG_SCHEMA) return queue.purge() except OSError, error: raise JensMessagingError("Failed to purge Queue object (%s)" % error)
def count_pending_hints(): settings = Settings() try: queue = Queue(settings.MESSAGING_QUEUEDIR, schema=MSG_SCHEMA) return queue.count() except OSError, error: raise JensMessagingError("Failed to create Queue object (%s)" % error)
def enqueue_hint(settings, partition, name): if partition not in ("modules", "hostgroups", "common"): raise JensMessagingError("Unknown partition '%s'" % partition) hint = { 'time' : datetime.now().isoformat(), 'data' : pickle.dumps({partition : [name]}) } _queue_item(settings, hint) logging.info("Hint '%s/%s' added to the queue" % (partition, name))
def _fetch_all_messages(settings): try: queue = Queue(settings.MESSAGING_QUEUEDIR, schema=MSG_SCHEMA) except OSError, error: raise JensMessagingError("Failed to create Queue object (%s)" % error)
'time' : datetime.now().isoformat(), 'data' : pickle.dumps({partition : [name]}) } _queue_item(settings, hint) logging.info("Hint '%s/%s' added to the queue" % (partition, name)) def _queue_item(settings, item): try: queue = Queue(settings.MESSAGING_QUEUEDIR, schema=MSG_SCHEMA) except OSError, error: raise JensMessagingError("Failed to create Queue object (%s)" % error) try: queue.add(item) except QueueError, error: raise JensMessagingError("Failed to element (%s)" % error) def count_pending_hints(settings): try: queue = Queue(settings.MESSAGING_QUEUEDIR, schema=MSG_SCHEMA) return queue.count() except OSError, error: raise JensMessagingError("Failed to create Queue object (%s)" % error) def _fetch_all_messages(settings): try: queue = Queue(settings.MESSAGING_QUEUEDIR, schema=MSG_SCHEMA) except OSError, error: raise JensMessagingError("Failed to create Queue object (%s)" % error) msgs = [] for i, name in enumerate(queue):
def _queue_item(item): settings = Settings() try: queue = Queue(settings.MESSAGING_QUEUEDIR, schema=MSG_SCHEMA) except OSError, error: raise JensMessagingError("Failed to create Queue object (%s)" % error)