orionis 0.512.0__py3-none-any.whl → 0.514.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.
@@ -2,7 +2,7 @@ from typing import Any, Dict, List
2
2
  from orionis.console.args.argument import CLIArgument
3
3
  from orionis.console.dynamic.progress_bar import ProgressBar
4
4
  from orionis.console.output.console import Console
5
- from orionis.console.base.contracts.command import IBaseCommand
5
+ from orionis.console.contracts.command import IBaseCommand
6
6
 
7
7
  class BaseCommand(Console, ProgressBar, IBaseCommand):
8
8
  """
@@ -1,5 +1,5 @@
1
1
  from datetime import datetime
2
- from orionis.console.base.contracts.scheduler import IBaseScheduler
2
+ from orionis.console.contracts.scheduler import IBaseScheduler
3
3
  from orionis.console.contracts.schedule import ISchedule
4
4
 
5
5
  class BaseScheduler(IBaseScheduler):
@@ -1,4 +1,3 @@
1
- from orionis.console.contracts.schedule import ISchedule
2
1
  from orionis.console.contracts.schedule_event_listener import IScheduleEventListener
3
2
  from orionis.console.entities.job_error import JobError
4
3
  from orionis.console.entities.job_executed import JobExecuted
@@ -18,7 +17,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
18
17
  specific behavior for each event type.
19
18
  """
20
19
 
21
- async def before(self, event: JobSubmitted, schedule: ISchedule):
20
+ async def before(self, event: JobSubmitted, schedule):
22
21
  """
23
22
  Called before processing a job submission event.
24
23
 
@@ -31,7 +30,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
31
30
  """
32
31
  pass
33
32
 
34
- async def after(self, event: JobExecuted, schedule: ISchedule):
33
+ async def after(self, event: JobExecuted, schedule):
35
34
  """
36
35
  Called after processing a job execution event.
37
36
 
@@ -44,7 +43,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
44
43
  """
45
44
  pass
46
45
 
47
- async def onSuccess(self, event: JobExecuted, schedule: ISchedule):
46
+ async def onSuccess(self, event: JobExecuted, schedule):
48
47
  """
49
48
  Called when a job is successfully executed.
50
49
 
@@ -57,7 +56,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
57
56
  """
58
57
  pass
59
58
 
60
- async def onFailure(self, event: JobError, schedule: ISchedule):
59
+ async def onFailure(self, event: JobError, schedule):
61
60
  """
62
61
  Called when a job execution fails.
63
62
 
@@ -70,7 +69,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
70
69
  """
71
70
  pass
72
71
 
73
- async def onMissed(self, event: JobMissed, schedule: ISchedule):
72
+ async def onMissed(self, event: JobMissed, schedule):
74
73
  """
75
74
  Called when a job execution is missed.
76
75
 
@@ -83,7 +82,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
83
82
  """
84
83
  pass
85
84
 
86
- async def onMaxInstances(self, event: JobMaxInstances, schedule: ISchedule):
85
+ async def onMaxInstances(self, event: JobMaxInstances, schedule):
87
86
  """
88
87
  Called when a job exceeds the maximum allowed instances.
89
88
 
@@ -96,7 +95,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
96
95
  """
97
96
  pass
98
97
 
99
- async def onPaused(self, event: JobPause, schedule: ISchedule):
98
+ async def onPaused(self, event: JobPause, schedule):
100
99
  """
101
100
  Called when the scheduler is paused.
102
101
 
@@ -109,7 +108,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
109
108
  """
110
109
  pass
111
110
 
112
- async def onResumed(self, event: JobResume, schedule: ISchedule):
111
+ async def onResumed(self, event: JobResume, schedule):
113
112
  """
114
113
  Called when the scheduler is resumed.
115
114
 
@@ -122,7 +121,7 @@ class BaseScheduleEventListener(IScheduleEventListener):
122
121
  """
123
122
  pass
124
123
 
125
- async def onRemoved(self, event: JobRemoved, schedule: ISchedule):
124
+ async def onRemoved(self, event: JobRemoved, schedule):
126
125
  """
127
126
  Called when a job is removed from the scheduler.
128
127
 
@@ -38,7 +38,7 @@ class ScheduleListCommand(BaseCommand):
38
38
  # Command description
39
39
  description: str = "Executes the scheduled tasks defined in the application."
40
40
 
41
- def handle(self, app: IApplication, console: Console) -> bool:
41
+ async def handle(self, app: IApplication, console: Console) -> bool:
42
42
  """
43
43
  Displays a table of scheduled jobs defined in the application.
44
44
 
@@ -64,13 +64,13 @@ class ScheduleListCommand(BaseCommand):
64
64
  try:
65
65
 
66
66
  # Retrieve the Scheduler instance from the application
67
- Scheduler = app.getScheduler()
67
+ scheduler = app.getScheduler()
68
68
 
69
69
  # Create an instance of the ISchedule service
70
70
  schedule_service: ISchedule = app.make(ISchedule)
71
71
 
72
72
  # Register scheduled tasks using the Scheduler's tasks method
73
- Scheduler.tasks(schedule_service)
73
+ await scheduler.tasks(schedule_service)
74
74
 
75
75
  # Retrieve the list of scheduled jobs/events
76
76
  list_tasks = schedule_service.events()
@@ -1,14 +1,11 @@
1
1
  from datetime import datetime
2
2
  from rich.console import Console
3
3
  from rich.panel import Panel
4
- from rich.text import Text
5
4
  from orionis.console.base.command import BaseCommand
6
5
  from orionis.console.contracts.schedule import ISchedule
7
6
  from orionis.console.enums.listener import ListeningEvent
8
7
  from orionis.console.exceptions import CLIOrionisRuntimeError
9
- from orionis.container.exceptions.exception import OrionisContainerException
10
8
  from orionis.foundation.contracts.application import IApplication
11
- from orionis.foundation.exceptions.runtime import OrionisRuntimeError
12
9
 
13
10
  class ScheduleWorkCommand(BaseCommand):
14
11
  """
@@ -94,33 +91,39 @@ class ScheduleWorkCommand(BaseCommand):
94
91
  return True
95
92
 
96
93
  # 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)
94
+ if hasattr(scheduler, "onStarted") and callable(scheduler.onStarted):
95
+ schedule_service.setListener(ListeningEvent.SCHEDULER_STARTED, scheduler.onStarted)
99
96
 
100
97
  # If the scheduler has an onPaused method
101
- if hasattr(scheduler, "onPaused"):
102
- schedule_service._setListener(ListeningEvent.SCHEDULER_PAUSED.value, scheduler.onPaused)
98
+ if hasattr(scheduler, "onPaused") and callable(scheduler.onPaused):
99
+ schedule_service.setListener(ListeningEvent.SCHEDULER_PAUSED, scheduler.onPaused)
103
100
 
104
101
  # If the scheduler has an onResumed method
105
- if hasattr(scheduler, "onResumed"):
106
- schedule_service._setListener(ListeningEvent.SCHEDULER_RESUMED.value, scheduler.onResumed)
102
+ if hasattr(scheduler, "onResumed") and callable(scheduler.onResumed):
103
+ schedule_service.setListener(ListeningEvent.SCHEDULER_RESUMED, scheduler.onResumed)
107
104
 
108
105
  # If the scheduler has an onFinalized method
109
- if hasattr(scheduler, "onFinalized"):
110
- schedule_service._setListener(ListeningEvent.SCHEDULER_SHUTDOWN.value, scheduler.onFinalized)
106
+ if hasattr(scheduler, "onFinalized") and callable(scheduler.onFinalized):
107
+ schedule_service.setListener(ListeningEvent.SCHEDULER_SHUTDOWN, scheduler.onFinalized)
111
108
 
112
109
  # If the scheduler has an onError method
113
- if hasattr(scheduler, "onError"):
114
- schedule_service._setListener(ListeningEvent.SCHEDULER_ERROR.value, scheduler.onError)
110
+ if hasattr(scheduler, "onError") and callable(scheduler.onError):
111
+ schedule_service.setListener(ListeningEvent.SCHEDULER_ERROR, scheduler.onError)
115
112
 
116
113
  # Check if the scheduler has specific pause, resume, and finalize times
117
- if hasattr(scheduler, "PAUSE_AT") and isinstance(scheduler.PAUSE_AT, datetime):
114
+ if hasattr(scheduler, "PAUSE_AT") and scheduler.PAUSE_AT is not None:
115
+ if not isinstance(scheduler.PAUSE_AT, datetime):
116
+ raise CLIOrionisRuntimeError("PAUSE_AT must be a datetime instance.")
118
117
  schedule_service.pauseEverythingAt(scheduler.PAUSE_AT)
119
118
 
120
- if hasattr(scheduler, "RESUME_AT") and isinstance(scheduler.RESUME_AT, datetime):
119
+ if hasattr(scheduler, "RESUME_AT") and scheduler.RESUME_AT is not None:
120
+ if not isinstance(scheduler.RESUME_AT, datetime):
121
+ raise CLIOrionisRuntimeError("RESUME_AT must be a datetime instance.")
121
122
  schedule_service.resumeEverythingAt(scheduler.RESUME_AT)
122
123
 
123
- if hasattr(scheduler, "FINALIZE_AT") and isinstance(scheduler.FINALIZE_AT, datetime):
124
+ if hasattr(scheduler, "FINALIZE_AT") and scheduler.FINALIZE_AT is not None:
125
+ if not isinstance(scheduler.FINALIZE_AT, datetime):
126
+ raise CLIOrionisRuntimeError("FINALIZE_AT must be a datetime instance.")
124
127
  schedule_service.shutdownEverythingAt(scheduler.FINALIZE_AT)
125
128
 
126
129
  # Start the scheduler worker asynchronously
@@ -1,31 +1,70 @@
1
1
  from abc import ABC, abstractmethod
2
- from typing import List, Optional
2
+ from datetime import datetime
3
+ from typing import List, Optional, Union
4
+ from orionis.console.contracts.schedule_event_listener import IScheduleEventListener
5
+ from orionis.console.enums.listener import ListeningEvent
3
6
  from orionis.console.tasks.event import Event
4
7
 
5
8
  class ISchedule(ABC):
6
9
 
7
10
  @abstractmethod
8
- def _setListener(
11
+ def command(
9
12
  self,
10
- event: str,
11
- listener: callable
13
+ signature: str,
14
+ args: Optional[List[str]] = None
15
+ ) -> 'Event':
16
+ """
17
+ Prepare an Event instance for a given command signature and its arguments.
18
+
19
+ This method validates the provided command signature and arguments, ensuring
20
+ that the command exists among the registered commands and that the arguments
21
+ are in the correct format. If validation passes, it creates and returns an
22
+ Event object representing the scheduled command, including its signature,
23
+ arguments, and description.
24
+
25
+ Parameters
26
+ ----------
27
+ signature : str
28
+ The unique signature identifying the command to be scheduled. Must be a non-empty string.
29
+ args : Optional[List[str]], optional
30
+ A list of string arguments to be passed to the command. Defaults to None.
31
+
32
+ Returns
33
+ -------
34
+ Event
35
+ An Event instance containing the command signature, arguments, and its description.
36
+
37
+ Raises
38
+ ------
39
+ ValueError
40
+ If the command signature is not a non-empty string, if the arguments are not a list
41
+ of strings or None, or if the command does not exist among the registered commands.
42
+ """
43
+ pass
44
+
45
+ @abstractmethod
46
+ def setListener(
47
+ self,
48
+ event: Union[str, ListeningEvent],
49
+ listener: Union[IScheduleEventListener, callable]
12
50
  ) -> None:
13
51
  """
14
52
  Register a listener callback for a specific scheduler event.
15
53
 
16
- This method allows the registration of a callable listener function that will be
17
- invoked when the specified scheduler event occurs. The event can be one of the
18
- predefined global events or a specific job ID. The listener must be a callable
19
- function that accepts a single argument, which will be the event object.
54
+ This method registers a listener function or an instance of IScheduleEventListener
55
+ to be invoked when the specified scheduler event occurs. The event can be a global
56
+ event name (e.g., 'scheduler_started') or a specific job ID. The listener must be
57
+ callable and should accept the event object as a parameter.
20
58
 
21
59
  Parameters
22
60
  ----------
23
61
  event : str
24
62
  The name of the event to listen for. This can be a global event name (e.g., 'scheduler_started')
25
63
  or a specific job ID.
26
- listener : callable
27
- A callable function that will be invoked when the specified event occurs.
28
- The function should accept one parameter, which will be the event object.
64
+ listener : IScheduleEventListener or callable
65
+ A callable function or an instance of IScheduleEventListener that will be invoked
66
+ when the specified event occurs. The listener should accept one parameter, which
67
+ will be the event object.
29
68
 
30
69
  Returns
31
70
  -------
@@ -35,41 +74,101 @@ class ISchedule(ABC):
35
74
  Raises
36
75
  ------
37
76
  ValueError
38
- If the event name is not a non-empty string or if the listener is not callable.
77
+ If the event name is not a non-empty string or if the listener is not callable
78
+ or an instance of IScheduleEventListener.
39
79
  """
80
+ pass
40
81
 
41
82
  @abstractmethod
42
- def command(
83
+ def pauseEverythingAt(
43
84
  self,
44
- signature: str,
45
- args: Optional[List[str]] = None
46
- ) -> 'Event':
85
+ at: datetime
86
+ ) -> None:
47
87
  """
48
- Prepare an Event instance for a given command signature and its arguments.
88
+ Schedule the scheduler to pause all operations at a specific datetime.
49
89
 
50
- This method validates the provided command signature and arguments, ensuring
51
- that the command exists among the registered commands and that the arguments
52
- are in the correct format. If validation passes, it creates and returns an
53
- Event object representing the scheduled command, including its signature,
54
- arguments, and description.
90
+ This method allows you to schedule a job that will pause the AsyncIOScheduler
91
+ at the specified datetime. The job is added to the scheduler with a 'date'
92
+ trigger, ensuring it executes exactly at the given time.
55
93
 
56
94
  Parameters
57
95
  ----------
58
- signature : str
59
- The unique signature identifying the command to be scheduled. Must be a non-empty string.
60
- args : Optional[List[str]], optional
61
- A list of string arguments to be passed to the command. Defaults to None.
96
+ at : datetime
97
+ The datetime at which the scheduler should be paused. Must be a valid
98
+ datetime object.
62
99
 
63
100
  Returns
64
101
  -------
65
- Event
66
- An Event instance containing the command signature, arguments, and its description.
102
+ None
103
+ This method does not return any value. It schedules a job to pause the
104
+ scheduler at the specified datetime.
67
105
 
68
106
  Raises
69
107
  ------
70
108
  ValueError
71
- If the command signature is not a non-empty string, if the arguments are not a list
72
- of strings or None, or if the command does not exist among the registered commands.
109
+ If the 'at' parameter is not a valid datetime object.
110
+ """
111
+ pass
112
+
113
+ @abstractmethod
114
+ def resumeEverythingAt(
115
+ self,
116
+ at: datetime
117
+ ) -> None:
118
+ """
119
+ Schedule the scheduler to resume all operations at a specific datetime.
120
+
121
+ This method allows you to schedule a job that will resume the AsyncIOScheduler
122
+ at the specified datetime. The job is added to the scheduler with a 'date'
123
+ trigger, ensuring it executes exactly at the given time.
124
+
125
+ Parameters
126
+ ----------
127
+ at : datetime
128
+ The datetime at which the scheduler should be resumed. Must be a valid
129
+ datetime object.
130
+
131
+ Returns
132
+ -------
133
+ None
134
+ This method does not return any value. It schedules a job to resume the
135
+ scheduler at the specified datetime.
136
+
137
+ Raises
138
+ ------
139
+ ValueError
140
+ If the 'at' parameter is not a valid datetime object.
141
+ """
142
+ pass
143
+
144
+ @abstractmethod
145
+ def shutdownEverythingAt(
146
+ self,
147
+ at: datetime
148
+ ) -> None:
149
+ """
150
+ Schedule the scheduler to shut down all operations at a specific datetime.
151
+
152
+ This method allows you to schedule a job that will shut down the AsyncIOScheduler
153
+ at the specified datetime. The job is added to the scheduler with a 'date'
154
+ trigger, ensuring it executes exactly at the given time.
155
+
156
+ Parameters
157
+ ----------
158
+ at : datetime
159
+ The datetime at which the scheduler should be shut down. Must be a valid
160
+ datetime object.
161
+
162
+ Returns
163
+ -------
164
+ None
165
+ This method does not return any value. It schedules a job to shut down the
166
+ scheduler at the specified datetime.
167
+
168
+ Raises
169
+ ------
170
+ ValueError
171
+ If the 'at' parameter is not a valid datetime object.
73
172
  """
74
173
  pass
75
174
 
@@ -94,45 +193,112 @@ class ISchedule(ABC):
94
193
  """
95
194
  Shut down the AsyncIO scheduler instance asynchronously.
96
195
 
97
- This method gracefully stops the AsyncIOScheduler that handles asynchronous job execution.
98
- Using async ensures proper cleanup in asyncio environments.
196
+ This method gracefully stops the AsyncIOScheduler that manages asynchronous job execution.
197
+ It ensures proper cleanup in asyncio environments and allows for an optional wait period
198
+ to complete currently executing jobs before shutting down.
99
199
 
100
200
  Parameters
101
201
  ----------
102
202
  wait : bool, optional
103
- If True, the method will wait until all currently executing jobs are completed before shutting down the scheduler.
104
- If False, the scheduler will be shut down immediately without waiting for running jobs to finish. Default is True.
203
+ If True, the method waits until all currently executing jobs are completed before shutting down the scheduler.
204
+ If False, the scheduler shuts down immediately without waiting for running jobs to finish. Default is True.
105
205
 
106
206
  Returns
107
207
  -------
108
208
  None
109
- This method does not return any value. It shuts down the AsyncIO scheduler.
209
+ This method does not return any value. It performs the shutdown operation for the AsyncIO scheduler.
210
+
211
+ Raises
212
+ ------
213
+ ValueError
214
+ If the 'wait' parameter is not a boolean value.
215
+ CLIOrionisRuntimeError
216
+ If an error occurs during the shutdown process.
110
217
  """
111
218
  pass
112
219
 
113
220
  @abstractmethod
114
- async def remove(self, signature: str) -> bool:
221
+ def pause(self, signature: str) -> bool:
115
222
  """
116
- Remove a scheduled job from the AsyncIO scheduler asynchronously.
223
+ Pause a scheduled job in the AsyncIO scheduler.
117
224
 
118
- This method removes a job with the specified signature from both the internal
119
- jobs dictionary and the AsyncIOScheduler instance. Using async ensures proper
120
- cleanup in asyncio environments.
225
+ This method pauses a job in the AsyncIOScheduler identified by its unique signature.
226
+ It validates the provided signature to ensure it is a non-empty string and attempts
227
+ to pause the job. If the operation is successful, it logs the action and returns True.
228
+ If the job cannot be paused (e.g., it does not exist), the method returns False.
121
229
 
122
230
  Parameters
123
231
  ----------
124
232
  signature : str
125
- The signature of the command/job to remove from the scheduler.
233
+ The unique signature (ID) of the job to pause. This must be a non-empty string.
126
234
 
127
235
  Returns
128
236
  -------
129
237
  bool
130
- Returns True if the job was successfully removed, False if the job was not found.
238
+ True if the job was successfully paused.
239
+ False if the job does not exist or an error occurred.
131
240
 
132
241
  Raises
133
242
  ------
134
- ValueError
135
- If the signature is not a non-empty string.
243
+ CLIOrionisValueError
244
+ If the `signature` parameter is not a non-empty string.
245
+ """
246
+ pass
247
+
248
+ @abstractmethod
249
+ def resume(self, signature: str) -> bool:
250
+ """
251
+ Resume a paused job in the AsyncIO scheduler.
252
+
253
+ This method attempts to resume a job that was previously paused in the AsyncIOScheduler.
254
+ It validates the provided job signature, ensures it is a non-empty string, and then
255
+ resumes the job if it exists and is currently paused. If the operation is successful,
256
+ it logs the action and returns True. If the job cannot be resumed (e.g., it does not exist),
257
+ the method returns False.
258
+
259
+ Parameters
260
+ ----------
261
+ signature : str
262
+ The unique signature (ID) of the job to resume. This must be a non-empty string.
263
+
264
+ Returns
265
+ -------
266
+ bool
267
+ True if the job was successfully resumed, False if the job does not exist or an error occurred.
268
+
269
+ Raises
270
+ ------
271
+ CLIOrionisValueError
272
+ If the `signature` parameter is not a non-empty string.
273
+ """
274
+ pass
275
+
276
+ @abstractmethod
277
+ def remove(self, signature: str) -> bool:
278
+ """
279
+ Remove a scheduled job from the AsyncIO scheduler.
280
+
281
+ This method removes a job from the AsyncIOScheduler using its unique signature (ID).
282
+ It validates the provided signature to ensure it is a non-empty string, attempts to
283
+ remove the job from the scheduler, and updates the internal jobs list accordingly.
284
+ If the operation is successful, it logs the action and returns True. If the job
285
+ cannot be removed (e.g., it does not exist), the method returns False.
286
+
287
+ Parameters
288
+ ----------
289
+ signature : str
290
+ The unique signature (ID) of the job to remove. This must be a non-empty string.
291
+
292
+ Returns
293
+ -------
294
+ bool
295
+ True if the job was successfully removed from the scheduler.
296
+ False if the job does not exist or an error occurred.
297
+
298
+ Raises
299
+ ------
300
+ CLIOrionisValueError
301
+ If the `signature` parameter is not a non-empty string.
136
302
  """
137
303
  pass
138
304
 
@@ -1,5 +1,4 @@
1
1
  from abc import ABC, abstractmethod
2
- from typing import TYPE_CHECKING
3
2
  from orionis.console.entities.job_error import JobError
4
3
  from orionis.console.entities.job_executed import JobExecuted
5
4
  from orionis.console.entities.job_max_instances import JobMaxInstances
@@ -9,9 +8,6 @@ from orionis.console.entities.job_removed import JobRemoved
9
8
  from orionis.console.entities.job_resume import JobResume
10
9
  from orionis.console.entities.job_submitted import JobSubmitted
11
10
 
12
- if TYPE_CHECKING:
13
- from orionis.console.contracts.schedule import ISchedule
14
-
15
11
  class IScheduleEventListener(ABC):
16
12
  """
17
13
  Interface for event listeners that handle various stages of event processing.
@@ -85,40 +81,6 @@ class IScheduleEventListener(ABC):
85
81
  # Subclasses must override this method to provide specific behavior.
86
82
  pass
87
83
 
88
- @abstractmethod
89
- async def onSuccess(self, event: JobExecuted, schedule):
90
- """
91
- Handle actions to be performed when an event is successfully processed.
92
-
93
- This method is invoked after an event is processed successfully, allowing
94
- for any follow-up actions, such as logging, notifications, or triggering
95
- dependent tasks. Subclasses should override this method to define custom
96
- behavior for handling successful event processing.
97
-
98
- Parameters
99
- ----------
100
- event : JobExecuted
101
- The event object containing details about the successfully executed job,
102
- such as its status, metadata, and execution results.
103
- schedule : ISchedule
104
- The schedule object associated with the event, providing context about
105
- the scheduling system and its state.
106
-
107
- Returns
108
- -------
109
- None
110
- This method does not return any value.
111
-
112
- Notes
113
- -----
114
- Override this method to implement specific actions or checks that should
115
- occur after an event is successfully processed.
116
- """
117
-
118
- # This is an abstract method, so it does not contain any implementation.
119
- # Subclasses must override this method to provide specific behavior.
120
- pass
121
-
122
84
  @abstractmethod
123
85
  async def onFailure(self, event: JobError, schedule):
124
86
  """