arpakitlib 1.7.66__py3-none-any.whl → 1.7.124__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/example.env +4 -0
- arpakitlib/_arpakit_project_template/manage/hello_world.py +2 -2
- arpakitlib/_arpakit_project_template/manage/json_beutify.py +4 -4
- arpakitlib/_arpakit_project_template/manage/poetry_config.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/poetry_self_add_plugin_export.sh +2 -0
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_1.py +4 -4
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_2.py +4 -4
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_3.py +4 -4
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_4.py +4 -4
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_5.py +4 -4
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_6.py +4 -4
- arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_7.py +4 -4
- arpakitlib/_arpakit_project_template/resource/static/healthcheck +1 -0
- arpakitlib/_arpakit_project_template/src/admin1/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/admin1/add_admin_in_app.py +25 -0
- arpakitlib/_arpakit_project_template/src/admin1/admin_auth.py +29 -0
- arpakitlib/_arpakit_project_template/src/admin1/model_view.py +19 -0
- arpakitlib/_arpakit_project_template/src/api/auth.py +1 -6
- arpakitlib/_arpakit_project_template/src/api/create_api_app.py +13 -52
- arpakitlib/_arpakit_project_template/src/api/event.py +51 -2
- arpakitlib/_arpakit_project_template/src/api/router/main_router.py +3 -0
- arpakitlib/_arpakit_project_template/src/api/router/v1/get_api_error_info.py +6 -4
- arpakitlib/_arpakit_project_template/src/api/start_api_for_dev_with_reload.py +12 -4
- arpakitlib/_arpakit_project_template/src/api/{start_api_for_dev.py → start_api_for_dev_without_reload.py} +3 -3
- arpakitlib/_arpakit_project_template/src/api/transmitted_api_data.py +4 -0
- arpakitlib/_arpakit_project_template/src/business_service/hello_world.py +12 -0
- arpakitlib/_arpakit_project_template/{manage/logging_check.py → src/core/check_logging.py} +3 -3
- arpakitlib/_arpakit_project_template/src/core/check_settings.py +12 -0
- arpakitlib/_arpakit_project_template/src/core/generate_settings_env_example.py +16 -0
- arpakitlib/_arpakit_project_template/src/core/settings.py +13 -5
- arpakitlib/_arpakit_project_template/src/core/util.py +0 -18
- arpakitlib/_arpakit_project_template/{manage/sqlalchemy_db_check_conn.py → src/db/check_conn_sqlalchemy_db.py} +2 -1
- arpakitlib/_arpakit_project_template/src/db/const.py +0 -0
- arpakitlib/_arpakit_project_template/src/db/init_sqlalchemy_db.py +11 -0
- arpakitlib/_arpakit_project_template/src/db/reinit_sqlalchemy_db.py +13 -0
- arpakitlib/_arpakit_project_template/src/db/util.py +21 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/operation_executor.py +6 -4
- arpakitlib/_arpakit_project_template/src/operation_execution/scheduled_operations.py +3 -3
- arpakitlib/_arpakit_project_template/src/operation_execution/{start_operation_executor_worker_for_dev.py → start_operation_executor_worker.py} +7 -5
- arpakitlib/_arpakit_project_template/src/operation_execution/start_scheduled_operation_creator_worker.py +19 -0
- arpakitlib/_arpakit_project_template/src/operation_execution/util.py +0 -0
- arpakitlib/_arpakit_project_template/src/tg_bot/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/tg_bot/router/__init__.py +0 -0
- arpakitlib/_arpakit_project_template/src/tg_bot/start_tg_bot.py +0 -0
- arpakitlib/api_key_util.py +12 -0
- arpakitlib/ar_additional_model_util.py +18 -1
- arpakitlib/ar_arpakit_lib_module_util.py +13 -1
- arpakitlib/ar_arpakit_schedule_uust_api_client_util.py +24 -3
- arpakitlib/ar_arpakitlib_cli_util.py +2 -0
- arpakitlib/ar_base_worker_util.py +67 -18
- arpakitlib/ar_exception_util.py +13 -0
- arpakitlib/ar_fastapi_util.py +129 -98
- arpakitlib/ar_file_util.py +2 -0
- arpakitlib/ar_func_util.py +55 -0
- arpakitlib/ar_json_util.py +11 -9
- arpakitlib/ar_need_type_util.py +8 -1
- arpakitlib/ar_openai_api_client_util.py +16 -2
- arpakitlib/ar_operation_execution_util.py +143 -141
- arpakitlib/ar_schedule_uust_api_client_util.py +13 -6
- arpakitlib/ar_settings_util.py +24 -5
- arpakitlib/ar_sqlalchemy_model_util.py +37 -7
- arpakitlib/ar_ssh_runner_util.py +2 -2
- arpakitlib/ar_str_util.py +30 -1
- arpakitlib/ar_type_util.py +52 -7
- {arpakitlib-1.7.66.dist-info → arpakitlib-1.7.124.dist-info}/METADATA +27 -20
- {arpakitlib-1.7.66.dist-info → arpakitlib-1.7.124.dist-info}/RECORD +70 -62
- {arpakitlib-1.7.66.dist-info → arpakitlib-1.7.124.dist-info}/WHEEL +1 -1
- arpakitlib/_arpakit_project_template/AUTHOR.md +0 -4
- arpakitlib/_arpakit_project_template/manage/example_nginx_proxy.nginx +0 -14
- arpakitlib/_arpakit_project_template/manage/example_poetry_arpakitlib.sh +0 -1
- arpakitlib/_arpakit_project_template/manage/example_pyproject.toml +0 -18
- arpakitlib/_arpakit_project_template/manage/example_systemd.service +0 -12
- arpakitlib/_arpakit_project_template/manage/requirements.txt +0 -209
- arpakitlib/_arpakit_project_template/manage/settings_check.py +0 -10
- arpakitlib/_arpakit_project_template/manage/settings_generate_env_example.py +0 -13
- arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_init.py +0 -10
- arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_reinit.py +0 -10
- arpakitlib/_arpakit_project_template/src/operation_execution/start_scheduled_operation_creator_worker_for_dev.py +0 -16
- {arpakitlib-1.7.66.dist-info → arpakitlib-1.7.124.dist-info}/LICENSE +0 -0
- {arpakitlib-1.7.66.dist-info → arpakitlib-1.7.124.dist-info}/NOTICE +0 -0
- {arpakitlib-1.7.66.dist-info → arpakitlib-1.7.124.dist-info}/entry_points.txt +0 -0
@@ -1,4 +1,5 @@
|
|
1
1
|
# mode_type=
|
2
|
+
# project_name=
|
2
3
|
# sql_db_url=
|
3
4
|
# sql_db_echo=
|
4
5
|
# api_init_sql_db_at_start=
|
@@ -9,6 +10,8 @@
|
|
9
10
|
# api_start_scheduled_operation_creator_worker=
|
10
11
|
# api_port=
|
11
12
|
# api_correct_api_key=
|
13
|
+
# api_correct_token=
|
14
|
+
# api_enable_admin1=
|
12
15
|
# var_dirname=
|
13
16
|
# var_dirpath=
|
14
17
|
# log_filename=
|
@@ -20,3 +23,4 @@
|
|
20
23
|
# dump_dirname=
|
21
24
|
# dump_dirpath=
|
22
25
|
# local_timezone=
|
26
|
+
# admin1_secret_key=
|
@@ -1,10 +1,10 @@
|
|
1
|
-
from arpakitlib.ar_json_util import
|
1
|
+
from arpakitlib.ar_json_util import safely_transfer_str_to_json_obj_to_json_str
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def __command():
|
5
5
|
s = input("JSON:\n")
|
6
|
-
print(
|
6
|
+
print(safely_transfer_str_to_json_obj_to_json_str(s))
|
7
7
|
|
8
8
|
|
9
9
|
if __name__ == '__main__':
|
10
|
-
|
10
|
+
__command()
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def __sandbox():
|
5
5
|
pass
|
6
6
|
|
7
7
|
|
8
|
-
async def
|
8
|
+
async def __async_sandbox():
|
9
9
|
pass
|
10
10
|
|
11
11
|
|
12
12
|
if __name__ == '__main__':
|
13
|
-
|
14
|
-
asyncio.run(
|
13
|
+
__sandbox()
|
14
|
+
asyncio.run(__async_sandbox())
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def __sandbox():
|
5
5
|
pass
|
6
6
|
|
7
7
|
|
8
|
-
async def
|
8
|
+
async def __async_sandbox():
|
9
9
|
pass
|
10
10
|
|
11
11
|
|
12
12
|
if __name__ == '__main__':
|
13
|
-
|
14
|
-
asyncio.run(
|
13
|
+
__sandbox()
|
14
|
+
asyncio.run(__async_sandbox())
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def __sandbox():
|
5
5
|
pass
|
6
6
|
|
7
7
|
|
8
|
-
async def
|
8
|
+
async def __async_sandbox():
|
9
9
|
pass
|
10
10
|
|
11
11
|
|
12
12
|
if __name__ == '__main__':
|
13
|
-
|
14
|
-
asyncio.run(
|
13
|
+
__sandbox()
|
14
|
+
asyncio.run(__async_sandbox())
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def __sandbox():
|
5
5
|
pass
|
6
6
|
|
7
7
|
|
8
|
-
async def
|
8
|
+
async def __async_sandbox():
|
9
9
|
pass
|
10
10
|
|
11
11
|
|
12
12
|
if __name__ == '__main__':
|
13
|
-
|
14
|
-
asyncio.run(
|
13
|
+
__sandbox()
|
14
|
+
asyncio.run(__async_sandbox())
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def __sandbox():
|
5
5
|
pass
|
6
6
|
|
7
7
|
|
8
|
-
async def
|
8
|
+
async def __async_sandbox():
|
9
9
|
pass
|
10
10
|
|
11
11
|
|
12
12
|
if __name__ == '__main__':
|
13
|
-
|
14
|
-
asyncio.run(
|
13
|
+
__sandbox()
|
14
|
+
asyncio.run(__async_sandbox())
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def __sandbox():
|
5
5
|
pass
|
6
6
|
|
7
7
|
|
8
|
-
async def
|
8
|
+
async def __async_sandbox():
|
9
9
|
pass
|
10
10
|
|
11
11
|
|
12
12
|
if __name__ == '__main__':
|
13
|
-
|
14
|
-
asyncio.run(
|
13
|
+
__sandbox()
|
14
|
+
asyncio.run(__async_sandbox())
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def __sandbox():
|
5
5
|
pass
|
6
6
|
|
7
7
|
|
8
|
-
async def
|
8
|
+
async def __async_sandbox():
|
9
9
|
pass
|
10
10
|
|
11
11
|
|
12
12
|
if __name__ == '__main__':
|
13
|
-
|
14
|
-
asyncio.run(
|
13
|
+
__sandbox()
|
14
|
+
asyncio.run(__async_sandbox())
|
@@ -0,0 +1 @@
|
|
1
|
+
Healthcheck
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
from fastapi import FastAPI
|
2
|
+
from sqladmin import Admin
|
3
|
+
|
4
|
+
from src.admin1.admin_auth import AdminAuth
|
5
|
+
from src.admin1.model_view import MODEL_VIEWS
|
6
|
+
from src.api.transmitted_api_data import TransmittedAPIData
|
7
|
+
|
8
|
+
|
9
|
+
def add_admin1_in_app(*, app: FastAPI) -> FastAPI:
|
10
|
+
transmitted_api_data: TransmittedAPIData = app.state.transmitted_api_data
|
11
|
+
|
12
|
+
authentication_backend = AdminAuth()
|
13
|
+
|
14
|
+
admin = Admin(
|
15
|
+
app=app,
|
16
|
+
engine=transmitted_api_data.sqlalchemy_db.engine,
|
17
|
+
base_url="/admin1",
|
18
|
+
authentication_backend=authentication_backend,
|
19
|
+
title="{PROJECT_NAME}"
|
20
|
+
)
|
21
|
+
|
22
|
+
for model_view in MODEL_VIEWS:
|
23
|
+
admin.add_model_view(model_view)
|
24
|
+
|
25
|
+
return app
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import logging
|
2
|
+
|
3
|
+
from sqladmin.authentication import AuthenticationBackend
|
4
|
+
from starlette.requests import Request
|
5
|
+
|
6
|
+
from src.core.settings import get_cached_settings
|
7
|
+
|
8
|
+
|
9
|
+
class AdminAuth(AuthenticationBackend):
|
10
|
+
def __init__(self):
|
11
|
+
self._logger = logging.getLogger(self.__class__.__name__)
|
12
|
+
super().__init__(secret_key=get_cached_settings().admin1_secret_key)
|
13
|
+
|
14
|
+
async def login(self, request: Request) -> bool:
|
15
|
+
# ...
|
16
|
+
# form = await request.form()
|
17
|
+
# request.session.update(...)
|
18
|
+
# ...
|
19
|
+
return True
|
20
|
+
|
21
|
+
async def logout(self, request: Request) -> bool:
|
22
|
+
request.session.clear()
|
23
|
+
return True
|
24
|
+
|
25
|
+
async def authenticate(self, request: Request) -> bool:
|
26
|
+
# ...
|
27
|
+
# request.session.get("...")
|
28
|
+
# ...
|
29
|
+
return True
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from sqladmin import ModelView
|
2
|
+
|
3
|
+
|
4
|
+
class BaseModelView(ModelView):
|
5
|
+
can_create = True
|
6
|
+
can_edit = True
|
7
|
+
can_delete = True
|
8
|
+
can_view_details = True
|
9
|
+
can_export = True
|
10
|
+
page_size = 50
|
11
|
+
page_size_options = [25, 50, 100, 200]
|
12
|
+
save_as = True
|
13
|
+
save_as_continue = True
|
14
|
+
export_types = ["xlsx", "csv", "json"]
|
15
|
+
|
16
|
+
|
17
|
+
MODEL_VIEWS = []
|
18
|
+
|
19
|
+
# ...
|
@@ -1,6 +1 @@
|
|
1
|
-
|
2
|
-
from src.core.settings import get_cached_settings
|
3
|
-
|
4
|
-
check_with_settings_is_api_key_correct_api_auth = is_api_key_correct_api_auth(
|
5
|
-
correct_api_key=get_cached_settings().api_correct_api_key
|
6
|
-
)
|
1
|
+
# ...
|
@@ -1,10 +1,7 @@
|
|
1
1
|
from fastapi import FastAPI
|
2
2
|
|
3
|
-
from arpakitlib.
|
4
|
-
|
5
|
-
create_handle_exception, create_story_log_before_response_in_handle_exception, DEFAULT_CONTACT, \
|
6
|
-
SafeRunWorkerStartupAPIEvent
|
7
|
-
from arpakitlib.ar_operation_execution_util import OperationExecutorWorker, ScheduledOperationCreatorWorker
|
3
|
+
from arpakitlib.ar_fastapi_util import create_fastapi_app, \
|
4
|
+
create_handle_exception, create_story_log_before_response_in_handle_exception
|
8
5
|
from arpakitlib.ar_sqlalchemy_util import SQLAlchemyDB
|
9
6
|
from arpakitlib.ar_type_util import raise_for_type
|
10
7
|
from src.api.event import StartupAPIEvent, ShutdownAPIEvent
|
@@ -12,10 +9,9 @@ from src.api.router.main_router import main_api_router
|
|
12
9
|
from src.api.transmitted_api_data import TransmittedAPIData
|
13
10
|
from src.core.const import STATIC_DIRPATH
|
14
11
|
from src.core.settings import get_cached_settings
|
15
|
-
from src.core.util import
|
16
|
-
|
17
|
-
from src.
|
18
|
-
from src.operation_execution.scheduled_operations import ALL_SCHEDULED_OPERATIONS
|
12
|
+
from src.core.util import setup_logging, get_cached_media_file_storage_in_dir, get_cached_cache_file_storage_in_dir, \
|
13
|
+
get_cached_dump_file_storage_in_dir
|
14
|
+
from src.db.util import get_cached_sqlalchemy_db
|
19
15
|
|
20
16
|
|
21
17
|
def create_api_app() -> FastAPI:
|
@@ -27,7 +23,10 @@ def create_api_app() -> FastAPI:
|
|
27
23
|
|
28
24
|
transmitted_api_data = TransmittedAPIData(
|
29
25
|
settings=settings,
|
30
|
-
sqlalchemy_db=sqlalchemy_db
|
26
|
+
sqlalchemy_db=sqlalchemy_db,
|
27
|
+
media_file_storage_in_dir=get_cached_media_file_storage_in_dir(),
|
28
|
+
cache_file_storage_in_dir=get_cached_cache_file_storage_in_dir(),
|
29
|
+
dump_file_storage_in_dir=get_cached_dump_file_storage_in_dir()
|
31
30
|
)
|
32
31
|
|
33
32
|
funcs_before_response = []
|
@@ -48,49 +47,8 @@ def create_api_app() -> FastAPI:
|
|
48
47
|
|
49
48
|
startup_api_events = []
|
50
49
|
|
51
|
-
startup_api_events.append(InitFileStoragesInDir(
|
52
|
-
file_storages_in_dir=[
|
53
|
-
get_cached_media_file_storage_in_dir() if settings.media_dirpath is not None else None,
|
54
|
-
get_cached_cache_file_storage_in_dir() if settings.cache_dirpath is not None else None,
|
55
|
-
get_cached_dump_file_storage_in_dir() if settings.dump_dirpath is not None else None
|
56
|
-
]
|
57
|
-
))
|
58
|
-
|
59
|
-
if settings.api_init_sql_db_at_start:
|
60
|
-
raise_for_type(sqlalchemy_db, SQLAlchemyDB)
|
61
|
-
startup_api_events.append(InitSqlalchemyDBStartupAPIEvent(sqlalchemy_db=sqlalchemy_db))
|
62
|
-
|
63
50
|
startup_api_events.append(StartupAPIEvent(transmitted_api_data=transmitted_api_data))
|
64
51
|
|
65
|
-
if settings.api_start_operation_executor_worker:
|
66
|
-
raise_for_type(sqlalchemy_db, SQLAlchemyDB)
|
67
|
-
startup_api_events.append(
|
68
|
-
SafeRunWorkerStartupAPIEvent(
|
69
|
-
workers=[
|
70
|
-
OperationExecutorWorker(
|
71
|
-
sqlalchemy_db=sqlalchemy_db,
|
72
|
-
operation_executor=OperationExecutor(sqlalchemy_db=sqlalchemy_db),
|
73
|
-
filter_operation_types=None
|
74
|
-
)
|
75
|
-
],
|
76
|
-
safe_run_in_background_mode=SafeRunInBackgroundModes.async_task
|
77
|
-
)
|
78
|
-
)
|
79
|
-
|
80
|
-
if settings.api_start_scheduled_operation_creator_worker:
|
81
|
-
raise_for_type(sqlalchemy_db, SQLAlchemyDB)
|
82
|
-
startup_api_events.append(
|
83
|
-
SafeRunWorkerStartupAPIEvent(
|
84
|
-
workers=[
|
85
|
-
ScheduledOperationCreatorWorker(
|
86
|
-
sqlalchemy_db=sqlalchemy_db,
|
87
|
-
scheduled_operations=ALL_SCHEDULED_OPERATIONS
|
88
|
-
)
|
89
|
-
],
|
90
|
-
safe_run_in_background_mode=SafeRunInBackgroundModes.async_task
|
91
|
-
)
|
92
|
-
)
|
93
|
-
|
94
52
|
shutdown_api_events = []
|
95
53
|
|
96
54
|
shutdown_api_events.append(ShutdownAPIEvent(transmitted_api_data=transmitted_api_data))
|
@@ -104,11 +62,14 @@ def create_api_app() -> FastAPI:
|
|
104
62
|
shutdown_api_events=shutdown_api_events,
|
105
63
|
transmitted_api_data=transmitted_api_data,
|
106
64
|
main_api_router=main_api_router,
|
107
|
-
contact=DEFAULT_CONTACT,
|
108
65
|
media_dirpath=settings.media_dirpath,
|
109
66
|
static_dirpath=STATIC_DIRPATH
|
110
67
|
)
|
111
68
|
|
69
|
+
if settings.api_enable_admin1:
|
70
|
+
from src.admin1.add_admin_in_app import add_admin1_in_app
|
71
|
+
add_admin1_in_app(app=api_app)
|
72
|
+
|
112
73
|
return api_app
|
113
74
|
|
114
75
|
|
@@ -1,5 +1,11 @@
|
|
1
|
+
from arpakitlib.ar_base_worker_util import safe_run_worker_in_background, SafeRunInBackgroundModes
|
1
2
|
from arpakitlib.ar_fastapi_util import BaseStartupAPIEvent, BaseShutdownAPIEvent
|
3
|
+
from arpakitlib.ar_operation_execution_util import OperationExecutorWorker, ScheduledOperationCreatorWorker
|
4
|
+
from arpakitlib.ar_sqlalchemy_util import SQLAlchemyDB
|
5
|
+
from arpakitlib.ar_type_util import raise_for_type
|
2
6
|
from src.api.transmitted_api_data import TransmittedAPIData
|
7
|
+
from src.operation_execution.operation_executor import OperationExecutor
|
8
|
+
from src.operation_execution.scheduled_operations import SCHEDULED_OPERATIONS
|
3
9
|
|
4
10
|
|
5
11
|
class StartupAPIEvent(BaseStartupAPIEvent):
|
@@ -8,7 +14,49 @@ class StartupAPIEvent(BaseStartupAPIEvent):
|
|
8
14
|
self.transmitted_api_data = transmitted_api_data
|
9
15
|
|
10
16
|
async def async_on_startup(self, *args, **kwargs):
|
11
|
-
self._logger.info(
|
17
|
+
self._logger.info("start")
|
18
|
+
|
19
|
+
if self.transmitted_api_data.media_file_storage_in_dir is not None:
|
20
|
+
self.transmitted_api_data.media_file_storage_in_dir.init()
|
21
|
+
|
22
|
+
if self.transmitted_api_data.cache_file_storage_in_dir is not None:
|
23
|
+
self.transmitted_api_data.cache_file_storage_in_dir.init()
|
24
|
+
|
25
|
+
if self.transmitted_api_data.dump_file_storage_in_dir is not None:
|
26
|
+
self.transmitted_api_data.dump_file_storage_in_dir.init()
|
27
|
+
|
28
|
+
if self.transmitted_api_data.settings.api_init_sql_db_at_start:
|
29
|
+
raise_for_type(self.transmitted_api_data.sqlalchemy_db, SQLAlchemyDB)
|
30
|
+
self.transmitted_api_data.sqlalchemy_db.init()
|
31
|
+
|
32
|
+
if self.transmitted_api_data.settings.api_start_operation_executor_worker:
|
33
|
+
raise_for_type(self.transmitted_api_data.sqlalchemy_db, SQLAlchemyDB)
|
34
|
+
_ = safe_run_worker_in_background(
|
35
|
+
worker=OperationExecutorWorker(
|
36
|
+
sqlalchemy_db=self.transmitted_api_data.sqlalchemy_db,
|
37
|
+
operation_executor=OperationExecutor(sqlalchemy_db=self.transmitted_api_data.sqlalchemy_db),
|
38
|
+
filter_operation_types=None,
|
39
|
+
startup_funcs=[
|
40
|
+
self.transmitted_api_data.sqlalchemy_db.init
|
41
|
+
]
|
42
|
+
),
|
43
|
+
mode=SafeRunInBackgroundModes.thread
|
44
|
+
)
|
45
|
+
|
46
|
+
if self.transmitted_api_data.settings.api_start_scheduled_operation_creator_worker:
|
47
|
+
raise_for_type(self.transmitted_api_data.sqlalchemy_db, SQLAlchemyDB)
|
48
|
+
_ = safe_run_worker_in_background(
|
49
|
+
worker=ScheduledOperationCreatorWorker(
|
50
|
+
sqlalchemy_db=self.transmitted_api_data.sqlalchemy_db,
|
51
|
+
scheduled_operations=SCHEDULED_OPERATIONS,
|
52
|
+
startup_funcs=[
|
53
|
+
self.transmitted_api_data.sqlalchemy_db.init
|
54
|
+
]
|
55
|
+
),
|
56
|
+
mode=SafeRunInBackgroundModes.async_task
|
57
|
+
)
|
58
|
+
|
59
|
+
self._logger.info("finish")
|
12
60
|
|
13
61
|
|
14
62
|
class ShutdownAPIEvent(BaseShutdownAPIEvent):
|
@@ -17,4 +65,5 @@ class ShutdownAPIEvent(BaseShutdownAPIEvent):
|
|
17
65
|
self.transmitted_api_data = transmitted_api_data
|
18
66
|
|
19
67
|
async def async_on_shutdown(self, *args, **kwargs):
|
20
|
-
self._logger.info(
|
68
|
+
self._logger.info("start")
|
69
|
+
self._logger.info("finish")
|
@@ -1,23 +1,25 @@
|
|
1
1
|
import fastapi.requests
|
2
|
-
from fastapi import APIRouter
|
2
|
+
from fastapi import APIRouter, Depends
|
3
3
|
from starlette import status
|
4
4
|
|
5
|
-
from arpakitlib.ar_fastapi_util import ErrorSO
|
5
|
+
from arpakitlib.ar_fastapi_util import ErrorSO, get_transmitted_api_data
|
6
6
|
from src.api.const import APIErrorCodes, APIErrorSpecificationCodes
|
7
7
|
from src.api.schema.v1.out import APIErrorInfoSO
|
8
|
+
from src.api.transmitted_api_data import TransmittedAPIData
|
8
9
|
|
9
10
|
api_router = APIRouter()
|
10
11
|
|
11
12
|
|
12
13
|
@api_router.get(
|
13
|
-
"
|
14
|
+
"",
|
14
15
|
response_model=APIErrorInfoSO | ErrorSO,
|
15
16
|
status_code=status.HTTP_200_OK
|
16
17
|
)
|
17
18
|
async def _(
|
18
19
|
*,
|
19
20
|
request: fastapi.requests.Request,
|
20
|
-
response: fastapi.responses.Response
|
21
|
+
response: fastapi.responses.Response,
|
22
|
+
transmitted_api_data: TransmittedAPIData = Depends(get_transmitted_api_data)
|
21
23
|
):
|
22
24
|
return APIErrorInfoSO(
|
23
25
|
api_error_codes=APIErrorCodes.values_list(),
|
@@ -1,9 +1,17 @@
|
|
1
|
-
|
1
|
+
import uvicorn
|
2
2
|
|
3
|
+
from src.core.settings import get_cached_settings
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
|
6
|
+
def __command():
|
7
|
+
uvicorn.run(
|
8
|
+
"src.api.asgi:app",
|
9
|
+
port=get_cached_settings().api_port,
|
10
|
+
host="localhost",
|
11
|
+
workers=1,
|
12
|
+
reload=True
|
13
|
+
)
|
6
14
|
|
7
15
|
|
8
16
|
if __name__ == '__main__':
|
9
|
-
|
17
|
+
__command()
|
@@ -3,15 +3,15 @@ import uvicorn
|
|
3
3
|
from src.core.settings import get_cached_settings
|
4
4
|
|
5
5
|
|
6
|
-
def
|
6
|
+
def __command():
|
7
7
|
uvicorn.run(
|
8
8
|
"src.api.asgi:app",
|
9
9
|
port=get_cached_settings().api_port,
|
10
10
|
host="localhost",
|
11
11
|
workers=1,
|
12
|
-
reload=
|
12
|
+
reload=False
|
13
13
|
)
|
14
14
|
|
15
15
|
|
16
16
|
if __name__ == '__main__':
|
17
|
-
|
17
|
+
__command()
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from arpakitlib.ar_fastapi_util import BaseTransmittedAPIData
|
2
|
+
from arpakitlib.ar_file_storage_in_dir_util import FileStorageInDir
|
2
3
|
from arpakitlib.ar_sqlalchemy_util import SQLAlchemyDB
|
3
4
|
|
4
5
|
from src.core.settings import Settings
|
@@ -7,3 +8,6 @@ from src.core.settings import Settings
|
|
7
8
|
class TransmittedAPIData(BaseTransmittedAPIData):
|
8
9
|
settings: Settings
|
9
10
|
sqlalchemy_db: SQLAlchemyDB | None = None
|
11
|
+
media_file_storage_in_dir: FileStorageInDir | None = None
|
12
|
+
cache_file_storage_in_dir: FileStorageInDir | None = None
|
13
|
+
dump_file_storage_in_dir: FileStorageInDir | None = None
|
@@ -5,10 +5,10 @@ from src.core.util import setup_logging
|
|
5
5
|
_logger = logging.getLogger(__name__)
|
6
6
|
|
7
7
|
|
8
|
-
def
|
8
|
+
def __check_logging():
|
9
9
|
setup_logging()
|
10
|
-
_logger.info("
|
10
|
+
_logger.info("logging is good")
|
11
11
|
|
12
12
|
|
13
13
|
if __name__ == '__main__':
|
14
|
-
|
14
|
+
__check_logging()
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from arpakitlib.ar_json_util import safely_transfer_obj_to_json_str
|
2
|
+
from src.core.settings import get_cached_settings
|
3
|
+
from src.core.util import setup_logging
|
4
|
+
|
5
|
+
|
6
|
+
def command():
|
7
|
+
setup_logging()
|
8
|
+
print(safely_transfer_obj_to_json_str(get_cached_settings().model_dump(mode="json")))
|
9
|
+
|
10
|
+
|
11
|
+
if __name__ == '__main__':
|
12
|
+
command()
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import os.path
|
2
|
+
|
3
|
+
from arpakitlib.ar_json_util import safely_transfer_obj_to_json_str
|
4
|
+
from src.core.const import BASE_DIRPATH
|
5
|
+
from src.core.settings import Settings, get_cached_settings
|
6
|
+
from src.core.util import setup_logging
|
7
|
+
|
8
|
+
|
9
|
+
def command():
|
10
|
+
setup_logging()
|
11
|
+
print(safely_transfer_obj_to_json_str(get_cached_settings().model_dump(mode="json")))
|
12
|
+
Settings.save_env_example_to_file(filepath=os.path.join(BASE_DIRPATH, "example.env"))
|
13
|
+
|
14
|
+
|
15
|
+
if __name__ == '__main__':
|
16
|
+
command()
|
@@ -5,15 +5,17 @@ from typing import Any
|
|
5
5
|
|
6
6
|
import pytz
|
7
7
|
|
8
|
-
from arpakitlib.ar_json_util import
|
8
|
+
from arpakitlib.ar_json_util import safely_transfer_obj_to_json_str
|
9
9
|
from arpakitlib.ar_settings_util import SimpleSettings
|
10
10
|
from src.core.const import BASE_DIRPATH, ENV_FILEPATH
|
11
11
|
|
12
12
|
|
13
13
|
class Settings(SimpleSettings):
|
14
|
+
project_name: str = "{PROJECT_NAME}"
|
15
|
+
|
14
16
|
sql_db_url: str | None = (
|
15
17
|
"postgresql://{PROJECT_NAME}:{PROJECT_NAME}@127.0.0.1:{SQL_DB_PORT}/{PROJECT_NAME}"
|
16
|
-
)
|
18
|
+
) if (str("{PROJECT_NAME}") and str("{SQL_DB_PORT}").strip().isdigit()) else None
|
17
19
|
|
18
20
|
sql_db_echo: bool = False
|
19
21
|
|
@@ -29,9 +31,13 @@ class Settings(SimpleSettings):
|
|
29
31
|
|
30
32
|
api_start_scheduled_operation_creator_worker: bool = False
|
31
33
|
|
32
|
-
api_port: int | None = int("{API_PORT}") if "{API_PORT}".isdigit() else None
|
34
|
+
api_port: int | None = int("{API_PORT}") if "{API_PORT}".strip().isdigit() else None
|
35
|
+
|
36
|
+
api_correct_api_key: str | None = "1"
|
33
37
|
|
34
|
-
|
38
|
+
api_correct_token: str | None = "1"
|
39
|
+
|
40
|
+
api_enable_admin1: bool = True
|
35
41
|
|
36
42
|
var_dirname: str | None = "var"
|
37
43
|
|
@@ -59,6 +65,8 @@ class Settings(SimpleSettings):
|
|
59
65
|
def local_timezone_as_pytz(self) -> Any:
|
60
66
|
return pytz.timezone(self.local_timezone)
|
61
67
|
|
68
|
+
admin1_secret_key: str | None = "85a9583cb91c4de7a78d7eb1e5306a04418c9c43014c447ea8ec8dd5deb4cf71"
|
69
|
+
|
62
70
|
# ...
|
63
71
|
|
64
72
|
|
@@ -70,7 +78,7 @@ def get_cached_settings() -> Settings:
|
|
70
78
|
|
71
79
|
|
72
80
|
def __example():
|
73
|
-
print(
|
81
|
+
print(safely_transfer_obj_to_json_str(get_cached_settings().model_dump(mode="json")))
|
74
82
|
|
75
83
|
|
76
84
|
async def __async_example():
|