本文整理汇总了Python中azure.storage.queue.QueueService.get_queue_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python QueueService.get_queue_metadata方法的具体用法?Python QueueService.get_queue_metadata怎么用?Python QueueService.get_queue_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.storage.queue.QueueService
的用法示例。
在下文中一共展示了QueueService.get_queue_metadata方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_queue_details
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import get_queue_metadata [as 别名]
def get_queue_details(creds, resource_group_name, account_name, queue_name):
keys = _get_storage_account_keys(creds, resource_group_name, account_name)
queue_service = QueueService(account_name, keys.key1)
model = StorageAccountQueueDetails()
model.queue_name = queue_name
model.metadata = queue_service.get_queue_metadata(queue_name)
count = int(model.metadata.get("x-ms-approximate-messages-count", "0"))
model.messages = queue_service.peek_messages(queue_name, count) if count else []
for msg in model.messages:
try:
msg.decoded_text = b64decode(msg.message_text).decode()
except:
msg.decoded_text = None
return model
示例2: account_sas
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import get_queue_metadata [as 别名]
def account_sas(self):
queue_name = self._create_queue()
metadata = {'val1': 'foo', 'val2': 'blah'}
self.service.set_queue_metadata(queue_name, metadata=metadata)
# Access to read operations on the queues themselves
# Expires in an hour
token = self.service.generate_account_shared_access_signature(
ResourceTypes.CONTAINER,
AccountPermissions.READ,
datetime.utcnow() + timedelta(hours=1),
)
# Create a service and use the SAS
sas_service = QueueService(
account_name=self.account.account_name,
sas_token=token,
)
metadata = sas_service.get_queue_metadata(queue_name) # metadata={'val1': 'foo', 'val2': 'blah'}
self.service.delete_queue(queue_name)
示例3: __init__
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import get_queue_metadata [as 别名]
class Queue:
def __init__(self, account_name, account_key, queue_name="logqueue"):
"""Initialiaze a queue. The type is set by the
'ACS_LOGGING_QUEUE_TYPE' environment variable. If it is set to
'AzureStorageQueue' then values must be provided for
'account_name' and 'account_key' which are values associated
with the Azure Storage account. 'queue_name' is optional and
defaults to 'logqueue'.
"""
self.log = Log()
self.queue_type = config.ACS_LOGGING_QUEUE_TYPE
self.queue_name = queue_name
# self.log.debug("Queue type: " + self.queue_type + " / " + self.queue_name)
if self.queue_type == "AzureStorageQueue":
self.createAzureQueues(account_name, account_key)
elif self.queue_type == "LocalFile":
self.file_queue = open(config.UNPROCESSED_LOG_FILE, "w+")
else:
self.log.error("Unknown queue type: " + queue_type)
def createAzureQueues(self, account_name, account_key):
"""
Create a queue for unprocessed log messages. Entries in the queue
will be dequeued, processed and deleted upon success.
"""
self.queue_service = QueueService(account_name, account_key)
self.queue_service.create_queue(self.queue_name)
def close(self):
"""Perform any necessary clearnup on the queue
at the end of a run.
"""
if self.queue_type == "AzureStorageQueue":
pass
elif self.queue_type == "LocalFile":
self.file_queue.close()
else:
self.log.error("Unknown queue type: " + queue_type)
def enqueue(self, msg, level="INFO"):
msg = level + " - " + msg
if self.queue_type == "LocalFile":
file_queue.write(msg + "\n")
elif self.queue_type == "AzureStorageQueue":
self.queue_service.put_message(self.queue_name, msg)
self.log.debug(msg)
def dequeue(self):
messages = []
if self.queue_type == "LocalFile":
with open(config.UNPROCESSED_LOG_FILE, "r") as f:
messages = f.readlines()[1]
elif self.queue_type == "AzureStorageQueue":
messages = self.queue_service.get_messages(self.queue_name)
return messages
def delete(self, message):
self.queue_service.delete_message(self.queue_name, message.message_id, message.pop_receipt)
# with open(config.PROCESSED_LOG_FILE, 'a') as processed:
# processed.write(log)
# os.remove(config.UNPROCESSED_LOG_FILE)
def delete_queue(self, queue_name):
self.queue_service.delete_queue(queue_name, False)
def getLength(self):
"""
Get the approximate length of the queue
"""
queue_metadata = self.queue_service.get_queue_metadata(self.queue_name)
count = queue_metadata["x-ms-approximate-messages-count"]
return count
示例4: QueueService
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import get_queue_metadata [as 别名]
# Queue reader - Simple script to read and print entries in the queue
# Pedro Perez - 2015
#
# -----------------------------------------------------------------------------
import sys
import os
import subprocess
from azure.storage.queue import QueueService
account_name = "mcdockerqueue"
account_key = sys.argv[1]
queuename = "servers"
queue_service = QueueService(account_name, account_key)
queue_metadata = queue_service.get_queue_metadata(queuename)
count = queue_metadata['x-ms-approximate-messages-count']
print "There are %s messages in the queue" % count
if count > 0:
messages = queue_service.get_messages(queuename)
for message in messages:
print(message.message_text)
# Remove message from the queue
queue_service.delete_message(queuename, message.message_id, message.pop_receipt)
else:
print "There are no messages to process"