orionis 0.511.0__py3-none-any.whl → 0.512.0__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.
- orionis/console/base/scheduler_event_listener.py +136 -0
- orionis/console/commands/scheduler_work.py +37 -25
- orionis/console/contracts/event.py +3032 -9
- orionis/console/contracts/schedule.py +34 -0
- orionis/console/contracts/schedule_event_listener.py +324 -0
- orionis/console/entities/all_jobs_removed.py +23 -0
- orionis/console/entities/executor_added.py +23 -0
- orionis/console/entities/executor_removed.py +25 -0
- orionis/console/entities/job_added.py +24 -0
- orionis/console/entities/job_error.py +35 -0
- orionis/console/entities/job_event_data.py +40 -0
- orionis/console/entities/job_executed.py +31 -0
- orionis/console/entities/job_max_instances.py +27 -0
- orionis/console/entities/job_missed.py +25 -0
- orionis/console/entities/job_modified.py +23 -0
- orionis/console/entities/job_pause.py +22 -0
- orionis/console/entities/job_removed.py +22 -0
- orionis/console/entities/job_resume.py +25 -0
- orionis/console/entities/job_store_added.py +24 -0
- orionis/console/entities/job_store_removed.py +25 -0
- orionis/console/entities/job_submitted.py +24 -0
- orionis/console/entities/scheduler_event_data.py +33 -0
- orionis/console/entities/scheduler_paused.py +17 -0
- orionis/console/entities/scheduler_resumed.py +24 -0
- orionis/console/entities/scheduler_shutdown.py +23 -0
- orionis/console/entities/scheduler_started.py +21 -0
- orionis/console/enums/listener.py +75 -0
- orionis/console/tasks/event.py +3703 -21
- orionis/console/tasks/schedule.py +702 -48
- orionis/metadata/framework.py +1 -1
- {orionis-0.511.0.dist-info → orionis-0.512.0.dist-info}/METADATA +1 -1
- {orionis-0.511.0.dist-info → orionis-0.512.0.dist-info}/RECORD +36 -15
- orionis/console/contracts/listener.py +0 -132
- orionis/console/entities/listeners.py +0 -241
- orionis/console/tasks/exception_report.py +0 -94
- {orionis-0.511.0.dist-info → orionis-0.512.0.dist-info}/WHEEL +0 -0
- {orionis-0.511.0.dist-info → orionis-0.512.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.511.0.dist-info → orionis-0.512.0.dist-info}/top_level.txt +0 -0
- {orionis-0.511.0.dist-info → orionis-0.512.0.dist-info}/zip-safe +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
from orionis.console.contracts.schedule import ISchedule
|
|
2
|
+
from orionis.console.contracts.schedule_event_listener import IScheduleEventListener
|
|
3
|
+
from orionis.console.entities.job_error import JobError
|
|
4
|
+
from orionis.console.entities.job_executed import JobExecuted
|
|
5
|
+
from orionis.console.entities.job_max_instances import JobMaxInstances
|
|
6
|
+
from orionis.console.entities.job_missed import JobMissed
|
|
7
|
+
from orionis.console.entities.job_pause import JobPause
|
|
8
|
+
from orionis.console.entities.job_removed import JobRemoved
|
|
9
|
+
from orionis.console.entities.job_resume import JobResume
|
|
10
|
+
from orionis.console.entities.job_submitted import JobSubmitted
|
|
11
|
+
|
|
12
|
+
class BaseScheduleEventListener(IScheduleEventListener):
|
|
13
|
+
"""
|
|
14
|
+
Base implementation of the IScheduleEventListener interface.
|
|
15
|
+
|
|
16
|
+
This class provides method definitions for handling various job events in a
|
|
17
|
+
scheduling system. Subclasses should override these methods to implement
|
|
18
|
+
specific behavior for each event type.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
async def before(self, event: JobSubmitted, schedule: ISchedule):
|
|
22
|
+
"""
|
|
23
|
+
Called before processing a job submission event.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
event : JobSubmitted
|
|
28
|
+
The job submission event.
|
|
29
|
+
schedule : ISchedule
|
|
30
|
+
The associated schedule.
|
|
31
|
+
"""
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
async def after(self, event: JobExecuted, schedule: ISchedule):
|
|
35
|
+
"""
|
|
36
|
+
Called after processing a job execution event.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
event : JobExecuted
|
|
41
|
+
The job execution event.
|
|
42
|
+
schedule : ISchedule
|
|
43
|
+
The associated schedule.
|
|
44
|
+
"""
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
async def onSuccess(self, event: JobExecuted, schedule: ISchedule):
|
|
48
|
+
"""
|
|
49
|
+
Called when a job is successfully executed.
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
----------
|
|
53
|
+
event : JobExecuted
|
|
54
|
+
The successful job execution event.
|
|
55
|
+
schedule : ISchedule
|
|
56
|
+
The associated schedule.
|
|
57
|
+
"""
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
async def onFailure(self, event: JobError, schedule: ISchedule):
|
|
61
|
+
"""
|
|
62
|
+
Called when a job execution fails.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
event : JobError
|
|
67
|
+
The job error event.
|
|
68
|
+
schedule : ISchedule
|
|
69
|
+
The associated schedule.
|
|
70
|
+
"""
|
|
71
|
+
pass
|
|
72
|
+
|
|
73
|
+
async def onMissed(self, event: JobMissed, schedule: ISchedule):
|
|
74
|
+
"""
|
|
75
|
+
Called when a job execution is missed.
|
|
76
|
+
|
|
77
|
+
Parameters
|
|
78
|
+
----------
|
|
79
|
+
event : JobMissed
|
|
80
|
+
The missed job event.
|
|
81
|
+
schedule : ISchedule
|
|
82
|
+
The associated schedule.
|
|
83
|
+
"""
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
async def onMaxInstances(self, event: JobMaxInstances, schedule: ISchedule):
|
|
87
|
+
"""
|
|
88
|
+
Called when a job exceeds the maximum allowed instances.
|
|
89
|
+
|
|
90
|
+
Parameters
|
|
91
|
+
----------
|
|
92
|
+
event : JobMaxInstances
|
|
93
|
+
The max instances event.
|
|
94
|
+
schedule : ISchedule
|
|
95
|
+
The associated schedule.
|
|
96
|
+
"""
|
|
97
|
+
pass
|
|
98
|
+
|
|
99
|
+
async def onPaused(self, event: JobPause, schedule: ISchedule):
|
|
100
|
+
"""
|
|
101
|
+
Called when the scheduler is paused.
|
|
102
|
+
|
|
103
|
+
Parameters
|
|
104
|
+
----------
|
|
105
|
+
event : JobPause
|
|
106
|
+
The pause event.
|
|
107
|
+
schedule : ISchedule
|
|
108
|
+
The associated schedule.
|
|
109
|
+
"""
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
async def onResumed(self, event: JobResume, schedule: ISchedule):
|
|
113
|
+
"""
|
|
114
|
+
Called when the scheduler is resumed.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
event : JobResume
|
|
119
|
+
The resume event.
|
|
120
|
+
schedule : ISchedule
|
|
121
|
+
The associated schedule.
|
|
122
|
+
"""
|
|
123
|
+
pass
|
|
124
|
+
|
|
125
|
+
async def onRemoved(self, event: JobRemoved, schedule: ISchedule):
|
|
126
|
+
"""
|
|
127
|
+
Called when a job is removed from the scheduler.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
event : JobRemoved
|
|
132
|
+
The job removal event.
|
|
133
|
+
schedule : ISchedule
|
|
134
|
+
The associated schedule.
|
|
135
|
+
"""
|
|
136
|
+
pass
|
|
@@ -4,6 +4,7 @@ from rich.panel import Panel
|
|
|
4
4
|
from rich.text import Text
|
|
5
5
|
from orionis.console.base.command import BaseCommand
|
|
6
6
|
from orionis.console.contracts.schedule import ISchedule
|
|
7
|
+
from orionis.console.enums.listener import ListeningEvent
|
|
7
8
|
from orionis.console.exceptions import CLIOrionisRuntimeError
|
|
8
9
|
from orionis.container.exceptions.exception import OrionisContainerException
|
|
9
10
|
from orionis.foundation.contracts.application import IApplication
|
|
@@ -74,16 +75,16 @@ class ScheduleWorkCommand(BaseCommand):
|
|
|
74
75
|
try:
|
|
75
76
|
|
|
76
77
|
# Retrieve the Scheduler instance from the application
|
|
77
|
-
|
|
78
|
+
scheduler = app.getScheduler()
|
|
78
79
|
|
|
79
80
|
# Create an instance of the ISchedule service
|
|
80
|
-
|
|
81
|
+
schedule_service: ISchedule = app.make(ISchedule)
|
|
81
82
|
|
|
82
83
|
# Register scheduled tasks using the Scheduler's tasks method
|
|
83
|
-
|
|
84
|
+
await scheduler.tasks(schedule_service)
|
|
84
85
|
|
|
85
86
|
# Retrieve the list of scheduled jobs/events
|
|
86
|
-
list_tasks =
|
|
87
|
+
list_tasks = schedule_service.events()
|
|
87
88
|
|
|
88
89
|
# Display a message if no scheduled jobs are found
|
|
89
90
|
if not list_tasks:
|
|
@@ -92,33 +93,44 @@ class ScheduleWorkCommand(BaseCommand):
|
|
|
92
93
|
console.line()
|
|
93
94
|
return True
|
|
94
95
|
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
96
|
+
# If there are scheduled jobs and the scheduler has an onStarted method
|
|
97
|
+
if hasattr(scheduler, "onStarted"):
|
|
98
|
+
schedule_service._setListener(ListeningEvent.SCHEDULER_STARTED.value, scheduler.onStarted)
|
|
99
|
+
|
|
100
|
+
# If the scheduler has an onPaused method
|
|
101
|
+
if hasattr(scheduler, "onPaused"):
|
|
102
|
+
schedule_service._setListener(ListeningEvent.SCHEDULER_PAUSED.value, scheduler.onPaused)
|
|
103
|
+
|
|
104
|
+
# If the scheduler has an onResumed method
|
|
105
|
+
if hasattr(scheduler, "onResumed"):
|
|
106
|
+
schedule_service._setListener(ListeningEvent.SCHEDULER_RESUMED.value, scheduler.onResumed)
|
|
107
|
+
|
|
108
|
+
# If the scheduler has an onFinalized method
|
|
109
|
+
if hasattr(scheduler, "onFinalized"):
|
|
110
|
+
schedule_service._setListener(ListeningEvent.SCHEDULER_SHUTDOWN.value, scheduler.onFinalized)
|
|
111
|
+
|
|
112
|
+
# If the scheduler has an onError method
|
|
113
|
+
if hasattr(scheduler, "onError"):
|
|
114
|
+
schedule_service._setListener(ListeningEvent.SCHEDULER_ERROR.value, scheduler.onError)
|
|
115
|
+
|
|
116
|
+
# Check if the scheduler has specific pause, resume, and finalize times
|
|
117
|
+
if hasattr(scheduler, "PAUSE_AT") and isinstance(scheduler.PAUSE_AT, datetime):
|
|
118
|
+
schedule_service.pauseEverythingAt(scheduler.PAUSE_AT)
|
|
119
|
+
|
|
120
|
+
if hasattr(scheduler, "RESUME_AT") and isinstance(scheduler.RESUME_AT, datetime):
|
|
121
|
+
schedule_service.resumeEverythingAt(scheduler.RESUME_AT)
|
|
122
|
+
|
|
123
|
+
if hasattr(scheduler, "FINALIZE_AT") and isinstance(scheduler.FINALIZE_AT, datetime):
|
|
124
|
+
schedule_service.shutdownEverythingAt(scheduler.FINALIZE_AT)
|
|
111
125
|
|
|
112
126
|
# Start the scheduler worker asynchronously
|
|
113
|
-
await
|
|
127
|
+
await schedule_service.start()
|
|
128
|
+
|
|
129
|
+
# Flag to indicate the scheduler is running
|
|
114
130
|
return True
|
|
115
131
|
|
|
116
132
|
except Exception as e:
|
|
117
133
|
|
|
118
|
-
# If the exception is already a CLIOrionisRuntimeError or OrionisContainerException, re-raise it
|
|
119
|
-
if isinstance(e, (OrionisRuntimeError, OrionisContainerException)):
|
|
120
|
-
raise
|
|
121
|
-
|
|
122
134
|
# Raise any unexpected exceptions as CLIOrionisRuntimeError
|
|
123
135
|
raise CLIOrionisRuntimeError(
|
|
124
136
|
f"An unexpected error occurred while starting the scheduler worker: {e}"
|