arpakitlib 1.7.250__py3-none-any.whl → 1.7.253__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.
- arpakitlib/_arpakit_project_template/alembic/README +1 -0
- arpakitlib/_arpakit_project_template/alembic/env.py +83 -0
- arpakitlib/_arpakit_project_template/alembic/script.py.mako +26 -0
- arpakitlib/_arpakit_project_template/alembic.ini +119 -0
- arpakitlib/_arpakit_project_template/example.env +5 -14
- arpakitlib/_arpakit_project_template/manage/docker_rm_postgres.sh +3 -0
- arpakitlib/_arpakit_project_template/manage/docker_run_postgres.sh +4 -3
- arpakitlib/_arpakit_project_template/manage/docker_start_postgres.sh +2 -1
- arpakitlib/_arpakit_project_template/manage/docker_stop_postgres.sh +2 -1
- arpakitlib/_arpakit_project_template/manage/git_set_arpakit_company_origin.sh +4 -2
- arpakitlib/_arpakit_project_template/manage/git_set_arpakit_origin.sh +4 -2
- arpakitlib/_arpakit_project_template/src/additional_model/additional_model.py +0 -7
- arpakitlib/_arpakit_project_template/src/api/auth.py +52 -0
- arpakitlib/_arpakit_project_template/src/api/create_api_app.py +22 -15
- arpakitlib/_arpakit_project_template/src/api/create_handle_exception_.py +13 -13
- arpakitlib/_arpakit_project_template/src/api/event.py +28 -6
- arpakitlib/_arpakit_project_template/src/api/transmitted_api_data.py +3 -11
- arpakitlib/_arpakit_project_template/src/core/settings.py +3 -111
- arpakitlib/_arpakit_project_template/src/just_script/example.py +16 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/_start_operation_executor_worker.py +1 -1
- arpakitlib/_arpakit_project_template/src/operation_execution/_start_scheduled_operation_creator_worker.py +1 -1
- arpakitlib/_arpakit_project_template/src/sql_db/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/{db → sql_db}/_check_conn_sqlalchemy_db.py +1 -1
- arpakitlib/_arpakit_project_template/src/{db → sql_db}/_drop_sqlalchemy_db.py +1 -1
- arpakitlib/_arpakit_project_template/src/{db → sql_db}/_init_sqlalchemy_db.py +1 -1
- arpakitlib/_arpakit_project_template/src/{db → sql_db}/_reinit_sqlalchemy_db.py +1 -1
- arpakitlib/_arpakit_project_template/src/{operation_execution → sql_db}/_remove_operations.py +1 -1
- arpakitlib/_arpakit_project_template/src/sql_db/_remove_story_logs.py +16 -0
- arpakitlib/_arpakit_project_template/src/{db → sql_db}/util.py +6 -8
- arpakitlib/_arpakit_project_template/src/tg_bot/transmitted_tg_data.py +3 -14
- arpakitlib/ar_aiogram_util.py +27 -4
- arpakitlib/ar_arpakit_project_template_util.py +8 -18
- arpakitlib/ar_arpakit_schedule_uust_api_client_util.py +5 -4
- arpakitlib/ar_arpakitlib_cli_util.py +10 -22
- arpakitlib/ar_class_util.py +0 -1
- arpakitlib/ar_cryptomus_api_client_util.py +21 -0
- arpakitlib/ar_fastapi_util.py +106 -73
- arpakitlib/ar_operation_execution_util.py +7 -7
- arpakitlib/ar_schedule_uust_api_client_util.py +24 -24
- arpakitlib/ar_settings_util.py +166 -14
- arpakitlib/ar_sqlalchemy_model_util.py +1 -1
- arpakitlib/ar_sqlalchemy_util.py +4 -4
- arpakitlib/ar_steam_payment_api_client_util.py +21 -0
- arpakitlib/ar_wata_api_client.py +21 -0
- {arpakitlib-1.7.250.dist-info → arpakitlib-1.7.253.dist-info}/METADATA +1 -1
- {arpakitlib-1.7.250.dist-info → arpakitlib-1.7.253.dist-info}/RECORD +53 -42
- /arpakitlib/_arpakit_project_template/src/core/{_check_settings.py → _show_settings.py} +0 -0
- /arpakitlib/_arpakit_project_template/src/{db → just_script}/__init__.py +0 -0
- /arpakitlib/_arpakit_project_template/src/{db → sql_db}/const.py +0 -0
- /arpakitlib/_arpakit_project_template/src/{db → sql_db}/sqlalchemy_model.py +0 -0
- {arpakitlib-1.7.250.dist-info → arpakitlib-1.7.253.dist-info}/LICENSE +0 -0
- {arpakitlib-1.7.250.dist-info → arpakitlib-1.7.253.dist-info}/WHEEL +0 -0
- {arpakitlib-1.7.250.dist-info → arpakitlib-1.7.253.dist-info}/entry_points.txt +0 -0
arpakitlib/ar_fastapi_util.py
CHANGED
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
4
4
|
|
5
5
|
import asyncio
|
6
6
|
import datetime as dt
|
7
|
+
import inspect
|
7
8
|
import logging
|
8
9
|
import os.path
|
9
10
|
import pathlib
|
@@ -24,14 +25,17 @@ from starlette import status
|
|
24
25
|
from starlette.middleware.cors import CORSMiddleware
|
25
26
|
from starlette.staticfiles import StaticFiles
|
26
27
|
|
28
|
+
from arpakitlib.ar_datetime_util import now_utc_dt
|
27
29
|
from arpakitlib.ar_dict_util import combine_dicts
|
28
30
|
from arpakitlib.ar_enumeration_util import Enumeration
|
29
31
|
from arpakitlib.ar_exception_util import exception_to_traceback_str
|
32
|
+
from arpakitlib.ar_file_storage_in_dir_util import FileStorageInDir
|
30
33
|
from arpakitlib.ar_func_util import raise_if_not_async_func, is_async_object
|
34
|
+
from arpakitlib.ar_json_db_util import JSONDb
|
31
35
|
from arpakitlib.ar_json_util import safely_transfer_obj_to_json_str_to_json_obj, safely_transfer_obj_to_json_str
|
32
|
-
from arpakitlib.
|
36
|
+
from arpakitlib.ar_settings_util import BaseSettings2
|
33
37
|
from arpakitlib.ar_sqlalchemy_model_util import StoryLogDBM, OperationDBM
|
34
|
-
from arpakitlib.ar_sqlalchemy_util import
|
38
|
+
from arpakitlib.ar_sqlalchemy_util import SQLAlchemyDb
|
35
39
|
from arpakitlib.ar_type_util import raise_for_type, raise_if_none
|
36
40
|
|
37
41
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
@@ -212,19 +216,20 @@ class APIException(fastapi.exceptions.HTTPException):
|
|
212
216
|
|
213
217
|
def create_handle_exception(
|
214
218
|
*,
|
215
|
-
|
216
|
-
|
219
|
+
funcs_before: list[Callable | None] | None = None,
|
220
|
+
async_funcs_after: list[Callable | None] | None = None,
|
217
221
|
) -> Callable:
|
218
|
-
if
|
219
|
-
|
220
|
-
|
222
|
+
if funcs_before is None:
|
223
|
+
funcs_before = []
|
224
|
+
funcs_before = [v for v in funcs_before if v is not None]
|
221
225
|
|
222
|
-
if
|
223
|
-
|
224
|
-
|
226
|
+
if async_funcs_after is None:
|
227
|
+
async_funcs_after = []
|
228
|
+
async_funcs_after = [v for v in async_funcs_after if v is not None]
|
225
229
|
|
226
|
-
async def
|
227
|
-
request: starlette.requests.Request,
|
230
|
+
async def func(
|
231
|
+
request: starlette.requests.Request,
|
232
|
+
exception: Exception
|
228
233
|
) -> APIJSONResponse:
|
229
234
|
status_code = starlette.status.HTTP_500_INTERNAL_SERVER_ERROR
|
230
235
|
|
@@ -266,10 +271,10 @@ def create_handle_exception(
|
|
266
271
|
status_code = starlette.status.HTTP_500_INTERNAL_SERVER_ERROR
|
267
272
|
error_so.error_code = BaseAPIErrorCodes.unknown_error
|
268
273
|
|
269
|
-
if error_so.error_code:
|
274
|
+
if error_so.error_code is not None:
|
270
275
|
error_so.error_code = error_so.error_code.upper().replace(" ", "_").strip()
|
271
276
|
|
272
|
-
if error_so.error_specification_code:
|
277
|
+
if error_so.error_specification_code is not None:
|
273
278
|
error_so.error_specification_code = (
|
274
279
|
error_so.error_specification_code.upper().replace(" ", "_").strip()
|
275
280
|
)
|
@@ -280,23 +285,29 @@ def create_handle_exception(
|
|
280
285
|
if error_so.error_code == BaseAPIErrorCodes.cannot_authorize:
|
281
286
|
status_code = status.HTTP_401_UNAUTHORIZED
|
282
287
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
288
|
+
error_so.error_data["status_code"] = status_code
|
289
|
+
|
290
|
+
# funcs_before
|
291
|
+
|
292
|
+
_transmitted_kwargs = {}
|
293
|
+
for func_before in funcs_before:
|
294
|
+
_func_data = func_before(
|
295
|
+
request=request, status_code=status_code, error_so=error_so, exception=exception,
|
296
|
+
transmitted_kwargs=_transmitted_kwargs
|
287
297
|
)
|
288
298
|
if is_async_object(_func_data):
|
289
299
|
_func_data = await _func_data
|
290
300
|
if _func_data is not None:
|
291
|
-
|
292
|
-
raise_for_type(status_code, int)
|
301
|
+
error_so, _transmitted_kwargs = _func_data[0], _func_data[1]
|
293
302
|
raise_for_type(error_so, ErrorSO)
|
294
|
-
raise_for_type(
|
303
|
+
raise_for_type(_transmitted_kwargs, dict)
|
304
|
+
|
305
|
+
# async_funcs_after
|
295
306
|
|
296
|
-
for
|
297
|
-
raise_if_not_async_func(
|
298
|
-
_ = asyncio.create_task(
|
299
|
-
|
307
|
+
for async_func_after in async_funcs_after:
|
308
|
+
raise_if_not_async_func(async_func_after)
|
309
|
+
_ = asyncio.create_task(async_func_after(
|
310
|
+
request=request, status_code=status_code, error_so=error_so, exception=exception
|
300
311
|
))
|
301
312
|
|
302
313
|
return APIJSONResponse(
|
@@ -304,71 +315,77 @@ def create_handle_exception(
|
|
304
315
|
status_code=status_code
|
305
316
|
)
|
306
317
|
|
307
|
-
return
|
318
|
+
return func
|
308
319
|
|
309
320
|
|
310
|
-
def
|
321
|
+
def logging__api_func_before_in_handle_exception(
|
311
322
|
*,
|
312
323
|
ignore_api_error_codes: list[str] | None = None,
|
313
324
|
ignore_status_codes: list[int] | None = None,
|
314
325
|
ignore_exception_types: list[type[Exception]] | None = None,
|
315
326
|
need_exc_info: bool = False
|
316
|
-
):
|
327
|
+
) -> Callable:
|
328
|
+
current_func_name = inspect.currentframe().f_code.co_name
|
329
|
+
|
317
330
|
def func(
|
318
331
|
*,
|
332
|
+
request: starlette.requests.Request,
|
319
333
|
status_code: int,
|
320
334
|
error_so: ErrorSO,
|
321
|
-
request: starlette.requests.Request,
|
322
335
|
exception: Exception,
|
336
|
+
transmitted_kwargs: dict[str, Any],
|
323
337
|
**kwargs
|
324
|
-
) -> (
|
325
|
-
|
338
|
+
) -> (ErrorSO, dict[str, Any]):
|
339
|
+
transmitted_kwargs[current_func_name] = now_utc_dt()
|
326
340
|
|
327
341
|
if ignore_api_error_codes and error_so.error_code in ignore_api_error_codes:
|
328
|
-
return
|
342
|
+
return error_so, transmitted_kwargs
|
329
343
|
|
330
344
|
if ignore_status_codes and status_code in ignore_status_codes:
|
331
|
-
return
|
345
|
+
return error_so, transmitted_kwargs
|
332
346
|
|
333
347
|
if ignore_exception_types and (
|
334
348
|
exception in ignore_exception_types or type(exception) in ignore_exception_types
|
335
349
|
):
|
336
|
-
return
|
350
|
+
return error_so, transmitted_kwargs
|
337
351
|
|
338
352
|
_logger.error(safely_transfer_obj_to_json_str(error_so.model_dump()), exc_info=need_exc_info)
|
339
353
|
|
340
354
|
return func
|
341
355
|
|
342
356
|
|
343
|
-
def
|
357
|
+
def story_log__api_func_before_in_handle_exception(
|
344
358
|
*,
|
345
|
-
sqlalchemy_db:
|
359
|
+
sqlalchemy_db: SQLAlchemyDb,
|
346
360
|
ignore_api_error_codes: list[str] | None = None,
|
347
361
|
ignore_status_codes: list[int] | None = None,
|
348
362
|
ignore_exception_types: list[type[Exception]] | None = None
|
349
363
|
) -> Callable:
|
350
|
-
raise_for_type(sqlalchemy_db,
|
364
|
+
raise_for_type(sqlalchemy_db, SQLAlchemyDb)
|
365
|
+
|
366
|
+
current_func_name = inspect.currentframe().f_code.co_name
|
351
367
|
|
352
368
|
async def async_func(
|
353
369
|
*,
|
370
|
+
request: starlette.requests.Request,
|
354
371
|
status_code: int,
|
355
372
|
error_so: ErrorSO,
|
356
|
-
request: starlette.requests.Request,
|
357
373
|
exception: Exception,
|
374
|
+
transmitted_kwargs: dict[str, Any],
|
358
375
|
**kwargs
|
359
|
-
) -> (
|
360
|
-
|
376
|
+
) -> (ErrorSO, dict[str, Any]):
|
377
|
+
transmitted_kwargs[current_func_name] = now_utc_dt()
|
361
378
|
|
362
379
|
if ignore_api_error_codes and error_so.error_code in ignore_api_error_codes:
|
363
|
-
return
|
380
|
+
return error_so, transmitted_kwargs
|
364
381
|
|
365
382
|
if ignore_status_codes and status_code in ignore_status_codes:
|
366
|
-
return
|
383
|
+
return error_so, transmitted_kwargs
|
367
384
|
|
368
385
|
if ignore_exception_types and (
|
369
386
|
exception in ignore_exception_types or type(exception) in ignore_exception_types
|
370
387
|
):
|
371
|
-
return
|
388
|
+
return error_so, transmitted_kwargs
|
372
389
|
|
373
390
|
async with sqlalchemy_db.new_async_session() as session:
|
374
391
|
story_log_dbm = StoryLogDBM(
|
@@ -384,9 +401,9 @@ def story_log_func_before_response(
|
|
384
401
|
await session.refresh(story_log_dbm)
|
385
402
|
|
386
403
|
error_so.error_data.update({"story_log_long_id": story_log_dbm.long_id})
|
387
|
-
|
404
|
+
transmitted_kwargs["story_log_id"] = story_log_dbm.id
|
388
405
|
|
389
|
-
return
|
406
|
+
return error_so, transmitted_kwargs
|
390
407
|
|
391
408
|
return async_func
|
392
409
|
|
@@ -463,7 +480,7 @@ class ARPAKITLibSO(BaseSO):
|
|
463
480
|
arpakitlib: bool = True
|
464
481
|
|
465
482
|
|
466
|
-
def
|
483
|
+
def create_needed_api_router():
|
467
484
|
api_router = APIRouter()
|
468
485
|
|
469
486
|
@api_router.get(
|
@@ -490,9 +507,7 @@ def add_needed_api_router_to_app(*, app: FastAPI):
|
|
490
507
|
content=ARPAKITLibSO(arpakitlib=True)
|
491
508
|
)
|
492
509
|
|
493
|
-
|
494
|
-
|
495
|
-
return app
|
510
|
+
return api_router
|
496
511
|
|
497
512
|
|
498
513
|
class BaseStartupAPIEvent:
|
@@ -517,6 +532,18 @@ class BaseTransmittedAPIData(BaseModel):
|
|
517
532
|
model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True, from_attributes=True)
|
518
533
|
|
519
534
|
|
535
|
+
class SimpleTransmittedAPIData(BaseTransmittedAPIData):
|
536
|
+
settings: BaseSettings2 | None = None
|
537
|
+
|
538
|
+
|
539
|
+
class AdvancedTransmittedAPIData(SimpleTransmittedAPIData):
|
540
|
+
sqlalchemy_db: SQLAlchemyDb | None = None
|
541
|
+
json_db: JSONDb | None = None
|
542
|
+
media_file_storage_in_dir: FileStorageInDir | None = None
|
543
|
+
cache_file_storage_in_dir: FileStorageInDir | None = None
|
544
|
+
dump_file_storage_in_dir: FileStorageInDir | None = None
|
545
|
+
|
546
|
+
|
520
547
|
def get_transmitted_api_data(request: starlette.requests.Request) -> BaseTransmittedAPIData:
|
521
548
|
return request.app.state.transmitted_api_data
|
522
549
|
|
@@ -574,7 +601,9 @@ def base_api_auth(
|
|
574
601
|
ac: fastapi.security.HTTPAuthorizationCredentials | None = fastapi.Security(
|
575
602
|
fastapi.security.HTTPBearer(auto_error=False)
|
576
603
|
),
|
577
|
-
api_key_string: str | None = Security(
|
604
|
+
api_key_string: str | None = Security(
|
605
|
+
APIKeyHeader(name="apikey", auto_error=False)
|
606
|
+
),
|
578
607
|
request: starlette.requests.Request,
|
579
608
|
transmitted_api_data: BaseTransmittedAPIData = Depends(get_transmitted_api_data)
|
580
609
|
) -> BaseAPIAuthData:
|
@@ -586,7 +615,7 @@ def base_api_auth(
|
|
586
615
|
require_correct_token=require_correct_token
|
587
616
|
)
|
588
617
|
|
589
|
-
# api_key
|
618
|
+
# parse api_key
|
590
619
|
|
591
620
|
api_auth_data.api_key_string = api_key_string
|
592
621
|
|
@@ -604,7 +633,7 @@ def base_api_auth(
|
|
604
633
|
if not api_auth_data.api_key_string and "apikey" in request.query_params.keys():
|
605
634
|
api_auth_data.api_key_string = request.query_params["apikey"]
|
606
635
|
|
607
|
-
# token
|
636
|
+
# parse token
|
608
637
|
|
609
638
|
api_auth_data.token_string = ac.credentials if ac and ac.credentials and ac.credentials.strip() else None
|
610
639
|
|
@@ -633,7 +662,7 @@ def base_api_auth(
|
|
633
662
|
if not api_auth_data.token_string:
|
634
663
|
api_auth_data.token_string = None
|
635
664
|
|
636
|
-
#
|
665
|
+
# require_api_key_string
|
637
666
|
|
638
667
|
if require_api_key_string and not api_auth_data.api_key_string:
|
639
668
|
raise APIException(
|
@@ -642,7 +671,7 @@ def base_api_auth(
|
|
642
671
|
error_data=safely_transfer_obj_to_json_str_to_json_obj(api_auth_data.model_dump())
|
643
672
|
)
|
644
673
|
|
645
|
-
#
|
674
|
+
# require_token_string
|
646
675
|
|
647
676
|
if require_token_string and not api_auth_data.token_string:
|
648
677
|
raise APIException(
|
@@ -651,10 +680,10 @@ def base_api_auth(
|
|
651
680
|
error_data=safely_transfer_obj_to_json_str_to_json_obj(api_auth_data.model_dump())
|
652
681
|
)
|
653
682
|
|
654
|
-
#
|
683
|
+
# validate_api_key_func
|
655
684
|
|
656
685
|
if validate_api_key_func is not None:
|
657
|
-
|
686
|
+
validate_api_key_func_res = validate_api_key_func(
|
658
687
|
api_key_string=api_auth_data.api_key_string,
|
659
688
|
token_string=api_auth_data.token_string,
|
660
689
|
base_api_auth_data=api_auth_data,
|
@@ -662,14 +691,14 @@ def base_api_auth(
|
|
662
691
|
request=request,
|
663
692
|
**kwargs
|
664
693
|
)
|
665
|
-
if is_async_object(
|
666
|
-
|
667
|
-
api_auth_data.is_api_key_correct =
|
694
|
+
if is_async_object(validate_api_key_func_res):
|
695
|
+
validate_api_key_func_res = await validate_api_key_func_res
|
696
|
+
api_auth_data.is_api_key_correct = validate_api_key_func_res
|
668
697
|
|
669
|
-
#
|
698
|
+
# validate_token_func
|
670
699
|
|
671
700
|
if validate_token_func is not None:
|
672
|
-
|
701
|
+
validate_token_func_res = validate_token_func(
|
673
702
|
api_key_string=api_auth_data.api_key_string,
|
674
703
|
token_string=api_auth_data.token_string,
|
675
704
|
base_api_auth_data=api_auth_data,
|
@@ -677,11 +706,11 @@ def base_api_auth(
|
|
677
706
|
request=request,
|
678
707
|
**kwargs
|
679
708
|
)
|
680
|
-
if is_async_object(
|
681
|
-
|
682
|
-
api_auth_data.is_token_correct =
|
709
|
+
if is_async_object(validate_token_func_res):
|
710
|
+
validate_token_func_res = await validate_token_func_res
|
711
|
+
api_auth_data.is_token_correct = validate_token_func_res
|
683
712
|
|
684
|
-
#
|
713
|
+
# require_correct_api_key
|
685
714
|
|
686
715
|
if require_correct_api_key:
|
687
716
|
if not api_auth_data.is_api_key_correct:
|
@@ -692,7 +721,7 @@ def base_api_auth(
|
|
692
721
|
error_data=safely_transfer_obj_to_json_str_to_json_obj(api_auth_data.model_dump()),
|
693
722
|
)
|
694
723
|
|
695
|
-
#
|
724
|
+
# require_correct_token
|
696
725
|
|
697
726
|
if require_correct_token:
|
698
727
|
if not api_auth_data.is_token_correct:
|
@@ -750,7 +779,6 @@ def create_fastapi_app(
|
|
750
779
|
*,
|
751
780
|
title: str = "arpakitlib FastAPI",
|
752
781
|
description: str | None = "arpakitlib FastAPI",
|
753
|
-
log_filepath: str | None = "./story.log",
|
754
782
|
handle_exception_: Callable | None = None,
|
755
783
|
startup_api_events: list[BaseStartupAPIEvent | None] | None = None,
|
756
784
|
shutdown_api_events: list[BaseShutdownAPIEvent | None] | None = None,
|
@@ -760,12 +788,14 @@ def create_fastapi_app(
|
|
760
788
|
media_dirpath: str | None = None,
|
761
789
|
static_dirpath: str | None = None
|
762
790
|
):
|
763
|
-
_logger.info("start
|
764
|
-
|
765
|
-
setup_normal_logging(log_filepath=log_filepath)
|
791
|
+
_logger.info("start")
|
766
792
|
|
767
793
|
if handle_exception_ is None:
|
768
|
-
handle_exception_ = create_handle_exception(
|
794
|
+
handle_exception_ = create_handle_exception(
|
795
|
+
funcs_before=[
|
796
|
+
logging__api_func_before_in_handle_exception()
|
797
|
+
]
|
798
|
+
)
|
769
799
|
|
770
800
|
if not startup_api_events:
|
771
801
|
startup_api_events = [BaseStartupAPIEvent()]
|
@@ -807,11 +837,14 @@ def create_fastapi_app(
|
|
807
837
|
handle_exception=handle_exception_
|
808
838
|
)
|
809
839
|
|
810
|
-
|
840
|
+
app.include_router(
|
841
|
+
router=create_needed_api_router(),
|
842
|
+
prefix=""
|
843
|
+
)
|
811
844
|
|
812
845
|
app.include_router(router=main_api_router)
|
813
846
|
|
814
|
-
_logger.info("finish
|
847
|
+
_logger.info("finish")
|
815
848
|
|
816
849
|
return app
|
817
850
|
|
@@ -19,7 +19,7 @@ from arpakitlib.ar_datetime_util import now_utc_dt
|
|
19
19
|
from arpakitlib.ar_dict_util import combine_dicts
|
20
20
|
from arpakitlib.ar_sleep_util import sync_safe_sleep, async_safe_sleep
|
21
21
|
from arpakitlib.ar_sqlalchemy_model_util import OperationDBM, StoryLogDBM, BaseOperationTypes
|
22
|
-
from arpakitlib.ar_sqlalchemy_util import
|
22
|
+
from arpakitlib.ar_sqlalchemy_util import SQLAlchemyDb
|
23
23
|
from arpakitlib.ar_type_util import raise_for_type
|
24
24
|
|
25
25
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
@@ -30,7 +30,7 @@ _logger = logging.getLogger(__name__)
|
|
30
30
|
def get_operation_for_execution(
|
31
31
|
*,
|
32
32
|
session: Session | None = None,
|
33
|
-
sqlalchemy_db:
|
33
|
+
sqlalchemy_db: SQLAlchemyDb | None = None,
|
34
34
|
filter_operation_types: list[str] | str | None = None,
|
35
35
|
lock: bool = False
|
36
36
|
) -> OperationDBM | None:
|
@@ -65,7 +65,7 @@ def get_operation_for_execution(
|
|
65
65
|
def get_operation_by_id(
|
66
66
|
*,
|
67
67
|
session: Session | None = None,
|
68
|
-
sqlalchemy_db:
|
68
|
+
sqlalchemy_db: SQLAlchemyDb | None = None,
|
69
69
|
filter_operation_id: int,
|
70
70
|
raise_if_not_found: bool = False,
|
71
71
|
lock: bool = False
|
@@ -101,7 +101,7 @@ def get_operation_by_id(
|
|
101
101
|
def remove_operations(
|
102
102
|
*,
|
103
103
|
session: Session | None = None,
|
104
|
-
sqlalchemy_db:
|
104
|
+
sqlalchemy_db: SQLAlchemyDb | None = None,
|
105
105
|
filter_operation_ids: list[int] | int | None = None,
|
106
106
|
filter_operation_types: list[str] | str | None = None,
|
107
107
|
filter_operation_statuses: list[str] | str | None = None
|
@@ -141,7 +141,7 @@ def remove_operations(
|
|
141
141
|
|
142
142
|
|
143
143
|
class BaseOperationExecutor:
|
144
|
-
def __init__(self, *, sqlalchemy_db:
|
144
|
+
def __init__(self, *, sqlalchemy_db: SQLAlchemyDb, **kwargs):
|
145
145
|
self._logger = logging.getLogger(self.__class__.__name__)
|
146
146
|
self.sql_alchemy_db = sqlalchemy_db
|
147
147
|
|
@@ -311,7 +311,7 @@ class OperationExecutorWorker(BaseWorker):
|
|
311
311
|
def __init__(
|
312
312
|
self,
|
313
313
|
*,
|
314
|
-
sqlalchemy_db:
|
314
|
+
sqlalchemy_db: SQLAlchemyDb,
|
315
315
|
operation_executor: BaseOperationExecutor | None = None,
|
316
316
|
filter_operation_types: str | list[str] | None = None,
|
317
317
|
startup_funcs: list[Any] | None = None,
|
@@ -384,7 +384,7 @@ class ScheduledOperationCreatorWorker(BaseWorker):
|
|
384
384
|
def __init__(
|
385
385
|
self,
|
386
386
|
*,
|
387
|
-
sqlalchemy_db:
|
387
|
+
sqlalchemy_db: SQLAlchemyDb,
|
388
388
|
scheduled_operations: ScheduledOperation | list[ScheduledOperation] | None = None,
|
389
389
|
startup_funcs: list[Any] | None = None
|
390
390
|
):
|
@@ -43,6 +43,30 @@ class ScheduleUUSTAPIClient:
|
|
43
43
|
)
|
44
44
|
}
|
45
45
|
|
46
|
+
async def _async_make_http_request(
|
47
|
+
self,
|
48
|
+
*,
|
49
|
+
method: str = "GET",
|
50
|
+
url: str,
|
51
|
+
params: dict[str, Any] | None = None,
|
52
|
+
**kwargs
|
53
|
+
) -> ClientResponse:
|
54
|
+
response = await async_make_http_request(
|
55
|
+
method=method,
|
56
|
+
url=url,
|
57
|
+
headers=self.headers,
|
58
|
+
params=combine_dicts(params, self.auth_params()),
|
59
|
+
max_tries_=9,
|
60
|
+
proxy_url_=self.api_proxy_url,
|
61
|
+
raise_for_status_=True,
|
62
|
+
timeout_=timedelta(seconds=15),
|
63
|
+
**kwargs
|
64
|
+
)
|
65
|
+
json_data = await response.json()
|
66
|
+
if "error" in json_data.keys():
|
67
|
+
raise Exception(f"error in json_data, {json_data}")
|
68
|
+
return response
|
69
|
+
|
46
70
|
def auth_params(self) -> dict[str, Any]:
|
47
71
|
if self.api_password:
|
48
72
|
return {
|
@@ -72,30 +96,6 @@ class ScheduleUUSTAPIClient:
|
|
72
96
|
def generate_v2_token(self) -> str:
|
73
97
|
return self.generate_new_v2_token(password_first_part=self.api_password_first_part)
|
74
98
|
|
75
|
-
async def _async_make_http_request(
|
76
|
-
self,
|
77
|
-
*,
|
78
|
-
method: str = "GET",
|
79
|
-
url: str,
|
80
|
-
params: dict[str, Any] | None = None,
|
81
|
-
**kwargs
|
82
|
-
) -> ClientResponse:
|
83
|
-
response = await async_make_http_request(
|
84
|
-
method=method,
|
85
|
-
url=url,
|
86
|
-
headers=self.headers,
|
87
|
-
params=combine_dicts(params, self.auth_params()),
|
88
|
-
max_tries_=9,
|
89
|
-
proxy_url_=self.api_proxy_url,
|
90
|
-
raise_for_status_=True,
|
91
|
-
timeout_=timedelta(seconds=15),
|
92
|
-
**kwargs
|
93
|
-
)
|
94
|
-
json_data = await response.json()
|
95
|
-
if "error" in json_data.keys():
|
96
|
-
raise Exception(f"error in json_data, {json_data}")
|
97
|
-
return response
|
98
|
-
|
99
99
|
async def get_current_week(self) -> int:
|
100
100
|
"""
|
101
101
|
response.json example
|