qena-shared-lib 0.1.2__py3-none-any.whl → 0.1.4__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.
- qena_shared_lib/rabbitmq/_exception_handlers.py +1 -0
- qena_shared_lib/scheduler.py +3 -5
- qena_shared_lib/security.py +9 -3
- {qena_shared_lib-0.1.2.dist-info → qena_shared_lib-0.1.4.dist-info}/METADATA +41 -1
- {qena_shared_lib-0.1.2.dist-info → qena_shared_lib-0.1.4.dist-info}/RECORD +6 -6
- {qena_shared_lib-0.1.2.dist-info → qena_shared_lib-0.1.4.dist-info}/WHEEL +0 -0
qena_shared_lib/scheduler.py
CHANGED
@@ -188,6 +188,7 @@ class ScheduleManager(AsyncEventLoopMixin):
|
|
188
188
|
self._logstash = logstash
|
189
189
|
self._scheduled_tasks: list[ScheduledTask] = []
|
190
190
|
self._next_run_in = None
|
191
|
+
self._scheduler_task = None
|
191
192
|
self._logger = LoggerProvider.default().get_logger("schedule_manager")
|
192
193
|
|
193
194
|
def include_scheduler(self, scheduler: Scheduler | type[SchedulerBase]):
|
@@ -227,10 +228,7 @@ class ScheduleManager(AsyncEventLoopMixin):
|
|
227
228
|
if not self._aquired_lock():
|
228
229
|
return
|
229
230
|
|
230
|
-
if (
|
231
|
-
getattr(self, "_scheduler_task", None) is not None
|
232
|
-
and not self._scheduler_task.done()
|
233
|
-
):
|
231
|
+
if self._scheduler_task is not None and not self._scheduler_task.done():
|
234
232
|
raise RuntimeError("scheduler already running")
|
235
233
|
|
236
234
|
self.use_schedulers()
|
@@ -256,7 +254,7 @@ class ScheduleManager(AsyncEventLoopMixin):
|
|
256
254
|
self._scheduled_tasks.extend(scheduler.scheduled_tasks)
|
257
255
|
|
258
256
|
def stop(self):
|
259
|
-
if not self._scheduler_task.done():
|
257
|
+
if self._scheduler_task is not None and not self._scheduler_task.done():
|
260
258
|
self._scheduler_task.cancel()
|
261
259
|
|
262
260
|
self.SCHEDULE_MANAGER_STATE.state("stopped")
|
qena_shared_lib/security.py
CHANGED
@@ -26,7 +26,7 @@ __all__ = [
|
|
26
26
|
]
|
27
27
|
|
28
28
|
|
29
|
-
MESSAGE = "you are not authorized to access requested
|
29
|
+
MESSAGE = "you are not authorized to access requested resource"
|
30
30
|
RESPONSE_CODE = int(environ.get("UNAUTHORIZED_RESPONSE_CODE") or 0)
|
31
31
|
|
32
32
|
|
@@ -92,9 +92,15 @@ class UserInfo(BaseModel):
|
|
92
92
|
async def extract_user_info(
|
93
93
|
jwt_adapter: Annotated[JwtAdapter, DependsOn(JwtAdapter)],
|
94
94
|
token: Annotated[
|
95
|
-
str | None,
|
95
|
+
str | None,
|
96
|
+
Header(
|
97
|
+
alias=environ.get("TOKEN_HEADER") or "authorization",
|
98
|
+
include_in_schema=False,
|
99
|
+
),
|
100
|
+
] = None,
|
101
|
+
user_agent: Annotated[
|
102
|
+
str | None, Header(alias="user-agent", include_in_schema=False)
|
96
103
|
] = None,
|
97
|
-
user_agent: Annotated[str | None, Header(alias="user-agent")] = None,
|
98
104
|
) -> UserInfo:
|
99
105
|
extra = {"userAgent": user_agent} if user_agent is not None else None
|
100
106
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: qena-shared-lib
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: A shared tools for other services
|
5
5
|
Requires-Python: >=3.10
|
6
6
|
Requires-Dist: cronsim~=2.0
|
@@ -30,6 +30,12 @@ A shared tools for other services. It includes.
|
|
30
30
|
|
31
31
|
# Usage
|
32
32
|
|
33
|
+
## Environment variables
|
34
|
+
|
35
|
+
- `LOGGER_NAME` root logger name.
|
36
|
+
- `UNAUTHORIZED_RESPONSE_CODE` an integer response on an authorized access of resource.
|
37
|
+
- `TOKEN_HEADER` to header key for jwt token.
|
38
|
+
|
33
39
|
## Http
|
34
40
|
|
35
41
|
To create fastapi app.
|
@@ -273,6 +279,40 @@ async def get_user(
|
|
273
279
|
return user
|
274
280
|
```
|
275
281
|
|
282
|
+
### Flow control
|
283
|
+
|
284
|
+
``` py
|
285
|
+
@Consumer("UserQueue")
|
286
|
+
class UserConsumer(ListenerBase):
|
287
|
+
|
288
|
+
@consume()
|
289
|
+
async def store_user(self, ctx: ListenerContext, user: User):
|
290
|
+
...
|
291
|
+
|
292
|
+
await ctx.flow_control.request(10)
|
293
|
+
|
294
|
+
...
|
295
|
+
|
296
|
+
```
|
297
|
+
|
298
|
+
### Rpc reply
|
299
|
+
|
300
|
+
Optionally it is possible to reply to rpc calls, through.
|
301
|
+
|
302
|
+
``` py
|
303
|
+
@RpcWorker("UserQueue")
|
304
|
+
class UserWorker(ListenerBase):
|
305
|
+
|
306
|
+
@execute()
|
307
|
+
async def store_user(self, ctx: ListenerContext, user: User):
|
308
|
+
...
|
309
|
+
|
310
|
+
await ctx.rpc_reply.reply("Done")
|
311
|
+
|
312
|
+
...
|
313
|
+
```
|
314
|
+
|
315
|
+
|
276
316
|
## Scheduler
|
277
317
|
|
278
318
|
``` py
|
@@ -6,8 +6,8 @@ qena_shared_lib/exceptions.py,sha256=cNeksC8ZavKgoqKLBik1NR-lCcdLZzITHMXww5deY5Y
|
|
6
6
|
qena_shared_lib/http.py,sha256=90bmDfs522KxKBj2o0vO-MgmDqa3EZOfaNUFp1DuUdQ,23864
|
7
7
|
qena_shared_lib/logging.py,sha256=JL6bAmkK1BJA84rZNpvDEmrec3dogQRpSug4fj1Omkw,1618
|
8
8
|
qena_shared_lib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
qena_shared_lib/scheduler.py,sha256=
|
10
|
-
qena_shared_lib/security.py,sha256=
|
9
|
+
qena_shared_lib/scheduler.py,sha256=qxM3zdKJnAKUWw8i_I2M5o3uL_fEOTaBzYUBL-HvUzg,11874
|
10
|
+
qena_shared_lib/security.py,sha256=cL3I75tF9jSBxjw-1fzQ-YXfkEXYyjMhKQsfXrh-1sA,6141
|
11
11
|
qena_shared_lib/utils.py,sha256=bvPnjaFx7npVGSUO6IKdpiAHfUECsGRCeDW8UOjVckU,845
|
12
12
|
qena_shared_lib/dependencies/__init__.py,sha256=W12RgJbhqZ9GiSV1nLlHmpwPzvQv8t7f4JEoazM_WYg,350
|
13
13
|
qena_shared_lib/dependencies/http.py,sha256=3KopQjq05qbYROMPZjji2Zz7qQLU6_2u3qKisLrjLks,1469
|
@@ -19,13 +19,13 @@ qena_shared_lib/logstash/_tcp_sender.py,sha256=ncvc3wYxOJPkB7c_0W8vboaxMRJ_1UYGd
|
|
19
19
|
qena_shared_lib/rabbitmq/__init__.py,sha256=WKAcKpRXXX9kqfHVEkyX6p2yIWzB07TMsBBWbV8nrKA,1209
|
20
20
|
qena_shared_lib/rabbitmq/_base.py,sha256=rOUpYK3FJu3U5rU4vF--31c_Ycpnt4FL9qGkZNGLnYY,23068
|
21
21
|
qena_shared_lib/rabbitmq/_channel.py,sha256=R0xzZvLkeE4YWsyLhx8bPDramsTFDZIcCgfsDyFmSB4,5429
|
22
|
-
qena_shared_lib/rabbitmq/_exception_handlers.py,sha256=
|
22
|
+
qena_shared_lib/rabbitmq/_exception_handlers.py,sha256=7-WguEUqUSIdbvCIWn10f2CRaWPCM3MDZ6sxSATCCYA,4762
|
23
23
|
qena_shared_lib/rabbitmq/_exceptions.py,sha256=Mg56Uk4eBEwTnWC91_WPS3_8d-yaqNkbb_32IpX_R-c,1208
|
24
24
|
qena_shared_lib/rabbitmq/_listener.py,sha256=1c6Qrz87hL10kaGobTZhI48v3ou88A5u371QdkyZIXA,44153
|
25
25
|
qena_shared_lib/rabbitmq/_pool.py,sha256=1_ftW0D3sPHI6v5c72oA03s05up4-1QqZ7d8icnZeNs,1951
|
26
26
|
qena_shared_lib/rabbitmq/_publisher.py,sha256=48JdpvNzFaw3Bw5LhunFxcjm3qNWz3AXKyXtcpzcohQ,2380
|
27
27
|
qena_shared_lib/rabbitmq/_rpc_client.py,sha256=E-J5PIfA1T3j1y9KoxjNTzSLdK95MbaePulNxiqGb-M,8724
|
28
28
|
qena_shared_lib/rabbitmq/_utils.py,sha256=5WZjYm4MdDrjL1dsrZuT8eKKiWfUef29_FJ262-hfSM,438
|
29
|
-
qena_shared_lib-0.1.
|
30
|
-
qena_shared_lib-0.1.
|
31
|
-
qena_shared_lib-0.1.
|
29
|
+
qena_shared_lib-0.1.4.dist-info/METADATA,sha256=Z1cefuDH6Kwx2RDb2sRpE_cDfIvpBbthMIcOl58gpKw,8520
|
30
|
+
qena_shared_lib-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
31
|
+
qena_shared_lib-0.1.4.dist-info/RECORD,,
|
File without changes
|