arpakitlib 1.7.44__py3-none-any.whl → 1.7.45__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.
@@ -8,6 +8,7 @@
8
8
  # api_start_execute_operation_worker=
9
9
  # api_start_create_scheduled_operation_worker=
10
10
  # api_port=
11
+ # api_correct_api_key=
11
12
  # var_dirname=
12
13
  # var_dirpath=
13
14
  # log_filename=
@@ -5,10 +5,8 @@ from src.core.settings import Settings
5
5
 
6
6
 
7
7
  def command():
8
- env_example = Settings.generate_env_example()
9
- print(env_example)
10
- with open(os.path.join(BASE_DIRPATH, "example.env"), mode="w") as f:
11
- f.write(env_example)
8
+ print(Settings.generate_env_example())
9
+ Settings.save_env_example_to_file(filepath=os.path.join(BASE_DIRPATH, "example.env"))
12
10
 
13
11
 
14
12
  if __name__ == '__main__':
@@ -6,6 +6,4 @@ class OperationTypes(BaseOperationTypes):
6
6
 
7
7
 
8
8
  if __name__ == '__main__':
9
- print(f"OperationTypes (len={len(OperationTypes.values_list())})")
10
- for v in OperationTypes.values_list():
11
- print(f"- {v}")
9
+ OperationTypes.print()
@@ -1,13 +1,25 @@
1
- from datetime import timedelta
1
+ from datetime import timedelta, time
2
2
 
3
- from arpakitlib.ar_operation_execution_util import ScheduledOperation, every_timedelta_is_time_func
3
+ from arpakitlib.ar_operation_execution_util import ScheduledOperation, every_timedelta_is_time_func, \
4
+ between_different_times_is_time_func
4
5
  from arpakitlib.ar_sqlalchemy_model_util import BaseOperationTypes
5
6
 
6
7
  ALL_SCHEDULED_OPERATIONS = []
7
8
 
8
- healthcheck_scheduled_operation = ScheduledOperation(
9
+ healthcheck_1_scheduled_operation = ScheduledOperation(
9
10
  type=BaseOperationTypes.healthcheck_,
10
- input_data={},
11
- is_time_func=every_timedelta_is_time_func(td=timedelta(seconds=5))
11
+ input_data={"healthcheck_1": "healthcheck_1"},
12
+ is_time_func=every_timedelta_is_time_func(td=timedelta(seconds=15))
12
13
  )
13
- ALL_SCHEDULED_OPERATIONS.append(healthcheck_scheduled_operation)
14
+ ALL_SCHEDULED_OPERATIONS.append(healthcheck_1_scheduled_operation)
15
+
16
+ healthcheck_2_scheduled_operation = ScheduledOperation(
17
+ type=BaseOperationTypes.healthcheck_,
18
+ input_data={"healthcheck_2": "healthcheck_2"},
19
+ is_time_func=between_different_times_is_time_func(
20
+ from_time=time(hour=12, minute=0),
21
+ to_time=time(hour=12, minute=15)
22
+ ),
23
+ timeout_after_creation=timedelta(seconds=60)
24
+ )
25
+ ALL_SCHEDULED_OPERATIONS.append(healthcheck_2_scheduled_operation)
@@ -16,6 +16,7 @@ from sqlalchemy.orm import Session
16
16
  from arpakitlib.ar_base_worker_util import BaseWorker
17
17
  from arpakitlib.ar_datetime_util import now_utc_dt
18
18
  from arpakitlib.ar_dict_util import combine_dicts
19
+ from arpakitlib.ar_sleep_util import sync_safe_sleep, async_safe_sleep
19
20
  from arpakitlib.ar_sqlalchemy_model_util import OperationDBM, StoryLogDBM, BaseOperationTypes
20
21
  from arpakitlib.ar_sqlalchemy_util import SQLAlchemyDB
21
22
 
@@ -292,6 +293,7 @@ class ScheduledOperation(BaseModel):
292
293
  type: str
293
294
  input_data: dict[str, Any] | None = None
294
295
  is_time_func: Callable[[], bool]
296
+ timeout_after_creation: timedelta | None = None
295
297
 
296
298
 
297
299
  class ScheduledOperationCreatorWorker(BaseWorker):
@@ -315,6 +317,8 @@ class ScheduledOperationCreatorWorker(BaseWorker):
315
317
  self.sqlalchemy_db.init()
316
318
 
317
319
  def sync_run(self):
320
+ timeout = None
321
+
318
322
  for scheduled_operation in self.scheduled_operations:
319
323
  if not scheduled_operation.is_time_func():
320
324
  continue
@@ -327,10 +331,22 @@ class ScheduledOperationCreatorWorker(BaseWorker):
327
331
  session.commit()
328
332
  session.refresh(operation_dbm)
329
333
 
330
- def async_on_startup(self):
334
+ if scheduled_operation.timeout_after_creation is not None:
335
+ if timeout is not None:
336
+ if scheduled_operation.timeout_after_creation > timeout:
337
+ timeout = scheduled_operation.timeout_after_creation
338
+ else:
339
+ timeout = scheduled_operation.timeout_after_creation
340
+
341
+ if timeout is not None:
342
+ sync_safe_sleep(n=timeout)
343
+
344
+ async def async_on_startup(self):
331
345
  self.sqlalchemy_db.init()
332
346
 
333
- def async_run(self):
347
+ async def async_run(self):
348
+ timeout: timedelta | None = None
349
+
334
350
  for scheduled_operation in self.scheduled_operations:
335
351
  if not scheduled_operation.is_time_func():
336
352
  continue
@@ -343,6 +359,16 @@ class ScheduledOperationCreatorWorker(BaseWorker):
343
359
  session.commit()
344
360
  session.refresh(operation_dbm)
345
361
 
362
+ if scheduled_operation.timeout_after_creation is not None:
363
+ if timeout is not None:
364
+ if scheduled_operation.timeout_after_creation > timeout:
365
+ timeout = scheduled_operation.timeout_after_creation
366
+ else:
367
+ timeout = scheduled_operation.timeout_after_creation
368
+
369
+ if timeout is not None:
370
+ await async_safe_sleep(n=timeout)
371
+
346
372
 
347
373
  def every_timedelta_is_time_func(*, td: timedelta) -> Callable:
348
374
  last_now_utc_dt = now_utc_dt()
@@ -35,8 +35,8 @@ class SimpleSettings(BaseSettings):
35
35
  return v
36
36
 
37
37
  @property
38
- def is_mode_type_dev(self) -> bool:
39
- return self.mode_type == self.ModeTypes.dev
38
+ def is_mode_type_not_prod(self) -> bool:
39
+ return self.mode_type == self.ModeTypes.not_prod
40
40
 
41
41
  @property
42
42
  def is_mode_type_prod(self) -> bool:
@@ -45,3 +45,10 @@ class SimpleSettings(BaseSettings):
45
45
  @classmethod
46
46
  def generate_env_example(cls) -> str:
47
47
  return generate_env_example(settings_class=cls)
48
+
49
+ @classmethod
50
+ def save_env_example_to_file(cls, filepath: str) -> str:
51
+ env_example = cls.generate_env_example()
52
+ with open(filepath, mode="w") as f:
53
+ f.write(env_example)
54
+ return env_example
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arpakitlib
3
- Version: 1.7.44
3
+ Version: 1.7.45
4
4
  Summary: arpakitlib
5
5
  Home-page: https://github.com/ARPAKIT-Company/arpakitlib
6
6
  License: Apache-2.0
@@ -6,7 +6,7 @@ arpakitlib/_arpakit_project_template/AUTHOR.md,sha256=d5QAx-1vbHfYYABpNQ0Yfjaxsw
6
6
  arpakitlib/_arpakit_project_template/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
7
7
  arpakitlib/_arpakit_project_template/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
8
8
  arpakitlib/_arpakit_project_template/README.md,sha256=EEoHPZrJQtLS3fKD3JvoPhkGhjfuDihxK5fmAGwihCQ,65
9
- arpakitlib/_arpakit_project_template/example.env,sha256=p5qdXuMHudefuGVkf1dcqSDlS3Xx2TjvebeufaROMOE,439
9
+ arpakitlib/_arpakit_project_template/example.env,sha256=CgmnowXuyz3_VGVPtS4e2hGupEIa_zeWY5zfOjsW4pc,462
10
10
  arpakitlib/_arpakit_project_template/manage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  arpakitlib/_arpakit_project_template/manage/docker_ps.sh,sha256=uwm8vHgeuNLCOn0o9hgP_uc-PUkS9FwLyzZh6ItZ3do,15
12
12
  arpakitlib/_arpakit_project_template/manage/docker_ps_a.sh,sha256=nOQejihYlzstg9oROvYwHIsSLt2Sw0DWQEeT3GBaBNs,18
@@ -59,7 +59,7 @@ arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_7.py,sha256=WdE1IWyO
59
59
  arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_8.sh,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
60
  arpakitlib/_arpakit_project_template/manage/sandbox/sandbox_9.sh,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
61
61
  arpakitlib/_arpakit_project_template/manage/settings_check.py,sha256=DeOGoWXgk2_VXpCIFbQgf1k2zcnv4hOLWIVc5BDv80c,260
62
- arpakitlib/_arpakit_project_template/manage/settings_generate_env_example.py,sha256=pRTr6SzBJxDUaxTXZgLJr7rJawHyvpyTJbrJSZW0hEc,330
62
+ arpakitlib/_arpakit_project_template/manage/settings_generate_env_example.py,sha256=BLLeF4JenexXbO1mMj8X-lB81TG3-QTmN4DjPYEUI8o,288
63
63
  arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_check_conn.py,sha256=3Q4QfvFVBZsbMMH5yr6v3a6v6UjQuIEIujlxGpvykNA,190
64
64
  arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_init.py,sha256=FqKVuakafDndHKBsyPcSowhss6MZb0Soy5oREUPVLUw,184
65
65
  arpakitlib/_arpakit_project_template/manage/sqlalchemy_db_reinit.py,sha256=twBWh64WU-sqHUte8v9ZJUZ_bCsFABExgIWLOnfLu4w,186
@@ -94,9 +94,9 @@ arpakitlib/_arpakit_project_template/src/db/__init__.py,sha256=47DEQpj8HBSa-_TIm
94
94
  arpakitlib/_arpakit_project_template/src/db/sqlalchemy_model.py,sha256=nXtayUkBaVb6tWx5qJgXZLbLOTVAjnSLpSDxBm7yZLc,234
95
95
  arpakitlib/_arpakit_project_template/src/db/util.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
96
  arpakitlib/_arpakit_project_template/src/operation_execution/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
97
- arpakitlib/_arpakit_project_template/src/operation_execution/const.py,sha256=4wOXu1042rDeNMe0KhMEhRVtJajQfoYMeqqaQ_UICkk,287
97
+ arpakitlib/_arpakit_project_template/src/operation_execution/const.py,sha256=HjupGEDUWVijQlbzxZPI9vBbAVOETUYzYU9pdnc9IcI,176
98
98
  arpakitlib/_arpakit_project_template/src/operation_execution/operation_executor.py,sha256=5sZpn3tVxnmcuIVRD5sbBhiMY5SAqPCc4tHzoNzDe4c,619
99
- arpakitlib/_arpakit_project_template/src/operation_execution/scheduled_operations.py,sha256=slgfIZikNcTPchjb8hxpf1aGCqlN0Q4VO-LxbptNOCA,484
99
+ arpakitlib/_arpakit_project_template/src/operation_execution/scheduled_operations.py,sha256=hBPZIOJAX7ym54s2tJ2QRky15FqqDF9r4yTr8Nh2YqI,985
100
100
  arpakitlib/_arpakit_project_template/src/operation_execution/start_operation_executor_for_dev_.py,sha256=N-X3kvjQZeEDxp2Z7DDrr4hR-wR9LmFMLPAA8tzo87A,589
101
101
  arpakitlib/_arpakit_project_template/src/operation_execution/start_scheduled_operation_creator_for_dev.py,sha256=RyHCafGTJaY-o3mgt7MReqgJ2txoBDhhsFzrjRiZWe4,574
102
102
  arpakitlib/_arpakit_project_template/src/test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -156,12 +156,12 @@ arpakitlib/ar_logging_util.py,sha256=Gyd7B9k0glIXPm6dASiigWLq9LC9lw6vhXTCeWpY5PY
156
156
  arpakitlib/ar_mongodb_util.py,sha256=2ECkTnGAZ92qxioL-fmN6R4yZOSr3bXdXLWTzT1C3vk,4038
157
157
  arpakitlib/ar_need_type_util.py,sha256=xq5bbAXJG-93CRVZUcLW0ZdM22rj-ZUW17C5hX_5grg,1699
158
158
  arpakitlib/ar_openai_api_client_util.py,sha256=dHUbfg1sVVCjsNl_fra3iCMEz1bR-Hk9fE-DdYbu7Wc,1215
159
- arpakitlib/ar_operation_execution_util.py,sha256=EZMQbjvp3EDFEfUYAdRV7_qtdqIW-qJrmVWpv5plxas,13874
159
+ arpakitlib/ar_operation_execution_util.py,sha256=EL7X7vN2GlOjlps3lCNoJPOP5lyqpbz4VTKmOWz7gVE,14948
160
160
  arpakitlib/ar_parse_command.py,sha256=-s61xcATIsfw1eV_iD3xi-grsitbGzSDoAFc5V0OFy4,3447
161
161
  arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJAdo,945
162
162
  arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
163
163
  arpakitlib/ar_schedule_uust_api_client_util.py,sha256=JD-hRUQSs-euK0zq9w_4QUfGO00yWM08gllWUVKTtHc,6109
164
- arpakitlib/ar_settings_util.py,sha256=95SaC8ROUoFFIZvGsOUmz4OEyn-KospL_EqjFYAJs9U,1231
164
+ arpakitlib/ar_settings_util.py,sha256=gnuC8rs7IkyXkRWurrV-K0jObDMMxeH_1NdfJLkekHA,1473
165
165
  arpakitlib/ar_sleep_util.py,sha256=OaLtRaJQWMkGjfj_mW1RB2P4RaSWsAIH8LUoXqsH0zM,1061
166
166
  arpakitlib/ar_sqlalchemy_model_util.py,sha256=TFGOAgpxcnBV_u7yZrLCkf1ldlB4Of8vIRsyk9kyP5c,4987
167
167
  arpakitlib/ar_sqlalchemy_util.py,sha256=Hcg1THrDsSR_-8dsY1CG3NWPEv0FqCbkPXFXLtjlSJ0,4207
@@ -170,9 +170,9 @@ arpakitlib/ar_str_util.py,sha256=oCEtQ_TTn35OEz9jCNLjbhopq76JmaifD_iYR-nEJJ4,214
170
170
  arpakitlib/ar_type_util.py,sha256=e6Ch8I_B3FMJMj-fiZvTwtGde4hxSa48fGt5g8RlV6I,2301
171
171
  arpakitlib/ar_yookassa_api_client_util.py,sha256=sh4fcUkAkdOetFn9JYoTvjcSXP-M1wU04KEY-ECLfLg,5137
172
172
  arpakitlib/ar_zabbix_api_client_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
173
- arpakitlib-1.7.44.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
174
- arpakitlib-1.7.44.dist-info/METADATA,sha256=9Rsxl80OE2FYpC5fZKMwsvGOHbxY3o0t7djohbxNnzs,2824
175
- arpakitlib-1.7.44.dist-info/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
176
- arpakitlib-1.7.44.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
177
- arpakitlib-1.7.44.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
178
- arpakitlib-1.7.44.dist-info/RECORD,,
173
+ arpakitlib-1.7.45.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
174
+ arpakitlib-1.7.45.dist-info/METADATA,sha256=7WXqfpqnXNdClOAoxKGuDN9DwBfiMcVB7MO203v_cyU,2824
175
+ arpakitlib-1.7.45.dist-info/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
176
+ arpakitlib-1.7.45.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
177
+ arpakitlib-1.7.45.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
178
+ arpakitlib-1.7.45.dist-info/RECORD,,