queue_processors: Fix strict_optional errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-07-04 17:48:29 -07:00 committed by Tim Abbott
parent e363382628
commit 8e6a439529
2 changed files with 6 additions and 5 deletions

View File

@ -40,8 +40,6 @@ strict_optional = True
# General exclusions to work on # General exclusions to work on
[mypy-zerver.worker.queue_processors]
strict_optional = False
[mypy-zerver.views.registration] [mypy-zerver.views.registration]
strict_optional = False strict_optional = False

View File

@ -161,12 +161,12 @@ def retry_send_email_failures(
return wrapper return wrapper
class QueueProcessingWorker(ABC): class QueueProcessingWorker(ABC):
queue_name: str = None queue_name: str
CONSUME_ITERATIONS_BEFORE_UPDATE_STATS_NUM = 50 CONSUME_ITERATIONS_BEFORE_UPDATE_STATS_NUM = 50
def __init__(self) -> None: def __init__(self) -> None:
self.q: SimpleQueueClient = None self.q: Optional[SimpleQueueClient] = None
if self.queue_name is None: if not hasattr(self, "queue_name"):
raise WorkerDeclarationException("Queue worker declared without queue_name") raise WorkerDeclarationException("Queue worker declared without queue_name")
self.initialize_statistics() self.initialize_statistics()
@ -268,11 +268,13 @@ class QueueProcessingWorker(ABC):
self.q = SimpleQueueClient() self.q = SimpleQueueClient()
def start(self) -> None: def start(self) -> None:
assert self.q is not None
self.initialize_statistics() self.initialize_statistics()
self.q.register_json_consumer(self.queue_name, self.consume_wrapper) self.q.register_json_consumer(self.queue_name, self.consume_wrapper)
self.q.start_consuming() self.q.start_consuming()
def stop(self) -> None: # nocoverage def stop(self) -> None: # nocoverage
assert self.q is not None
self.q.stop_consuming() self.q.stop_consuming()
class LoopQueueProcessingWorker(QueueProcessingWorker): class LoopQueueProcessingWorker(QueueProcessingWorker):
@ -280,6 +282,7 @@ class LoopQueueProcessingWorker(QueueProcessingWorker):
sleep_only_if_empty = True sleep_only_if_empty = True
def start(self) -> None: # nocoverage def start(self) -> None: # nocoverage
assert self.q is not None
self.initialize_statistics() self.initialize_statistics()
while True: while True:
events = self.q.json_drain_queue(self.queue_name) events = self.q.json_drain_queue(self.queue_name)