arpakitlib 1.7.96__py3-none-any.whl → 1.7.98__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.
File without changes
@@ -34,7 +34,7 @@ class BaseWorker(ABC):
34
34
  worker_name = self.__class__.__name__
35
35
  self.worker_name = worker_name
36
36
  self.worker_creation_dt = now_utc_dt()
37
- self.worker_id = f"{str(uuid4()).replace(' - ', '')}_{randint(1000, 9999)}"
37
+ self.worker_id = f"{str(uuid4()).replace('-', '')}_{randint(1000, 99999)}"
38
38
  self.worker_fullname = (
39
39
  f"{self.worker_name}_{self.worker_creation_dt.isoformat()}_{self.worker_id}"
40
40
  )
@@ -25,7 +25,7 @@ from starlette import status
25
25
  from starlette.middleware.cors import CORSMiddleware
26
26
  from starlette.staticfiles import StaticFiles
27
27
 
28
- from arpakitlib.ar_base_worker_util import BaseWorker, safe_run_worker_in_background, SafeRunInBackgroundModes
28
+ from arpakitlib.ar_base_worker_util import BaseWorker, safe_run_worker_in_background
29
29
  from arpakitlib.ar_dict_util import combine_dicts
30
30
  from arpakitlib.ar_enumeration_util import Enumeration
31
31
  from arpakitlib.ar_file_storage_in_dir_util import FileStorageInDir
@@ -448,7 +448,7 @@ class SafeRunWorkerStartupAPIEvent(BaseStartupAPIEvent):
448
448
 
449
449
  async def async_on_startup(self, *args, **kwargs):
450
450
  for worker in self.workers:
451
- _ = safe_run_worker_in_background(worker=worker, mode=SafeRunInBackgroundModes.async_task)
451
+ _ = safe_run_worker_in_background(worker=worker, mode=self.safe_run_in_background_mode)
452
452
 
453
453
 
454
454
  class InitFileStoragesInDir(BaseStartupAPIEvent):
@@ -145,7 +145,7 @@ class BaseOperationExecutor:
145
145
  self._logger = logging.getLogger(self.__class__.__name__)
146
146
  self.sql_alchemy_db = sqlalchemy_db
147
147
 
148
- def sync_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
148
+ def sync_execute_operation(self, operation_dbm: OperationDBM, session: Session) -> OperationDBM:
149
149
  if operation_dbm.type == BaseOperationTypes.healthcheck_:
150
150
  self._logger.info("healthcheck")
151
151
  elif operation_dbm.type == BaseOperationTypes.raise_fake_exception_:
@@ -172,13 +172,12 @@ class BaseOperationExecutor:
172
172
  }
173
173
  )
174
174
  session.commit()
175
- session.refresh(operation_dbm)
176
175
 
177
176
  exception: BaseException | None = None
178
177
  traceback_str: str | None = None
179
178
 
180
179
  try:
181
- self.sync_execute_operation(operation_dbm=operation_dbm)
180
+ self.sync_execute_operation(operation_dbm=operation_dbm, session=session)
182
181
  except BaseException as exception_:
183
182
  self._logger.error(
184
183
  f"error in sync_execute_operation (id={operation_dbm.id}, type={operation_dbm.type})",
@@ -213,7 +212,6 @@ class BaseOperationExecutor:
213
212
  )
214
213
  session.add(story_log_dbm)
215
214
  session.commit()
216
- session.refresh(story_log_dbm)
217
215
 
218
216
  session.refresh(operation_dbm)
219
217
 
@@ -227,7 +225,7 @@ class BaseOperationExecutor:
227
225
 
228
226
  return operation_dbm
229
227
 
230
- async def async_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
228
+ async def async_execute_operation(self, operation_dbm: OperationDBM, session: Session) -> OperationDBM:
231
229
  if operation_dbm.type == BaseOperationTypes.healthcheck_:
232
230
  self._logger.info("healthcheck")
233
231
  elif operation_dbm.type == BaseOperationTypes.raise_fake_exception_:
@@ -236,7 +234,7 @@ class BaseOperationExecutor:
236
234
  return operation_dbm
237
235
 
238
236
  async def async_safe_execute_operation(
239
- self, operation_dbm: OperationDBM, worker: OperationExecutorWorker
237
+ self, operation_dbm: OperationDBM, worker: OperationExecutorWorker, session: Session
240
238
  ) -> OperationDBM:
241
239
  self._logger.info(
242
240
  f"start "
@@ -245,26 +243,21 @@ class BaseOperationExecutor:
245
243
  f"operation_dbm.status={operation_dbm.status}"
246
244
  )
247
245
 
248
- with self.sql_alchemy_db.new_session() as session:
249
- operation_dbm: OperationDBM = get_operation_by_id(
250
- session=session, filter_operation_id=operation_dbm.id, raise_if_not_found=True, lock=True
251
- )
252
- operation_dbm.execution_start_dt = now_utc_dt()
253
- operation_dbm.status = OperationDBM.Statuses.executing
254
- operation_dbm.output_data = combine_dicts(
255
- operation_dbm.output_data,
256
- {
257
- worker.worker_fullname: True
258
- }
259
- )
260
- session.commit()
261
- session.refresh(operation_dbm)
246
+ operation_dbm.execution_start_dt = now_utc_dt()
247
+ operation_dbm.status = OperationDBM.Statuses.executing
248
+ operation_dbm.output_data = combine_dicts(
249
+ operation_dbm.output_data,
250
+ {
251
+ worker.worker_fullname: True
252
+ }
253
+ )
254
+ session.commit()
262
255
 
263
256
  exception: BaseException | None = None
264
257
  traceback_str: str | None = None
265
258
 
266
259
  try:
267
- await self.async_execute_operation(operation_dbm=operation_dbm)
260
+ await self.async_execute_operation(operation_dbm=operation_dbm, session=session)
268
261
  except BaseException as exception_:
269
262
  self._logger.error(
270
263
  f"error in async_execute_operation (id={operation_dbm.id}, type={operation_dbm.type})",
@@ -273,40 +266,34 @@ class BaseOperationExecutor:
273
266
  exception = exception_
274
267
  traceback_str = traceback.format_exc()
275
268
 
276
- with self.sql_alchemy_db.new_session() as session:
269
+ operation_dbm.execution_finish_dt = now_utc_dt()
270
+ if exception:
271
+ operation_dbm.status = OperationDBM.Statuses.executed_with_error
272
+ operation_dbm.error_data = combine_dicts(
273
+ {
274
+ "exception_str": str(exception),
275
+ "traceback_str": traceback_str
276
+ },
277
+ operation_dbm.error_data
278
+ )
279
+ else:
280
+ operation_dbm.status = OperationDBM.Statuses.executed_without_error
281
+ session.commit()
277
282
 
278
- operation_dbm: OperationDBM = get_operation_by_id(
279
- session=session, filter_operation_id=operation_dbm.id, raise_if_not_found=True, lock=True
283
+ if exception:
284
+ story_log_dbm = StoryLogDBM(
285
+ level=StoryLogDBM.Levels.error,
286
+ title=f"error in async_execute_operation (id={operation_dbm.id}, type={operation_dbm.type})",
287
+ data={
288
+ "operation_id": operation_dbm.id,
289
+ "exception_str": str(exception),
290
+ "traceback_str": traceback_str
291
+ }
280
292
  )
281
- operation_dbm.execution_finish_dt = now_utc_dt()
282
- if exception:
283
- operation_dbm.status = OperationDBM.Statuses.executed_with_error
284
- operation_dbm.error_data = combine_dicts(
285
- {
286
- "exception_str": str(exception),
287
- "traceback_str": traceback_str
288
- },
289
- operation_dbm.error_data
290
- )
291
- else:
292
- operation_dbm.status = OperationDBM.Statuses.executed_without_error
293
+ session.add(story_log_dbm)
293
294
  session.commit()
294
295
 
295
- if exception:
296
- story_log_dbm = StoryLogDBM(
297
- level=StoryLogDBM.Levels.error,
298
- title=f"error in async_execute_operation (id={operation_dbm.id}, type={operation_dbm.type})",
299
- data={
300
- "operation_id": operation_dbm.id,
301
- "exception_str": str(exception),
302
- "traceback_str": traceback_str
303
- }
304
- )
305
- session.add(story_log_dbm)
306
- session.commit()
307
- session.refresh(story_log_dbm)
308
-
309
- session.refresh(operation_dbm)
296
+ session.refresh(operation_dbm)
310
297
 
311
298
  self._logger.info(
312
299
  f"finish async_safe_execute_operation, "
@@ -365,18 +352,21 @@ class OperationExecutorWorker(BaseWorker):
365
352
  self.sqlalchemy_db.init()
366
353
  await self.async_run_startup_funcs()
367
354
 
368
- async def async_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
369
- return await self.operation_executor.async_safe_execute_operation(operation_dbm=operation_dbm, worker=self)
355
+ async def async_execute_operation(self, operation_dbm: OperationDBM, session: Session) -> OperationDBM:
356
+ return await self.operation_executor.async_safe_execute_operation(
357
+ operation_dbm=operation_dbm, worker=self, session=session
358
+ )
370
359
 
371
360
  async def async_run(self):
372
- operation_dbm: OperationDBM | None = get_operation_for_execution(
373
- sqlalchemy_db=self.sqlalchemy_db,
374
- filter_operation_types=self.filter_operation_types,
375
- lock=True
376
- )
377
- if not operation_dbm:
378
- return
379
- await self.async_execute_operation(operation_dbm=operation_dbm)
361
+ with self.sqlalchemy_db.new_session() as session:
362
+ operation_dbm: OperationDBM | None = get_operation_for_execution(
363
+ sqlalchemy_db=self.sqlalchemy_db,
364
+ filter_operation_types=self.filter_operation_types,
365
+ lock=True
366
+ )
367
+ if not operation_dbm:
368
+ return
369
+ await self.async_execute_operation(operation_dbm=operation_dbm, session=session)
380
370
 
381
371
  async def async_run_on_error(self, exception: BaseException, **kwargs):
382
372
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arpakitlib
3
- Version: 1.7.96
3
+ Version: 1.7.98
4
4
  Summary: arpakitlib
5
5
  Home-page: https://github.com/ARPAKIT-Company/arpakitlib
6
6
  License: Apache-2.0
@@ -96,6 +96,7 @@ arpakitlib/_arpakit_project_template/src/core/const.py,sha256=CZZew674y7LhCAlYhv
96
96
  arpakitlib/_arpakit_project_template/src/core/settings.py,sha256=S1WPgnFWiRNjCXLllZHq6xp3AiyzzqnRBubg02iRkvo,2238
97
97
  arpakitlib/_arpakit_project_template/src/core/util.py,sha256=5R8gvcZdvuDQes45FBnLC2IDv2Jhajp1VhJJYNKYjMQ,1539
98
98
  arpakitlib/_arpakit_project_template/src/db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
99
+ arpakitlib/_arpakit_project_template/src/db/const.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
99
100
  arpakitlib/_arpakit_project_template/src/db/sqlalchemy_model.py,sha256=nXtayUkBaVb6tWx5qJgXZLbLOTVAjnSLpSDxBm7yZLc,234
100
101
  arpakitlib/_arpakit_project_template/src/db/util.py,sha256=8Jg9TtTwvyxVYIN_W5_lk9y-Pyh8To1aMRFUKCRDuuA,550
101
102
  arpakitlib/_arpakit_project_template/src/operation_execution/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -120,7 +121,7 @@ arpakitlib/ar_arpakit_project_template_util.py,sha256=AswzQvvb-zfUyrcP4EP0K756YL
120
121
  arpakitlib/ar_arpakit_schedule_uust_api_client_util.py,sha256=jGbP6egs2yhgfheyqhM0J-SeM2qp2YrW7dV-u9djv4Q,19223
121
122
  arpakitlib/ar_arpakitlib_cli_util.py,sha256=8lhEDxnwMSRX2PGV2xQtQru1AYKSA92SVolol5u7iBk,3154
122
123
  arpakitlib/ar_base64_util.py,sha256=aZkg2cZTuAaP2IWeG_LXJ6RO7qhyskVwec-Lks0iM-k,676
123
- arpakitlib/ar_base_worker_util.py,sha256=hV_bMfkO897s00VGMAQ-z8GFzq-vEcRW5TKcmeBhbYM,5667
124
+ arpakitlib/ar_base_worker_util.py,sha256=T53HIx1azgal4ZmBR1afXqQ3_zex35NIAYPHNchhxfs,5666
124
125
  arpakitlib/ar_cache_file_util.py,sha256=Fo2pH-Zqm966KWFBHG_pbiySGZvhIFCYqy7k1weRfJ0,3476
125
126
  arpakitlib/ar_datetime_util.py,sha256=Xe1NiT9oPQzNSG7RVRkhukhbg4i-hhS5ImmV7sPUc8o,971
126
127
  arpakitlib/ar_dict_util.py,sha256=cF5LQJ6tLqyGoEXfDljMDZrikeZoWPw7CgINHIFGvXM,419
@@ -148,7 +149,7 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
148
149
  arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
149
150
  arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
150
151
  arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
151
- arpakitlib/ar_fastapi_util.py,sha256=HcV_7VHmBsuiszff18ZfgT-kIIrfKoHoauxwH6TgvZ8,27751
152
+ arpakitlib/ar_fastapi_util.py,sha256=U0hLXT8WYU81AIy46l8YmEXoJPaM1G1NadixhEjnrW4,27722
152
153
  arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
153
154
  arpakitlib/ar_file_util.py,sha256=GUdJYm1tUZnYpY-SIPRHAZBHGra8NKy1eYEI0D5AfhY,489
154
155
  arpakitlib/ar_func_util.py,sha256=t-QVfP3YqPi0NgI6tUuTN-s5fPbduwILk3wo-2Wb_hw,1324
@@ -164,7 +165,7 @@ arpakitlib/ar_logging_util.py,sha256=mx3H6CzX9dsh29ruFmYnva8lL6mwvdBXmeHH9E2tvu8
164
165
  arpakitlib/ar_mongodb_util.py,sha256=2ECkTnGAZ92qxioL-fmN6R4yZOSr3bXdXLWTzT1C3vk,4038
165
166
  arpakitlib/ar_need_type_util.py,sha256=GETiREPMEYhch-yU6T--Bdawlbb04Jp1Qy7cOsUlIeA,2228
166
167
  arpakitlib/ar_openai_api_client_util.py,sha256=_XmlApvHFMSyjvZydPa_kASIt9LsFrZmSC7YEzIG8Bg,1806
167
- arpakitlib/ar_operation_execution_util.py,sha256=tm5o-GyinsBQgKCnKJoOizKsqPLmlV1IhADVqARsT6g,18241
168
+ arpakitlib/ar_operation_execution_util.py,sha256=bREu2IpBzbITEioS6SaL9bhvUPlYCuVgclTVEZCGx-Q,17696
168
169
  arpakitlib/ar_parse_command.py,sha256=-s61xcATIsfw1eV_iD3xi-grsitbGzSDoAFc5V0OFy4,3447
169
170
  arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJAdo,945
170
171
  arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
@@ -178,9 +179,9 @@ arpakitlib/ar_str_util.py,sha256=tFoGSDYoGpfdVHWor5Li9pEOFmDFlHkX-Z8iOy1LK7Y,353
178
179
  arpakitlib/ar_type_util.py,sha256=s0NsTM7mV3HuwyRwyYLdNn7Ep2HbyI4FIr-dd8x0lfI,3734
179
180
  arpakitlib/ar_yookassa_api_client_util.py,sha256=sh4fcUkAkdOetFn9JYoTvjcSXP-M1wU04KEY-ECLfLg,5137
180
181
  arpakitlib/ar_zabbix_api_client_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
181
- arpakitlib-1.7.96.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
182
- arpakitlib-1.7.96.dist-info/METADATA,sha256=NUdQncUnBReSw8GBQxkblcPDWJ5UImdIcZJ15hI5PAg,2824
183
- arpakitlib-1.7.96.dist-info/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
184
- arpakitlib-1.7.96.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
185
- arpakitlib-1.7.96.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
186
- arpakitlib-1.7.96.dist-info/RECORD,,
182
+ arpakitlib-1.7.98.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
183
+ arpakitlib-1.7.98.dist-info/METADATA,sha256=zkxKjwhBYByQZXxTdQlu96XUSDy0C0Q8Zcy8nowTSwI,2824
184
+ arpakitlib-1.7.98.dist-info/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
185
+ arpakitlib-1.7.98.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
186
+ arpakitlib-1.7.98.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
187
+ arpakitlib-1.7.98.dist-info/RECORD,,