patera-taskmanager 0.2.0__tar.gz → 0.2.2__tar.gz
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.
- {patera_taskmanager-0.2.0 → patera_taskmanager-0.2.2}/PKG-INFO +2 -2
- {patera_taskmanager-0.2.0 → patera_taskmanager-0.2.2}/pyproject.toml +2 -2
- {patera_taskmanager-0.2.0 → patera_taskmanager-0.2.2}/src/patera/taskmanager/task_manager.py +14 -30
- {patera_taskmanager-0.2.0 → patera_taskmanager-0.2.2}/src/patera/taskmanager/__init__.py +0 -0
{patera_taskmanager-0.2.0 → patera_taskmanager-0.2.2}/src/patera/taskmanager/task_manager.py
RENAMED
|
@@ -4,14 +4,14 @@ Task manager class
|
|
|
4
4
|
|
|
5
5
|
from typing import (
|
|
6
6
|
Callable,
|
|
7
|
+
Generic,
|
|
7
8
|
Tuple,
|
|
8
9
|
Optional,
|
|
9
10
|
Type,
|
|
11
|
+
TypeVar,
|
|
10
12
|
cast,
|
|
11
13
|
TYPE_CHECKING,
|
|
12
14
|
Any,
|
|
13
|
-
TypedDict,
|
|
14
|
-
NotRequired,
|
|
15
15
|
)
|
|
16
16
|
from functools import wraps
|
|
17
17
|
|
|
@@ -31,7 +31,7 @@ if TYPE_CHECKING:
|
|
|
31
31
|
from patera import Patera
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
class
|
|
34
|
+
class TaskManagerConfig(BaseModel):
|
|
35
35
|
"""Configuration model for TaskManager extension."""
|
|
36
36
|
|
|
37
37
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
@@ -62,26 +62,17 @@ class _TaskManagerConfigs(BaseModel):
|
|
|
62
62
|
)
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
"""TypedDict for TaskManager configuration."""
|
|
65
|
+
AppT = TypeVar("AppT", bound="Patera", default="Patera")
|
|
67
66
|
|
|
68
|
-
NICE_NAME: NotRequired[str]
|
|
69
|
-
SCHEDULER: NotRequired[Type[BaseScheduler]]
|
|
70
|
-
JOB_STORES: NotRequired[dict[str, BaseJobStore]]
|
|
71
|
-
EXECUTORS: NotRequired[dict[str, BaseExecutor]]
|
|
72
|
-
JOB_DEFAULTS: NotRequired[dict[str, bool | int]]
|
|
73
|
-
DAEMON: NotRequired[bool]
|
|
74
67
|
|
|
75
|
-
|
|
76
|
-
class TaskManager(BaseExtension):
|
|
68
|
+
class TaskManager(BaseExtension[AppT], Generic[AppT]):
|
|
77
69
|
"""
|
|
78
70
|
Task manager class for scheduling and managing backgroudn tasks.
|
|
79
71
|
"""
|
|
80
72
|
|
|
81
|
-
def __init__(self
|
|
82
|
-
self._configs_name: str = cast(str, configs_name)
|
|
73
|
+
def __init__(self) -> None:
|
|
83
74
|
self._configs: dict[str, Any] = {}
|
|
84
|
-
self._app:
|
|
75
|
+
self._app: AppT = cast(AppT, None)
|
|
85
76
|
self._job_stores: dict
|
|
86
77
|
self._executors: dict
|
|
87
78
|
self._job_defaults: dict
|
|
@@ -90,14 +81,14 @@ class TaskManager(BaseExtension):
|
|
|
90
81
|
self._initial_jobs_methods_list: list[Tuple] = []
|
|
91
82
|
self._active_jobs: dict[str, Job] = {}
|
|
92
83
|
|
|
93
|
-
def init_app(self, app:
|
|
84
|
+
def init_app(self, app: AppT):
|
|
94
85
|
"""
|
|
95
86
|
Initlizer for TaskManager with Patera app
|
|
96
87
|
"""
|
|
97
88
|
self._app = app # type: ignore
|
|
98
|
-
self._configs =
|
|
89
|
+
self._configs = self.load_configs() or {}
|
|
99
90
|
|
|
100
|
-
self._configs = self.validate_configs(self._configs,
|
|
91
|
+
self._configs = self.validate_configs(self._configs, TaskManagerConfig)
|
|
101
92
|
self._job_stores = self._configs["JOB_STORES"]
|
|
102
93
|
self._executors = self._configs["EXECUTORS"]
|
|
103
94
|
self._job_defaults = self._configs["JOB_DEFAULTS"]
|
|
@@ -110,7 +101,7 @@ class TaskManager(BaseExtension):
|
|
|
110
101
|
job_defaults=self._job_defaults,
|
|
111
102
|
daemon=self._daemon,
|
|
112
103
|
) # type: ignore
|
|
113
|
-
self._app.add_extension(self)
|
|
104
|
+
# self._app.add_extension(self)
|
|
114
105
|
self._get_defined_jobs()
|
|
115
106
|
self._app.add_on_startup_method(self._start_scheduler)
|
|
116
107
|
self._app.add_on_shutdown_method(self._stop_scheduler)
|
|
@@ -190,7 +181,7 @@ class TaskManager(BaseExtension):
|
|
|
190
181
|
:param job: job id (str) or the Job instance returned by the scheduler.add_job method
|
|
191
182
|
"""
|
|
192
183
|
if isinstance(job, Job):
|
|
193
|
-
job = job.id
|
|
184
|
+
job = job.id # type: ignore
|
|
194
185
|
return self._remove_job(cast(str, job), job_store)
|
|
195
186
|
|
|
196
187
|
def pause_job(self, job: str | Job):
|
|
@@ -198,7 +189,7 @@ class TaskManager(BaseExtension):
|
|
|
198
189
|
Pauses the job
|
|
199
190
|
"""
|
|
200
191
|
if isinstance(job, Job):
|
|
201
|
-
return job.pause()
|
|
192
|
+
return job.pause() # type: ignore
|
|
202
193
|
active_job: Optional[Job] = self._active_jobs.get(job, None)
|
|
203
194
|
if job is None:
|
|
204
195
|
raise JobLookupError(job)
|
|
@@ -210,7 +201,7 @@ class TaskManager(BaseExtension):
|
|
|
210
201
|
:param paused_job: id or Job instance
|
|
211
202
|
"""
|
|
212
203
|
if isinstance(job, Job):
|
|
213
|
-
return job.resume()
|
|
204
|
+
return job.resume() # type: ignore
|
|
214
205
|
paused_job: Optional[Job] = self._active_jobs.get(job, None)
|
|
215
206
|
if paused_job is None:
|
|
216
207
|
raise JobLookupError(paused_job)
|
|
@@ -245,13 +236,6 @@ class TaskManager(BaseExtension):
|
|
|
245
236
|
"""Nice name of the instance"""
|
|
246
237
|
return self._configs["NICE_NAME"]
|
|
247
238
|
|
|
248
|
-
@property
|
|
249
|
-
def app(self) -> "Patera":
|
|
250
|
-
"""
|
|
251
|
-
Application instance
|
|
252
|
-
"""
|
|
253
|
-
return cast("Patera", self._app)
|
|
254
|
-
|
|
255
239
|
|
|
256
240
|
def schedule_job(*args, **kwargs):
|
|
257
241
|
"""
|
|
File without changes
|