workercommon 0.4.2__tar.gz → 0.4.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {workercommon-0.4.2 → workercommon-0.4.3}/PKG-INFO +1 -1
- {workercommon-0.4.2 → workercommon-0.4.3}/pyproject.toml +1 -1
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/worker.py +16 -8
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon.egg-info/PKG-INFO +1 -1
- {workercommon-0.4.2 → workercommon-0.4.3}/LICENSE.TXT +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/README.md +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/setup.cfg +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/__init__.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/background.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/commands.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/config.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/connectionpool.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/database/__init__.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/database/base.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/database/pg.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/database/py.typed +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/locking.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/py.typed +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/rabbitmqueue.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon/test.py +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon.egg-info/SOURCES.txt +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon.egg-info/dependency_links.txt +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon.egg-info/not-zip-safe +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon.egg-info/requires.txt +0 -0
- {workercommon-0.4.2 → workercommon-0.4.3}/workercommon.egg-info/top_level.txt +0 -0
|
@@ -4,19 +4,21 @@ import sys
|
|
|
4
4
|
if sys.version_info < (3, 8):
|
|
5
5
|
raise RuntimeError("At least Python 3.8 is required")
|
|
6
6
|
|
|
7
|
-
from pathlib import Path
|
|
8
7
|
from .database import Connection, Cursor
|
|
9
8
|
from . import rabbitmqueue
|
|
10
|
-
import json,
|
|
9
|
+
import json, pika.connection, pika.channel, pika.spec, logging
|
|
11
10
|
from collections.abc import Mapping
|
|
12
|
-
from time import sleep
|
|
13
11
|
from threading import Thread, Lock
|
|
14
12
|
from typing import Iterable, Optional, Any, Callable, List
|
|
15
|
-
from multiprocessing import Process
|
|
13
|
+
from multiprocessing import Process
|
|
16
14
|
from multiprocessing.managers import SyncManager
|
|
17
15
|
from concurrent.futures import ThreadPoolExecutor
|
|
18
16
|
|
|
19
17
|
|
|
18
|
+
class NoDatabase(RuntimeError):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
20
22
|
class BaseWorker(object):
|
|
21
23
|
def start(self) -> None:
|
|
22
24
|
raise NotImplementedError
|
|
@@ -43,7 +45,7 @@ class ThreadWorker(BaseWorker, Thread):
|
|
|
43
45
|
class ReaderWorker(ThreadWorker):
|
|
44
46
|
def __init__(
|
|
45
47
|
self,
|
|
46
|
-
database_source: Callable[[], Connection],
|
|
48
|
+
database_source: Optional[Callable[[], Connection]],
|
|
47
49
|
readq_parameters: rabbitmqueue.Parameters,
|
|
48
50
|
any_exchange: bool = False,
|
|
49
51
|
**readq_arguments: Any,
|
|
@@ -152,7 +154,7 @@ class ReaderWorker(ThreadWorker):
|
|
|
152
154
|
def get_cursor(self) -> Cursor:
|
|
153
155
|
if self.database is None:
|
|
154
156
|
if self.database_source is None:
|
|
155
|
-
raise
|
|
157
|
+
raise NoDatabase("Database source is unavailable")
|
|
156
158
|
self.database = self.database_source()
|
|
157
159
|
|
|
158
160
|
return self.database.cursor()
|
|
@@ -192,8 +194,11 @@ class ReaderWorker(ThreadWorker):
|
|
|
192
194
|
filtered = self.filter_message(root)
|
|
193
195
|
|
|
194
196
|
if filtered is not None:
|
|
195
|
-
|
|
196
|
-
self.
|
|
197
|
+
try:
|
|
198
|
+
with self.get_cursor() as cursor:
|
|
199
|
+
self.handle_message(cursor, filtered)
|
|
200
|
+
except NoDatabase:
|
|
201
|
+
self.handle_message_nodb(filtered)
|
|
197
202
|
|
|
198
203
|
logging.debug(f"Successfully handled {method.delivery_tag}")
|
|
199
204
|
self.get_readq().add_callback_threadsafe(
|
|
@@ -242,6 +247,9 @@ class ReaderWorker(ThreadWorker):
|
|
|
242
247
|
def handle_message(self, cursor: Cursor, message: Any) -> None:
|
|
243
248
|
raise NotImplementedError
|
|
244
249
|
|
|
250
|
+
def handle_message_nodb(self, message: Any) -> None:
|
|
251
|
+
raise NotImplementedError
|
|
252
|
+
|
|
245
253
|
def stop(self) -> None:
|
|
246
254
|
with self.lock:
|
|
247
255
|
if self.readq is not None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|