arpakitlib 1.7.103__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 +2 -2
- 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/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/create_api_app.py +12 -52
- arpakitlib/_arpakit_project_template/src/api/event.py +51 -2
- 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/{manage/settings_check.py → src/core/check_settings.py} +2 -0
- arpakitlib/_arpakit_project_template/src/core/generate_settings_env_example.py +16 -0
- arpakitlib/_arpakit_project_template/src/core/settings.py +4 -0
- arpakitlib/_arpakit_project_template/{manage/sqlalchemy_db_init.py → src/db/init_sqlalchemy_db.py} +2 -2
- arpakitlib/_arpakit_project_template/{manage/sqlalchemy_db_reinit.py → src/db/reinit_sqlalchemy_db.py} +4 -2
- 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} +5 -4
- arpakitlib/_arpakit_project_template/src/operation_execution/{start_scheduled_operation_creator_worker_for_dev.py → start_scheduled_operation_creator_worker.py} +6 -4
- arpakitlib/_arpakit_project_template/src/operation_execution/util.py +0 -21
- 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/ar_arpakit_lib_module_util.py +7 -0
- arpakitlib/ar_fastapi_util.py +0 -42
- arpakitlib/ar_settings_util.py +14 -5
- arpakitlib/ar_str_util.py +15 -15
- arpakitlib/ar_type_util.py +1 -1
- {arpakitlib-1.7.103.dist-info → arpakitlib-1.7.124.dist-info}/METADATA +27 -20
- {arpakitlib-1.7.103.dist-info → arpakitlib-1.7.124.dist-info}/RECORD +48 -44
- {arpakitlib-1.7.103.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_generate_env_example.py +0 -13
- /arpakitlib/_arpakit_project_template/{manage/sqlalchemy_db_check_conn.py → src/db/check_conn_sqlalchemy_db.py} +0 -0
- {arpakitlib-1.7.103.dist-info → arpakitlib-1.7.124.dist-info}/LICENSE +0 -0
- {arpakitlib-1.7.103.dist-info → arpakitlib-1.7.124.dist-info}/NOTICE +0 -0
- {arpakitlib-1.7.103.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
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
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())
|
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,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,11 +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 get_cached_media_file_storage_in_dir, \
|
16
|
-
|
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
|
17
14
|
from src.db.util import get_cached_sqlalchemy_db
|
18
|
-
from src.operation_execution.operation_executor import OperationExecutor
|
19
|
-
from src.operation_execution.scheduled_operations import ALL_SCHEDULED_OPERATIONS
|
20
15
|
|
21
16
|
|
22
17
|
def create_api_app() -> FastAPI:
|
@@ -28,7 +23,10 @@ def create_api_app() -> FastAPI:
|
|
28
23
|
|
29
24
|
transmitted_api_data = TransmittedAPIData(
|
30
25
|
settings=settings,
|
31
|
-
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()
|
32
30
|
)
|
33
31
|
|
34
32
|
funcs_before_response = []
|
@@ -49,49 +47,8 @@ def create_api_app() -> FastAPI:
|
|
49
47
|
|
50
48
|
startup_api_events = []
|
51
49
|
|
52
|
-
startup_api_events.append(InitFileStoragesInDir(
|
53
|
-
file_storages_in_dir=[
|
54
|
-
get_cached_media_file_storage_in_dir() if settings.media_dirpath is not None else None,
|
55
|
-
get_cached_cache_file_storage_in_dir() if settings.cache_dirpath is not None else None,
|
56
|
-
get_cached_dump_file_storage_in_dir() if settings.dump_dirpath is not None else None
|
57
|
-
]
|
58
|
-
))
|
59
|
-
|
60
|
-
if settings.api_init_sql_db_at_start:
|
61
|
-
raise_for_type(sqlalchemy_db, SQLAlchemyDB)
|
62
|
-
startup_api_events.append(InitSqlalchemyDBStartupAPIEvent(sqlalchemy_db=sqlalchemy_db))
|
63
|
-
|
64
50
|
startup_api_events.append(StartupAPIEvent(transmitted_api_data=transmitted_api_data))
|
65
51
|
|
66
|
-
if settings.api_start_operation_executor_worker:
|
67
|
-
raise_for_type(sqlalchemy_db, SQLAlchemyDB)
|
68
|
-
startup_api_events.append(
|
69
|
-
SafeRunWorkerStartupAPIEvent(
|
70
|
-
workers=[
|
71
|
-
OperationExecutorWorker(
|
72
|
-
sqlalchemy_db=sqlalchemy_db,
|
73
|
-
operation_executor=OperationExecutor(sqlalchemy_db=sqlalchemy_db),
|
74
|
-
filter_operation_types=None
|
75
|
-
)
|
76
|
-
],
|
77
|
-
safe_run_in_background_mode=SafeRunInBackgroundModes.async_task
|
78
|
-
)
|
79
|
-
)
|
80
|
-
|
81
|
-
if settings.api_start_scheduled_operation_creator_worker:
|
82
|
-
raise_for_type(sqlalchemy_db, SQLAlchemyDB)
|
83
|
-
startup_api_events.append(
|
84
|
-
SafeRunWorkerStartupAPIEvent(
|
85
|
-
workers=[
|
86
|
-
ScheduledOperationCreatorWorker(
|
87
|
-
sqlalchemy_db=sqlalchemy_db,
|
88
|
-
scheduled_operations=ALL_SCHEDULED_OPERATIONS
|
89
|
-
)
|
90
|
-
],
|
91
|
-
safe_run_in_background_mode=SafeRunInBackgroundModes.async_task
|
92
|
-
)
|
93
|
-
)
|
94
|
-
|
95
52
|
shutdown_api_events = []
|
96
53
|
|
97
54
|
shutdown_api_events.append(ShutdownAPIEvent(transmitted_api_data=transmitted_api_data))
|
@@ -105,11 +62,14 @@ def create_api_app() -> FastAPI:
|
|
105
62
|
shutdown_api_events=shutdown_api_events,
|
106
63
|
transmitted_api_data=transmitted_api_data,
|
107
64
|
main_api_router=main_api_router,
|
108
|
-
contact=DEFAULT_CONTACT,
|
109
65
|
media_dirpath=settings.media_dirpath,
|
110
66
|
static_dirpath=STATIC_DIRPATH
|
111
67
|
)
|
112
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
|
+
|
113
73
|
return api_app
|
114
74
|
|
115
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,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()
|
arpakitlib/_arpakit_project_template/{manage/settings_check.py → src/core/check_settings.py}
RENAMED
@@ -1,8 +1,10 @@
|
|
1
1
|
from arpakitlib.ar_json_util import safely_transfer_obj_to_json_str
|
2
2
|
from src.core.settings import get_cached_settings
|
3
|
+
from src.core.util import setup_logging
|
3
4
|
|
4
5
|
|
5
6
|
def command():
|
7
|
+
setup_logging()
|
6
8
|
print(safely_transfer_obj_to_json_str(get_cached_settings().model_dump(mode="json")))
|
7
9
|
|
8
10
|
|
@@ -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()
|
@@ -37,6 +37,8 @@ class Settings(SimpleSettings):
|
|
37
37
|
|
38
38
|
api_correct_token: str | None = "1"
|
39
39
|
|
40
|
+
api_enable_admin1: bool = True
|
41
|
+
|
40
42
|
var_dirname: str | None = "var"
|
41
43
|
|
42
44
|
var_dirpath: str | None = os.path.join(BASE_DIRPATH, var_dirname)
|
@@ -63,6 +65,8 @@ class Settings(SimpleSettings):
|
|
63
65
|
def local_timezone_as_pytz(self) -> Any:
|
64
66
|
return pytz.timezone(self.local_timezone)
|
65
67
|
|
68
|
+
admin1_secret_key: str | None = "85a9583cb91c4de7a78d7eb1e5306a04418c9c43014c447ea8ec8dd5deb4cf71"
|
69
|
+
|
66
70
|
# ...
|
67
71
|
|
68
72
|
|
arpakitlib/_arpakit_project_template/{manage/sqlalchemy_db_init.py → src/db/init_sqlalchemy_db.py}
RENAMED
@@ -2,10 +2,10 @@ from src.core.util import setup_logging
|
|
2
2
|
from src.db.util import get_cached_sqlalchemy_db
|
3
3
|
|
4
4
|
|
5
|
-
def
|
5
|
+
def __init_sqlalchemy_db():
|
6
6
|
setup_logging()
|
7
7
|
get_cached_sqlalchemy_db().init()
|
8
8
|
|
9
9
|
|
10
10
|
if __name__ == '__main__':
|
11
|
-
|
11
|
+
__init_sqlalchemy_db()
|
@@ -1,11 +1,13 @@
|
|
1
|
+
from src.core.settings import get_cached_settings
|
1
2
|
from src.core.util import setup_logging
|
2
3
|
from src.db.util import get_cached_sqlalchemy_db
|
3
4
|
|
4
5
|
|
5
|
-
def
|
6
|
+
def __reinit_sqlalchemy_db():
|
6
7
|
setup_logging()
|
8
|
+
get_cached_settings().raise_if_mode_type_not_prod()
|
7
9
|
get_cached_sqlalchemy_db().reinit()
|
8
10
|
|
9
11
|
|
10
12
|
if __name__ == '__main__':
|
11
|
-
|
13
|
+
__reinit_sqlalchemy_db()
|
@@ -1,14 +1,16 @@
|
|
1
|
+
from sqlalchemy.orm import Session
|
2
|
+
|
1
3
|
from arpakitlib.ar_operation_execution_util import BaseOperationExecutor
|
2
4
|
from arpakitlib.ar_sqlalchemy_model_util import OperationDBM
|
3
5
|
|
4
6
|
|
5
7
|
class OperationExecutor(BaseOperationExecutor):
|
6
|
-
def sync_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
|
8
|
+
def sync_execute_operation(self, operation_dbm: OperationDBM, session: Session) -> OperationDBM:
|
7
9
|
# ...
|
8
|
-
operation_dbm = super().sync_execute_operation(operation_dbm=operation_dbm)
|
10
|
+
operation_dbm = super().sync_execute_operation(operation_dbm=operation_dbm, session=session)
|
9
11
|
return operation_dbm
|
10
12
|
|
11
|
-
async def async_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
|
13
|
+
async def async_execute_operation(self, operation_dbm: OperationDBM, session: Session) -> OperationDBM:
|
12
14
|
# ...
|
13
|
-
operation_dbm = await super().async_execute_operation(operation_dbm=operation_dbm)
|
15
|
+
operation_dbm = await super().async_execute_operation(operation_dbm=operation_dbm, session=session)
|
14
16
|
return operation_dbm
|
@@ -4,14 +4,14 @@ from arpakitlib.ar_operation_execution_util import ScheduledOperation, every_tim
|
|
4
4
|
between_different_times_is_time_func
|
5
5
|
from arpakitlib.ar_sqlalchemy_model_util import BaseOperationTypes
|
6
6
|
|
7
|
-
|
7
|
+
SCHEDULED_OPERATIONS = []
|
8
8
|
|
9
9
|
healthcheck_1_scheduled_operation = ScheduledOperation(
|
10
10
|
type=BaseOperationTypes.healthcheck_,
|
11
11
|
input_data={"healthcheck_1": "healthcheck_1"},
|
12
12
|
is_time_func=every_timedelta_is_time_func(td=timedelta(seconds=15))
|
13
13
|
)
|
14
|
-
|
14
|
+
SCHEDULED_OPERATIONS.append(healthcheck_1_scheduled_operation)
|
15
15
|
|
16
16
|
healthcheck_2_scheduled_operation = ScheduledOperation(
|
17
17
|
type=BaseOperationTypes.healthcheck_,
|
@@ -22,4 +22,4 @@ healthcheck_2_scheduled_operation = ScheduledOperation(
|
|
22
22
|
),
|
23
23
|
timeout_after_creation=timedelta(seconds=60)
|
24
24
|
)
|
25
|
-
|
25
|
+
SCHEDULED_OPERATIONS.append(healthcheck_2_scheduled_operation)
|