qena-shared-lib 0.1.2__py3-none-any.whl → 0.1.3__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 +4 -5
- qena_shared_lib/security.py +9 -3
- {qena_shared_lib-0.1.2.dist-info → qena_shared_lib-0.1.3.dist-info}/METADATA +41 -1
- {qena_shared_lib-0.1.2.dist-info → qena_shared_lib-0.1.3.dist-info}/RECORD +6 -6
- {qena_shared_lib-0.1.2.dist-info → qena_shared_lib-0.1.3.dist-info}/WHEEL +0 -0
qena_shared_lib/scheduler.py
CHANGED
@@ -227,10 +227,7 @@ class ScheduleManager(AsyncEventLoopMixin):
|
|
227
227
|
if not self._aquired_lock():
|
228
228
|
return
|
229
229
|
|
230
|
-
if (
|
231
|
-
getattr(self, "_scheduler_task", None) is not None
|
232
|
-
and not self._scheduler_task.done()
|
233
|
-
):
|
230
|
+
if self._scheduler_task is not None and not self._scheduler_task.done():
|
234
231
|
raise RuntimeError("scheduler already running")
|
235
232
|
|
236
233
|
self.use_schedulers()
|
@@ -240,6 +237,8 @@ class ScheduleManager(AsyncEventLoopMixin):
|
|
240
237
|
"tasks" if self.scheduled_task_count > 1 else "task",
|
241
238
|
)
|
242
239
|
|
240
|
+
self._scheduler_task = None
|
241
|
+
|
243
242
|
if self.scheduled_task_count == 0:
|
244
243
|
return
|
245
244
|
|
@@ -256,7 +255,7 @@ class ScheduleManager(AsyncEventLoopMixin):
|
|
256
255
|
self._scheduled_tasks.extend(scheduler.scheduled_tasks)
|
257
256
|
|
258
257
|
def stop(self):
|
259
|
-
if not self._scheduler_task.done():
|
258
|
+
if self._scheduler_task is not None and not self._scheduler_task.done():
|
260
259
|
self._scheduler_task.cancel()
|
261
260
|
|
262
261
|
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.3
|
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=r7zbrvg8-gTfubXAS4bRZFB75dYmU5Ft4rtu5T0kdYM,11875
|
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.3.dist-info/METADATA,sha256=Z_t2uURpudf2bgTf64DOjKOOqbOF7YixzZytUYHKnu8,8520
|
30
|
+
qena_shared_lib-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
31
|
+
qena_shared_lib-0.1.3.dist-info/RECORD,,
|
File without changes
|