orionis 0.619.0__py3-none-any.whl → 0.621.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.
@@ -1,4 +1,3 @@
1
- from datetime import datetime
2
1
  from rich.console import Console
3
2
  from rich.panel import Panel
4
3
  from orionis.console.base.command import BaseCommand
@@ -6,6 +5,7 @@ from orionis.console.contracts.schedule import ISchedule
6
5
  from orionis.console.enums.listener import ListeningEvent
7
6
  from orionis.console.exceptions import CLIOrionisRuntimeError
8
7
  from orionis.foundation.contracts.application import IApplication
8
+ from orionis.services.introspection.instances.reflection import ReflectionInstance
9
9
 
10
10
  class ScheduleWorkCommand(BaseCommand):
11
11
  """
@@ -74,60 +74,57 @@ class ScheduleWorkCommand(BaseCommand):
74
74
  # Retrieve the Scheduler instance from the application
75
75
  scheduler = app.getScheduler()
76
76
 
77
+ # Create an instance of ReflectionInstance
78
+ rf_scheduler = ReflectionInstance(scheduler)
79
+
80
+ # If the Scheduler class does not define the 'tasks' method, raise an error
81
+ if not rf_scheduler.hasMethod("tasks"):
82
+ raise CLIOrionisRuntimeError(
83
+ "The 'tasks' method was not found in the Scheduler class. "
84
+ "Please ensure your Scheduler class defines a 'tasks(self, schedule: ISchedule)' method "
85
+ "to register scheduled tasks."
86
+ )
87
+
77
88
  # Create an instance of the ISchedule service
78
89
  schedule_service: ISchedule = app.make(ISchedule)
79
90
 
80
91
  # Register scheduled tasks using the Scheduler's tasks method
81
- await scheduler.tasks(schedule_service)
92
+ app.call(scheduler, 'tasks', schedule_service)
82
93
 
83
94
  # Retrieve the list of scheduled jobs/events
84
95
  list_tasks = schedule_service.events()
85
96
 
86
97
  # Display a message if no scheduled jobs are found
87
98
  if not list_tasks:
99
+
100
+ # Print a message indicating no scheduled jobs are found
88
101
  console.line()
89
102
  console.print(Panel("No scheduled jobs found.", border_style="green"))
90
103
  console.line()
104
+
105
+ # Return True indicating the command completed successfully
91
106
  return True
92
107
 
93
108
  # If there are scheduled jobs and the scheduler has an onStarted method
94
- if hasattr(scheduler, "onStarted") and callable(scheduler.onStarted):
109
+ if rf_scheduler.hasMethod("onStarted"):
95
110
  schedule_service.setListener(ListeningEvent.SCHEDULER_STARTED, scheduler.onStarted)
96
111
 
97
112
  # If the scheduler has an onPaused method
98
- if hasattr(scheduler, "onPaused") and callable(scheduler.onPaused):
113
+ if rf_scheduler.hasMethod("onPaused"):
99
114
  schedule_service.setListener(ListeningEvent.SCHEDULER_PAUSED, scheduler.onPaused)
100
115
 
101
116
  # If the scheduler has an onResumed method
102
- if hasattr(scheduler, "onResumed") and callable(scheduler.onResumed):
117
+ if rf_scheduler.hasMethod("onResumed"):
103
118
  schedule_service.setListener(ListeningEvent.SCHEDULER_RESUMED, scheduler.onResumed)
104
119
 
105
120
  # If the scheduler has an onFinalized method
106
- if hasattr(scheduler, "onFinalized") and callable(scheduler.onFinalized):
121
+ if rf_scheduler.hasMethod("onFinalized"):
107
122
  schedule_service.setListener(ListeningEvent.SCHEDULER_SHUTDOWN, scheduler.onFinalized)
108
123
 
109
124
  # If the scheduler has an onError method
110
- if hasattr(scheduler, "onError") and callable(scheduler.onError):
125
+ if rf_scheduler.hasMethod("onError"):
111
126
  schedule_service.setListener(ListeningEvent.SCHEDULER_ERROR, scheduler.onError)
112
127
 
113
- # If the scheduler has FINALIZE_AT and it is not None
114
- if hasattr(scheduler, "FINALIZE_AT") and scheduler.FINALIZE_AT is not None:
115
- if not isinstance(scheduler.FINALIZE_AT, datetime):
116
- raise CLIOrionisRuntimeError("FINALIZE_AT must be a datetime instance.")
117
- schedule_service.shutdownEverythingAt(scheduler.FINALIZE_AT)
118
-
119
- # If the scheduler has RESUME_AT and it is not None
120
- if hasattr(scheduler, "RESUME_AT") and scheduler.RESUME_AT is not None:
121
- if not isinstance(scheduler.RESUME_AT, datetime):
122
- raise CLIOrionisRuntimeError("RESUME_AT must be a datetime instance.")
123
- schedule_service.resumeEverythingAt(scheduler.RESUME_AT)
124
-
125
- # If the scheduler has PAUSE_AT and it is not None
126
- if hasattr(scheduler, "PAUSE_AT") and scheduler.PAUSE_AT is not None:
127
- if not isinstance(scheduler.PAUSE_AT, datetime):
128
- raise CLIOrionisRuntimeError("PAUSE_AT must be a datetime instance.")
129
- schedule_service.pauseEverythingAt(scheduler.PAUSE_AT)
130
-
131
128
  # Start the scheduler worker asynchronously
132
129
  await schedule_service.start()
133
130
 
@@ -1,4 +1,5 @@
1
1
  from abc import ABC, abstractmethod
2
+ from orionis.console.entities.command import Command as CommandEntity
2
3
 
3
4
  class ICommand(ABC):
4
5
 
@@ -84,4 +85,21 @@ class ICommand(ABC):
84
85
  If the args parameter is not a list, or if any element in the list
85
86
  is not an instance of CLIArgument.
86
87
  """
88
+ pass
89
+
90
+ @abstractmethod
91
+ def get(self) -> tuple[str, CommandEntity]:
92
+ """
93
+ Retrieve the configured Command entity.
94
+
95
+ This method constructs and returns a Command entity object that encapsulates
96
+ all the configuration details of the command, including its signature, concrete
97
+ class, method, description, arguments, and timestamp setting. The returned
98
+ Command entity can be used for command execution and management.
99
+
100
+ Returns
101
+ -------
102
+ CommandEntity
103
+ A Command entity object containing all the command's configuration details.
104
+ """
87
105
  pass
@@ -80,7 +80,7 @@ class ISchedule(ABC):
80
80
  pass
81
81
 
82
82
  @abstractmethod
83
- def pauseEverythingAt(
83
+ def pause(
84
84
  self,
85
85
  at: datetime
86
86
  ) -> None:
@@ -111,7 +111,7 @@ class ISchedule(ABC):
111
111
  pass
112
112
 
113
113
  @abstractmethod
114
- def resumeEverythingAt(
114
+ def resume(
115
115
  self,
116
116
  at: datetime
117
117
  ) -> None:
@@ -141,37 +141,6 @@ class ISchedule(ABC):
141
141
  """
142
142
  pass
143
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.
172
- """
173
- pass
174
-
175
144
  @abstractmethod
176
145
  async def start(self) -> None:
177
146
  """
@@ -326,57 +295,6 @@ class ISchedule(ABC):
326
295
  """
327
296
  pass
328
297
 
329
- @abstractmethod
330
- def cancelScheduledPause(self) -> bool:
331
- """
332
- Cancel a previously scheduled pause operation.
333
-
334
- This method attempts to remove a job from the scheduler that was set to pause
335
- the scheduler at a specific time. If the job exists, it is removed, and a log entry
336
- is created to indicate the cancellation. If no such job exists, the method returns False.
337
-
338
- Returns
339
- -------
340
- bool
341
- True if the scheduled pause job was successfully cancelled.
342
- False if no pause job was found or an error occurred during the cancellation process.
343
- """
344
- pass
345
-
346
- @abstractmethod
347
- def cancelScheduledResume(self) -> bool:
348
- """
349
- Cancel a previously scheduled resume operation.
350
-
351
- This method attempts to remove a job from the scheduler that was set to resume
352
- the scheduler at a specific time. If the job exists, it is removed, and a log entry
353
- is created to indicate the cancellation. If no such job exists, the method returns False.
354
-
355
- Returns
356
- -------
357
- bool
358
- True if the scheduled resume job was successfully cancelled.
359
- False if no resume job was found or an error occurred during the cancellation process.
360
- """
361
- pass
362
-
363
- @abstractmethod
364
- def cancelScheduledShutdown(self) -> bool:
365
- """
366
- Cancel a previously scheduled shutdown operation.
367
-
368
- This method attempts to remove a job from the scheduler that was set to shut down
369
- the scheduler at a specific time. If the job exists, it is removed, and a log entry
370
- is created to indicate the cancellation. If no such job exists, the method returns False.
371
-
372
- Returns
373
- -------
374
- bool
375
- True if the scheduled shutdown job was successfully cancelled.
376
- False if no shutdown job was found or an error occurred during the cancellation process.
377
- """
378
- pass
379
-
380
298
  @abstractmethod
381
299
  def isRunning(self) -> bool:
382
300
  """
@@ -1,4 +1,5 @@
1
1
  from dataclasses import dataclass
2
+ from datetime import datetime
2
3
  from typing import Optional
3
4
  from orionis.console.entities.scheduler_event_data import SchedulerEventData
4
5
 
@@ -7,16 +8,17 @@ class SchedulerError(SchedulerEventData):
7
8
  """
8
9
  Represents an error event triggered by the scheduler.
9
10
 
10
- This data class extends `SchedulerEventData` and is used to encapsulate
11
- information related to errors that occur during scheduler operations.
12
- It stores the exception that caused the error and the associated traceback
13
- for debugging and logging purposes.
11
+ This data class extends `SchedulerEventData` and encapsulates information about errors
12
+ that occur during scheduler operations. It stores the exception that caused the error,
13
+ the traceback for debugging, and the time the error occurred.
14
14
 
15
15
  Attributes
16
16
  ----------
17
- exception : Optional[BaseException]
17
+ time : str or datetime, optional
18
+ The time when the error occurred. Can be a string or a datetime object.
19
+ exception : BaseException, optional
18
20
  The exception instance that caused the scheduler error, if any.
19
- traceback : Optional[str]
21
+ traceback : str, optional
20
22
  The traceback string providing details about where the error occurred.
21
23
 
22
24
  Returns
@@ -25,6 +27,9 @@ class SchedulerError(SchedulerEventData):
25
27
  An instance containing details about the scheduler error event.
26
28
  """
27
29
 
30
+ # The time when the error occurred (string or datetime)
31
+ time: str | datetime = None
32
+
28
33
  # Exception that caused the scheduler error, if present
29
34
  exception: Optional[BaseException] = None
30
35
 
@@ -3,11 +3,11 @@ from dataclasses import dataclass
3
3
  @dataclass(kw_only=True)
4
4
  class SchedulerEventData:
5
5
  """
6
- Base data structure for scheduler-related events.
6
+ Base data structure for events in the scheduler system.
7
7
 
8
- This class encapsulates information about events that occur within the scheduler system.
9
- It provides a numeric event code to identify the event type and can be extended for
10
- additional context as needed.
8
+ This class serves as a foundational data container for events triggered within the scheduler.
9
+ It holds a numeric event code that uniquely identifies the event type. Subclasses can extend
10
+ this class to include additional event-specific context.
11
11
 
12
12
  Parameters
13
13
  ----------
@@ -17,8 +17,8 @@ class SchedulerEventData:
17
17
  Returns
18
18
  -------
19
19
  SchedulerEventData
20
- An instance of SchedulerEventData containing the event code.
20
+ An instance of SchedulerEventData with the specified event code.
21
21
  """
22
22
 
23
- # Numeric code representing the type of event
23
+ # Numeric code representing the type of event in the scheduler
24
24
  code: int
@@ -1,4 +1,5 @@
1
1
  from dataclasses import dataclass
2
+ from datetime import datetime
2
3
  from orionis.console.entities.scheduler_event_data import SchedulerEventData
3
4
 
4
5
  @dataclass(kw_only=True)
@@ -9,17 +10,24 @@ class SchedulerPaused(SchedulerEventData):
9
10
  This data class extends `SchedulerEventData` and encapsulates information
10
11
  related to the scheduler pause event, such as the time at which the pause occurred.
11
12
 
13
+ Parameters
14
+ ----------
15
+ time : str or datetime, optional
16
+ The time when the scheduler was paused. Can be a string or a `datetime` object.
17
+ Defaults to None.
18
+ (Other parameters are inherited from SchedulerEventData.)
19
+
12
20
  Attributes
13
21
  ----------
14
- time : str
15
- The time when the scheduler was paused, formatted as a string.
22
+ time : str or datetime
23
+ The time when the scheduler was paused.
16
24
  (Other attributes are inherited from SchedulerEventData.)
17
25
 
18
26
  Returns
19
27
  -------
20
28
  SchedulerPaused
21
- An instance of SchedulerPaused containing information about the pause event.
29
+ An instance of `SchedulerPaused` containing information about the pause event.
22
30
  """
23
31
 
24
- # The time when the scheduler was paused
25
- time: str
32
+ # The time when the scheduler was paused; can be a string or datetime object
33
+ time: str | datetime = None
@@ -1,24 +1,25 @@
1
1
  from dataclasses import dataclass
2
+ from datetime import datetime
2
3
  from orionis.console.entities.scheduler_event_data import SchedulerEventData
3
4
 
4
5
  @dataclass(kw_only=True)
5
6
  class SchedulerResumed(SchedulerEventData):
6
7
  """
7
- Represents an event triggered when the scheduler is resumed.
8
+ Represents an event that is triggered when the scheduler is resumed.
8
9
 
9
- This data class extends `SchedulerEventData` and is used to encapsulate
10
+ This data class extends `SchedulerEventData` and encapsulates
10
11
  information about the scheduler's resumption event.
11
12
 
12
13
  Attributes
13
14
  ----------
14
- time : str
15
- The time when the scheduler was resumed.
15
+ time : str or datetime, optional
16
+ The time when the scheduler was resumed. Can be a string or a datetime object.
16
17
 
17
18
  Returns
18
19
  -------
19
20
  SchedulerResumed
20
- An instance containing information about the resumed scheduler event.
21
+ An instance of `SchedulerResumed` containing information about the resumed scheduler event.
21
22
  """
22
23
 
23
- # The time when the scheduler was resumed
24
- time: str
24
+ # The time when the scheduler was resumed; can be a string or datetime object
25
+ time: str | datetime = None
@@ -1,4 +1,5 @@
1
- from dataclasses import dataclass, field
1
+ from dataclasses import dataclass
2
+ from datetime import datetime
2
3
  from orionis.console.entities.scheduler_event_data import SchedulerEventData
3
4
 
4
5
  @dataclass(kw_only=True)
@@ -6,26 +7,21 @@ class SchedulerShutdown(SchedulerEventData):
6
7
  """
7
8
  Represents an event triggered when the scheduler shuts down.
8
9
 
9
- This class extends `SchedulerEventData` and is used to encapsulate
10
- information related to the shutdown of the scheduler, such as the
11
- shutdown time and the list of tasks present at shutdown.
10
+ This dataclass extends `SchedulerEventData` and encapsulates information
11
+ related to the shutdown of the scheduler, such as the shutdown time and
12
+ the list of tasks present at shutdown.
12
13
 
13
14
  Attributes
14
15
  ----------
15
- time : str
16
- The time when the scheduler was shut down.
17
- tasks : list
18
- The list of tasks that were scheduled at the time of shutdown.
16
+ time : str or datetime, optional
17
+ The time when the scheduler was shut down. Can be a string or a datetime object.
19
18
 
20
19
  Returns
21
20
  -------
22
21
  SchedulerShutdown
23
- An instance representing the scheduler shutdown event, containing
24
- the shutdown time and the list of scheduled tasks.
22
+ An instance of SchedulerShutdown containing the shutdown time and
23
+ any additional event data inherited from SchedulerEventData.
25
24
  """
26
25
 
27
- # The time when the scheduler was shut down
28
- time: str = ""
29
-
30
- # List of tasks scheduled at the time of shutdown
31
- tasks: list = field(default_factory=list)
26
+ # The time when the scheduler was shut down; can be a string or datetime object
27
+ time: str | datetime = None
@@ -1,4 +1,5 @@
1
- from dataclasses import dataclass, field
1
+ from dataclasses import dataclass
2
+ from datetime import datetime
2
3
  from orionis.console.entities.scheduler_event_data import SchedulerEventData
3
4
 
4
5
  @dataclass(kw_only=True)
@@ -6,25 +7,21 @@ class SchedulerStarted(SchedulerEventData):
6
7
  """
7
8
  Represents the event data generated when the scheduler starts.
8
9
 
9
- This data class extends `SchedulerEventData` and encapsulates information
10
- about the scheduler's start event, such as the start time and the list of
11
- tasks scheduled at that moment.
10
+ This data class extends `SchedulerEventData` and encapsulates information about the scheduler's
11
+ start event, such as the start time and the list of tasks scheduled at that moment.
12
12
 
13
- Attributes
13
+ Parameters
14
14
  ----------
15
- time : str
16
- The time when the scheduler started.
17
- tasks : list
15
+ time : str or datetime, optional
16
+ The time when the scheduler started. Can be a string or a `datetime` object.
17
+ tasks : list, optional
18
18
  The list of tasks that were scheduled at the time the scheduler started.
19
19
 
20
20
  Returns
21
21
  -------
22
22
  SchedulerStarted
23
- An instance containing the scheduler start event data.
23
+ An instance of `SchedulerStarted` containing the scheduler start event data.
24
24
  """
25
25
 
26
- # The time when the scheduler started
27
- time: str = ""
28
-
29
- # List of tasks scheduled at the time of start
30
- tasks: list = field(default_factory=list)
26
+ # The time when the scheduler started; can be a string or datetime object
27
+ time: str | datetime = None
@@ -1,9 +1,10 @@
1
1
  from typing import Any, Callable
2
2
  from orionis.console.args.argument import CLIArgument
3
+ from orionis.console.contracts.command import ICommand
3
4
  from orionis.console.entities.command import Command as CommandEntity
4
5
  from orionis.services.introspection.concretes.reflection import ReflectionConcrete
5
6
 
6
- class Command:
7
+ class Command(ICommand):
7
8
 
8
9
  def __init__(
9
10
  self,