nlbone 0.6.17__py3-none-any.whl → 0.6.19__py3-none-any.whl
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.
- nlbone/adapters/db/postgres/audit.py +10 -3
- nlbone/adapters/db/postgres/query_builder.py +3 -1
- nlbone/adapters/repositories/__init__.py +0 -0
- nlbone/adapters/repositories/outbox_repo.py +20 -0
- nlbone/config/settings.py +2 -0
- nlbone/core/application/command_bus.py +25 -0
- nlbone/interfaces/jobs/dispatch_outbox.py +19 -0
- {nlbone-0.6.17.dist-info → nlbone-0.6.19.dist-info}/METADATA +1 -1
- {nlbone-0.6.17.dist-info → nlbone-0.6.19.dist-info}/RECORD +12 -8
- {nlbone-0.6.17.dist-info → nlbone-0.6.19.dist-info}/WHEEL +0 -0
- {nlbone-0.6.17.dist-info → nlbone-0.6.19.dist-info}/entry_points.txt +0 -0
- {nlbone-0.6.17.dist-info → nlbone-0.6.19.dist-info}/licenses/LICENSE +0 -0
|
@@ -8,11 +8,13 @@ from sqlalchemy import event
|
|
|
8
8
|
from sqlalchemy import inspect as sa_inspect
|
|
9
9
|
from sqlalchemy.orm import Session as SASession
|
|
10
10
|
|
|
11
|
+
from nlbone.config.settings import get_settings
|
|
11
12
|
from nlbone.core.domain.models import AuditLog
|
|
12
13
|
from nlbone.utils.context import current_context_dict
|
|
13
14
|
|
|
15
|
+
setting = get_settings()
|
|
14
16
|
DEFAULT_EXCLUDE = {"updated_at", "created_at"}
|
|
15
|
-
DEFAULT_ENABLED =
|
|
17
|
+
DEFAULT_ENABLED = setting.AUDIT_DEFAULT_ENABLE
|
|
16
18
|
DEFAULT_OPS = {"INSERT", "UPDATE", "DELETE"}
|
|
17
19
|
|
|
18
20
|
|
|
@@ -24,12 +26,17 @@ def _get_ops_for(obj) -> set[str]:
|
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
def _is_audit_disabled(obj) -> bool:
|
|
27
|
-
if not DEFAULT_ENABLED:
|
|
28
|
-
return True
|
|
29
29
|
if getattr(obj, "__audit_disable__", False):
|
|
30
30
|
return True
|
|
31
|
+
|
|
32
|
+
if not DEFAULT_ENABLED:
|
|
33
|
+
if hasattr(obj, "__audit_enable__") and getattr(obj, "__audit_enable__"):
|
|
34
|
+
return False
|
|
35
|
+
return True
|
|
36
|
+
|
|
31
37
|
if hasattr(obj, "__audit_enable__") and not getattr(obj, "__audit_enable__"):
|
|
32
38
|
return True
|
|
39
|
+
|
|
33
40
|
return False
|
|
34
41
|
|
|
35
42
|
|
|
@@ -340,8 +340,10 @@ def get_paginated_response(
|
|
|
340
340
|
with_count: bool = True,
|
|
341
341
|
output_cls: Optional[Type] = None,
|
|
342
342
|
eager_options: Optional[Sequence[LoaderOption]] = None,
|
|
343
|
+
query = None
|
|
343
344
|
) -> dict:
|
|
344
|
-
|
|
345
|
+
if not query:
|
|
346
|
+
query = session.query(entity)
|
|
345
347
|
if eager_options:
|
|
346
348
|
query = query.options(*eager_options)
|
|
347
349
|
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
class OutboxRecord(dict):
|
|
4
|
+
pass
|
|
5
|
+
|
|
6
|
+
class OutboxRepository:
|
|
7
|
+
def __init__(self, engine):
|
|
8
|
+
self._engine = engine
|
|
9
|
+
|
|
10
|
+
def add(self, msg) -> None:
|
|
11
|
+
...
|
|
12
|
+
|
|
13
|
+
def fetch_pending(self, limit: int = 100) -> List[OutboxRecord]:
|
|
14
|
+
...
|
|
15
|
+
|
|
16
|
+
def mark_sent(self, msg_id: int) -> None:
|
|
17
|
+
...
|
|
18
|
+
|
|
19
|
+
def schedule_retry(self, msg_id: int, retries: int, backoff_base: int = 2) -> None:
|
|
20
|
+
...
|
nlbone/config/settings.py
CHANGED
|
@@ -43,6 +43,8 @@ class Settings(BaseSettings):
|
|
|
43
43
|
LOG_LEVEL: Literal["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"] = Field(default="INFO")
|
|
44
44
|
LOG_JSON: bool = Field(default=True)
|
|
45
45
|
|
|
46
|
+
AUDIT_DEFAULT_ENABLE: bool = False
|
|
47
|
+
|
|
46
48
|
# ---------------------------
|
|
47
49
|
# HTTP / Timeouts
|
|
48
50
|
# ---------------------------
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Protocol, Type, Any, Dict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass(frozen=True)
|
|
6
|
+
class Command:
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CommandHandler(Protocol):
|
|
11
|
+
def __call__(self, command: Command) -> Any: ...
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CommandBus:
|
|
15
|
+
def __init__(self) -> None:
|
|
16
|
+
self._handlers: Dict[Type[Command], CommandHandler] = {}
|
|
17
|
+
|
|
18
|
+
def register(self, cmd_type: Type[Command], handler: CommandHandler) -> None:
|
|
19
|
+
self._handlers[cmd_type] = handler
|
|
20
|
+
|
|
21
|
+
def dispatch(self, command: Command) -> Any:
|
|
22
|
+
handler = self._handlers.get(type(command))
|
|
23
|
+
if handler is None:
|
|
24
|
+
raise LookupError(f"No handler registered for {type(command).__name__}")
|
|
25
|
+
return handler(command)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from nlbone.adapters.messaging.internal_router import internal_router
|
|
2
|
+
from nlbone.core.ports.event_bus import IntegrationPublisher
|
|
3
|
+
|
|
4
|
+
def run_dispatch_outbox(outbox_repo, publisher: IntegrationPublisher):
|
|
5
|
+
batch = outbox_repo.fetch_pending(limit=200)
|
|
6
|
+
for rec in batch:
|
|
7
|
+
try:
|
|
8
|
+
topic = rec["topic"]
|
|
9
|
+
payload = rec["payload"]
|
|
10
|
+
if topic.startswith("internal."):
|
|
11
|
+
internal_router.handle(topic, payload)
|
|
12
|
+
else:
|
|
13
|
+
publisher.publish(topic, payload)
|
|
14
|
+
outbox_repo.mark_sent(rec["id"])
|
|
15
|
+
except TemporaryError:
|
|
16
|
+
outbox_repo.schedule_retry(rec["id"], rec["retries"])
|
|
17
|
+
except Exception:
|
|
18
|
+
# mark_failed یا retry policy
|
|
19
|
+
outbox_repo.schedule_retry(rec["id"], rec["retries"])
|
|
@@ -12,10 +12,10 @@ nlbone/adapters/cache/pubsub_listener.py,sha256=3vfK4O4EzuQQhTsbZ_bweP06o99kDSyH
|
|
|
12
12
|
nlbone/adapters/cache/redis.py,sha256=2Y1DYHBLCrbHTO6O7pw85u3qY6OnCIFTYJ-HBvBs0FM,4608
|
|
13
13
|
nlbone/adapters/db/__init__.py,sha256=0CDSySEk4jJsqmwI0eNuaaLJOJDt8_iSiHBsFdC-L3s,212
|
|
14
14
|
nlbone/adapters/db/postgres/__init__.py,sha256=6JYJH0xZs3aR-zuyMpRhsdzFugmqz8nprwTQLprqhZc,313
|
|
15
|
-
nlbone/adapters/db/postgres/audit.py,sha256=
|
|
15
|
+
nlbone/adapters/db/postgres/audit.py,sha256=IuWkPitr70UyQ6-GkAedckp8U-Z4cTgzFbdt_bQv1VQ,4800
|
|
16
16
|
nlbone/adapters/db/postgres/base.py,sha256=kha9xmklzhuQAK8QEkNBn-mAHq8dUKbOM-3abaBpWmQ,71
|
|
17
17
|
nlbone/adapters/db/postgres/engine.py,sha256=UCegauVB1gvo42ThytYnn5VIcQBwR-5xhcXYFApRFNk,3448
|
|
18
|
-
nlbone/adapters/db/postgres/query_builder.py,sha256=
|
|
18
|
+
nlbone/adapters/db/postgres/query_builder.py,sha256=wtOIsUJ3iM5-vFxIUfbkM6I13WE4fSw8pJKdVi4jgXY,12544
|
|
19
19
|
nlbone/adapters/db/postgres/repository.py,sha256=J_DBE73JhHPYCk90c5-O7lQtZbxDgqjjN9OcWy4Omvs,1660
|
|
20
20
|
nlbone/adapters/db/postgres/schema.py,sha256=NlE7Rr8uXypsw4oWkdZhZwcIBHQEPIpoHLxcUo98i6s,1039
|
|
21
21
|
nlbone/adapters/db/postgres/uow.py,sha256=nRxNpY-WoWHpym-XeZ8VHm0MYvtB9wuopOeNdV_ebk8,2088
|
|
@@ -32,12 +32,15 @@ nlbone/adapters/messaging/event_bus.py,sha256=w-NPwDiPMLFPU_enRQCtfQXOALsXfg31u5
|
|
|
32
32
|
nlbone/adapters/messaging/redis.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
33
33
|
nlbone/adapters/percolation/__init__.py,sha256=0h1Bw7FzxgkDIHxeoyQXSfegrhP6VbpYV4QC8njYdRE,38
|
|
34
34
|
nlbone/adapters/percolation/connection.py,sha256=1iJISSwMEh4r_6nJI7mYf_v64Q0eeU1eSI0wLIfOK14,415
|
|
35
|
+
nlbone/adapters/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
36
|
+
nlbone/adapters/repositories/outbox_repo.py,sha256=UdvAsasMOMA7M6fV8nEnxh7HXUWg_32ITNTZLIrUXug,433
|
|
35
37
|
nlbone/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
36
38
|
nlbone/config/logging.py,sha256=Ot6Ctf7EQZlW8YNB-uBdleqI6wixn5fH0Eo6QRgNkQk,4358
|
|
37
|
-
nlbone/config/settings.py,sha256=
|
|
39
|
+
nlbone/config/settings.py,sha256=S4Uw7oOmTQSbSDvNBzrpq0arEdhCxF9aZE1Cit2UXmM,3951
|
|
38
40
|
nlbone/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
39
41
|
nlbone/core/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
40
42
|
nlbone/core/application/base_worker.py,sha256=5brIToSd-vi6tw0ukhHnUZGZhOLq1SQ-NRRy-kp6D24,1193
|
|
43
|
+
nlbone/core/application/command_bus.py,sha256=MxjlV5vbhxADB0xtifhPpTAytmLZHjKvEnnaaVbG520,705
|
|
41
44
|
nlbone/core/application/events.py,sha256=eQGLE0aZHuWJsy9J-qRse4CMXOtweH9-2rQ7AIPRMEQ,614
|
|
42
45
|
nlbone/core/application/services.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
46
|
nlbone/core/application/use_case.py,sha256=3GMQZ3CFK5cbLoBNBgohPft6GBq2j9_wr8iKRq_osQA,247
|
|
@@ -84,6 +87,7 @@ nlbone/interfaces/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
|
|
|
84
87
|
nlbone/interfaces/cli/init_db.py,sha256=C67n2MsJ1vzkJxC8zfUYOxFdd6mEB_vT9agxN6jWoG8,790
|
|
85
88
|
nlbone/interfaces/cli/main.py,sha256=pNldsTgplVyXa-Hx96dySO2I9gFRi49nDXv7J_dO73s,686
|
|
86
89
|
nlbone/interfaces/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
90
|
+
nlbone/interfaces/jobs/dispatch_outbox.py,sha256=Hke-DsCqE3ixtTbvCQfh0IB6nqm9XZGIu-qNcApnoA4,804
|
|
87
91
|
nlbone/interfaces/jobs/sync_tokens.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
88
92
|
nlbone/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
89
93
|
nlbone/utils/cache.py,sha256=hVfkR62o5vllDrE_nY4At10wK0It6qpZ45K1xoj10cQ,5931
|
|
@@ -93,8 +97,8 @@ nlbone/utils/context.py,sha256=MmclJ24BG2uvSTg1IK7J-Da9BhVFDQ5ag4Ggs2FF1_w,1600
|
|
|
93
97
|
nlbone/utils/http.py,sha256=UXUoXgQdTRNT08ho8zl-C5ekfDsD8uf-JiMQ323ooqw,872
|
|
94
98
|
nlbone/utils/redactor.py,sha256=-V4HrHmHwPi3Kez587Ek1uJlgK35qGSrwBOvcbw8Jas,1279
|
|
95
99
|
nlbone/utils/time.py,sha256=DjjyQ9GLsfXoT6NK8RDW2rOlJg3e6sF04Jw6PBUrSvg,1268
|
|
96
|
-
nlbone-0.6.
|
|
97
|
-
nlbone-0.6.
|
|
98
|
-
nlbone-0.6.
|
|
99
|
-
nlbone-0.6.
|
|
100
|
-
nlbone-0.6.
|
|
100
|
+
nlbone-0.6.19.dist-info/METADATA,sha256=v185nm1R92gj7OAhj7HYUYlWJc3Dmn5b_mk1Hoxb8IM,2228
|
|
101
|
+
nlbone-0.6.19.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
102
|
+
nlbone-0.6.19.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
|
|
103
|
+
nlbone-0.6.19.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
104
|
+
nlbone-0.6.19.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|