當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleQueueClient.start_consuming方法代碼示例

本文整理匯總了Python中zerver.lib.queue.SimpleQueueClient.start_consuming方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleQueueClient.start_consuming方法的具體用法?Python SimpleQueueClient.start_consuming怎麽用?Python SimpleQueueClient.start_consuming使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zerver.lib.queue.SimpleQueueClient的用法示例。


在下文中一共展示了SimpleQueueClient.start_consuming方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: QueueProcessingWorker

# 需要導入模塊: from zerver.lib.queue import SimpleQueueClient [as 別名]
# 或者: from zerver.lib.queue.SimpleQueueClient import start_consuming [as 別名]
class QueueProcessingWorker(object):
    def __init__(self):
        self.q = SimpleQueueClient()

    def consume_wrapper(self, data):
        try:
            self.consume(data)
        except Exception:
            self._log_problem()
            if not os.path.exists(settings.QUEUE_ERROR_DIR):
                os.mkdir(settings.QUEUE_ERROR_DIR)
            fname = '%s.errors' % (self.queue_name,)
            fn = os.path.join(settings.QUEUE_ERROR_DIR, fname)
            line = '%s\t%s\n' % (time.asctime(), ujson.dumps(data))
            lock_fn = fn + '.lock'
            with lockfile(lock_fn):
                with open(fn, 'a') as f:
                    f.write(line)
        reset_queries()

    def _log_problem(self):
        logging.exception("Problem handling data on queue %s" % (self.queue_name,))

    def start(self):
        self.q.register_json_consumer(self.queue_name, self.consume_wrapper)
        self.q.start_consuming()

    def stop(self):
        self.q.stop_consuming()
開發者ID:bgupta,項目名稱:zulip,代碼行數:31,代碼來源:queue_processors.py

示例2: QueueProcessingWorker

# 需要導入模塊: from zerver.lib.queue import SimpleQueueClient [as 別名]
# 或者: from zerver.lib.queue.SimpleQueueClient import start_consuming [as 別名]
class QueueProcessingWorker(object):
    queue_name = None  # type: str

    def __init__(self):
        # type: () -> None
        self.q = None  # type: SimpleQueueClient
        if self.queue_name is None:
            raise WorkerDeclarationException("Queue worker declared without queue_name")

    def consume(self, data):
        # type: (Mapping[str, Any]) -> None
        raise WorkerDeclarationException("No consumer defined!")

    def consume_wrapper(self, data):
        # type: (Mapping[str, Any]) -> None
        try:
            self.consume(data)
        except Exception:
            self._log_problem()
            if not os.path.exists(settings.QUEUE_ERROR_DIR):
                os.mkdir(settings.QUEUE_ERROR_DIR)
            fname = '%s.errors' % (self.queue_name,)
            fn = os.path.join(settings.QUEUE_ERROR_DIR, fname)
            line = u'%s\t%s\n' % (time.asctime(), ujson.dumps(data))
            lock_fn = fn + '.lock'
            with lockfile(lock_fn):
                with open(fn, 'ab') as f:
                    f.write(line.encode('utf-8'))
            check_and_send_restart_signal()
        finally:
            reset_queries()

    def _log_problem(self):
        # type: () -> None
        logging.exception("Problem handling data on queue %s" % (self.queue_name,))

    def setup(self):
        # type: () -> None
        self.q = SimpleQueueClient()

    def start(self):
        # type: () -> None
        self.q.register_json_consumer(self.queue_name, self.consume_wrapper)
        self.q.start_consuming()

    def stop(self):
        # type: () -> None
        self.q.stop_consuming()
開發者ID:yhl-python,項目名稱:zulip,代碼行數:50,代碼來源:queue_processors.py

示例3: QueueProcessingWorker

# 需要導入模塊: from zerver.lib.queue import SimpleQueueClient [as 別名]
# 或者: from zerver.lib.queue.SimpleQueueClient import start_consuming [as 別名]
class QueueProcessingWorker(object):
    queue_name = None

    def __init__(self):
        self.q = SimpleQueueClient()
        if self.queue_name is None:
            raise WorkerDeclarationException("Queue worker declared without queue_name")

    def consume(self, data):
        raise WorkerDeclarationException("No consumer defined!")

    def consume_wrapper(self, data):
        try:
            self.consume(data)
        except Exception:
            self._log_problem()
            if not os.path.exists(settings.QUEUE_ERROR_DIR):
                os.mkdir(settings.QUEUE_ERROR_DIR)
            fname = "%s.errors" % (self.queue_name,)
            fn = os.path.join(settings.QUEUE_ERROR_DIR, fname)
            line = "%s\t%s\n" % (time.asctime(), ujson.dumps(data))
            lock_fn = fn + ".lock"
            with lockfile(lock_fn):
                with open(fn, "a") as f:
                    f.write(line.encode("utf-8"))
        reset_queries()

    def _log_problem(self):
        logging.exception("Problem handling data on queue %s" % (self.queue_name,))

    def start(self):
        self.q.register_json_consumer(self.queue_name, self.consume_wrapper)
        self.q.start_consuming()

    def stop(self):
        self.q.stop_consuming()
開發者ID:SummerBulb,項目名稱:zulip,代碼行數:38,代碼來源:queue_processors.py


注:本文中的zerver.lib.queue.SimpleQueueClient.start_consuming方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。