11"""Cron-style application form: a single background mutation use case."""
22
33import asyncio
4- import enum
54import types
65from collections .abc import Iterator
76from json import JSONDecodeError
2423 UnavailableForContextHandler ,
2524 UnavailableGloballyHandler ,
2625)
26+ from jupiter .framework .appform .cron .execution_mode import CronExecutionMode
2727from jupiter .framework .appform .cron .trigger import cron_trigger_from_crontab
2828from jupiter .framework .auth .auth_token import (
2929 ExpiredAuthTokenError ,
6969)
7070
7171
72- class CronExecutionMode (enum .Enum ):
73- """How the cron process runs after startup."""
74-
75- START_RUN_STOP = "start_run_stop"
76- """Start, run the use case once, then exit."""
77-
78- RUN_FOREVER = "run_forever"
79- """Start and keep running the use case on its crontab (same model as WebAPI)."""
80-
81-
8272class Cron (
8373 AppForm [_PortsT , _GlobalPropertiesT , _ServicePropertiesT , _ComponentPropertiesT ],
8474 Generic [_PortsT , _GlobalPropertiesT , _ServicePropertiesT , _ComponentPropertiesT ],
@@ -140,6 +130,11 @@ def __init__(
140130 use_case = use_case ,
141131 )
142132
133+ @property
134+ def execution_mode (self ) -> CronExecutionMode :
135+ """How this cron process runs (once and exit vs scheduled loop)."""
136+ return self ._execution_mode
137+
143138 @classmethod
144139 def build_from_module_root (
145140 cls : type [_CronT ],
@@ -152,8 +147,8 @@ def build_from_module_root(
152147 invocation_recorder : MutationInvocationRecorder ,
153148 use_case_type : type [BackgroundMutationUseCase [Any , Any , Any , Any , Any ]], # type: ignore[explicit-any]
154149 exception_handler_base : type [_CronExceptionHandlerT ],
150+ execution_mode : CronExecutionMode ,
155151 * module_root : types .ModuleType ,
156- execution_mode : CronExecutionMode = CronExecutionMode .RUN_FOREVER ,
157152 ) -> _CronT :
158153 """Build the cron app form and register exception handlers from ``module_root``."""
159154
@@ -163,9 +158,7 @@ def extract_exception_handler(
163158 tuple [
164159 type [Exception ],
165160 type [
166- CronExceptionHandler [
167- GlobalProperties , ServiceProperties , Exception
168- ]
161+ CronExceptionHandler [GlobalProperties , ServiceProperties , Exception ]
169162 ],
170163 ]
171164 ]:
@@ -212,9 +205,7 @@ def extract_exception_handler(
212205 ):
213206 if exception_type in cron_app ._exception_handlers :
214207 continue
215- cron_app ._add_exception_handler (
216- exception_type , exception_handler_type
217- )
208+ cron_app ._add_exception_handler (exception_type , exception_handler_type )
218209
219210 return cron_app
220211
0 commit comments