本文整理匯總了Python中dbclient.DbClient.getOutboxMessages方法的典型用法代碼示例。如果您正苦於以下問題:Python DbClient.getOutboxMessages方法的具體用法?Python DbClient.getOutboxMessages怎麽用?Python DbClient.getOutboxMessages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dbclient.DbClient
的用法示例。
在下文中一共展示了DbClient.getOutboxMessages方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: flushOutboxInSeparateThread
# 需要導入模塊: from dbclient import DbClient [as 別名]
# 或者: from dbclient.DbClient import getOutboxMessages [as 別名]
def flushOutboxInSeparateThread(self):
'''This can take quite a while to do the flush'''
if self._flushing:
return
print("Outgoing postman is flushing the outbox...")
self._flushing = True
# Look in the outbox for messages
messagesFound = 0
messagesSent = 0
failedRecpts = set()
for m in DbClient.getOutboxMessages():
messagesFound += 1
# Get recipient, timestamp, relays, message
message = m['message']
sendTimestamp = m.get('timestamp', None) # not used yet
# TODO: if the timestamp is too old, then either just delete the message (if it's not to be queued) or move to inbox
# Some messages have a single recipient (and maybe relays), others only have a recipientList
recipient = m.get('recipient', None)
if recipient:
sendSuccess = self.RC_MESSAGE_FAILED if recipient in failedRecpts else self.sendMessage(message, recipient)
if sendSuccess == self.RC_MESSAGE_IGNORED:
print("Dealt with message so I should delete it from the db:", m["_id"])
DbClient.deleteMessageFromOutbox(m["_id"])
elif sendSuccess == self.RC_MESSAGE_SENT:
print("Sent message so I should delete it from the db:", m["_id"])
DbClient.deleteMessageFromOutbox(m["_id"])
messagesSent += 1
testMsg = "Message sent, type was %s and recipient was %s" % (m.get("msgType", "unknown"), recipient)
# TODO: Pass these values with the signal as an object, not a string
self.emit(QtCore.SIGNAL("messageSent"), testMsg)
elif not m.get('queue', False):
print("I failed to send a message but it shouldn't be queued, deleting it")
DbClient.deleteMessageFromOutbox(m["_id"])
failedRecpts.add(recipient)
else:
print("I failed to send but I'll keep the message and try again later")
failedRecpts.add(recipient)
else:
# There isn't a direct recipient, so let's hope there's a recipient list
recipientList = m.get('recipientList', None)
if recipientList:
print("I've got a message to relay to: ", recipientList)
failedRecipientsForThisMessage = set()
# TODO: Try to send to each in the list
# TODO: Does the parent even need to know when a send has worked?
if messagesSent > 0:
self.parent.postmanKnock() # only once
if messagesFound > 0:
print("For %d found messages, I managed to send %d copies" % (messagesFound, messagesSent))
# We tried to send a message to these recipients but failed - set them to be offline
for r in failedRecpts:
Contacts.goneOffline(r)
self._flushing = False