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


Python queue.SimpleQueueClient類代碼示例

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


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

示例1: handle

 def handle(self, *args, **options):
     # type: (*Any, **str) -> None
     queue_name = options['queue_name']
     queue = SimpleQueueClient()
     queue.ensure_queue(queue_name, lambda: None)
     queue.channel.queue_purge(queue_name)
     print("Done")
開發者ID:150vb,項目名稱:zulip,代碼行數:7,代碼來源:purge_queue.py

示例2: QueueProcessingWorker

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,代碼行數:29,代碼來源:queue_processors.py

示例3: QueueProcessingWorker

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,代碼行數:48,代碼來源:queue_processors.py

示例4: QueueProcessingWorker

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,代碼行數:36,代碼來源:queue_processors.py

示例5: setup

 def setup(self):
     self.q = SimpleQueueClient()
開發者ID:150vb,項目名稱:zulip,代碼行數:2,代碼來源:queue_processors.py

示例6: purge_queue

 def purge_queue(queue_name: str) -> None:
     queue = SimpleQueueClient()
     queue.ensure_queue(queue_name, lambda: None)
     queue.channel.queue_purge(queue_name)
開發者ID:brockwhittaker,項目名稱:zulip,代碼行數:4,代碼來源:purge_queue.py

示例7: setup

 def setup(self) -> None:
     self.q = SimpleQueueClient()
開發者ID:BakerWang,項目名稱:zulip,代碼行數:2,代碼來源:queue_processors.py

示例8: __init__

 def __init__(self):
     self.q = SimpleQueueClient()
開發者ID:bgupta,項目名稱:zulip,代碼行數:2,代碼來源:queue_processors.py

示例9: __init__

 def __init__(self):
     self.q = SimpleQueueClient()
     if self.queue_name is None:
         raise WorkerDeclarationException("Queue worker declared without queue_name")
開發者ID:Croolis,項目名稱:zulip,代碼行數:4,代碼來源:queue_processors.py

示例10: handle

 def handle(self, *args, **options):
     queue_name = options["queue_name"]
     queue = SimpleQueueClient()
     queue.ensure_queue(queue_name, lambda: None)
     queue.channel.queue_purge(queue_name)
     print "Done"
開發者ID:nskillen,項目名稱:zulip,代碼行數:6,代碼來源:purge_queue.py


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