orionis 0.618.0__py3-none-any.whl → 0.620.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,3 +1,4 @@
1
+ import asyncio
1
2
  from datetime import datetime
2
3
  from rich.console import Console
3
4
  from rich.panel import Panel
@@ -6,6 +7,7 @@ from orionis.console.contracts.schedule import ISchedule
6
7
  from orionis.console.enums.listener import ListeningEvent
7
8
  from orionis.console.exceptions import CLIOrionisRuntimeError
8
9
  from orionis.foundation.contracts.application import IApplication
10
+ from orionis.services.introspection.instances.reflection import ReflectionInstance
9
11
 
10
12
  class ScheduleWorkCommand(BaseCommand):
11
13
  """
@@ -74,11 +76,23 @@ class ScheduleWorkCommand(BaseCommand):
74
76
  # Retrieve the Scheduler instance from the application
75
77
  scheduler = app.getScheduler()
76
78
 
79
+ # Create an instance of ReflectionInstance
80
+ rf_scheduler = ReflectionInstance(scheduler)
81
+
82
+ # If the Scheduler class is not found, raise an error
83
+ if not rf_scheduler.hasMethod("tasks"):
84
+ raise CLIOrionisRuntimeError(
85
+ "The 'tasks' method is not defined in the Scheduler class."
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
+ if asyncio.iscoroutinefunction(scheduler.tasks):
93
+ await scheduler.tasks(schedule_service)
94
+ else:
95
+ scheduler.tasks(schedule_service)
82
96
 
83
97
  # Retrieve the list of scheduled jobs/events
84
98
  list_tasks = schedule_service.events()
@@ -91,25 +105,36 @@ class ScheduleWorkCommand(BaseCommand):
91
105
  return True
92
106
 
93
107
  # If there are scheduled jobs and the scheduler has an onStarted method
94
- if hasattr(scheduler, "onStarted") and callable(scheduler.onStarted):
108
+ if rf_scheduler.hasMethod("onStarted"):
95
109
  schedule_service.setListener(ListeningEvent.SCHEDULER_STARTED, scheduler.onStarted)
96
110
 
97
111
  # If the scheduler has an onPaused method
98
- if hasattr(scheduler, "onPaused") and callable(scheduler.onPaused):
112
+ if rf_scheduler.hasMethod("onPaused"):
99
113
  schedule_service.setListener(ListeningEvent.SCHEDULER_PAUSED, scheduler.onPaused)
100
114
 
101
115
  # If the scheduler has an onResumed method
102
- if hasattr(scheduler, "onResumed") and callable(scheduler.onResumed):
116
+ if rf_scheduler.hasMethod("onResumed"):
103
117
  schedule_service.setListener(ListeningEvent.SCHEDULER_RESUMED, scheduler.onResumed)
104
118
 
105
119
  # If the scheduler has an onFinalized method
106
- if hasattr(scheduler, "onFinalized") and callable(scheduler.onFinalized):
120
+ if rf_scheduler.hasMethod("onFinalized"):
107
121
  schedule_service.setListener(ListeningEvent.SCHEDULER_SHUTDOWN, scheduler.onFinalized)
108
122
 
109
123
  # If the scheduler has an onError method
110
- if hasattr(scheduler, "onError") and callable(scheduler.onError):
124
+ if rf_scheduler.hasMethod("onError"):
111
125
  schedule_service.setListener(ListeningEvent.SCHEDULER_ERROR, scheduler.onError)
112
126
 
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
113
138
  # If the scheduler has FINALIZE_AT and it is not None
114
139
  if hasattr(scheduler, "FINALIZE_AT") and scheduler.FINALIZE_AT is not None:
115
140
  if not isinstance(scheduler.FINALIZE_AT, datetime):
@@ -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
  """
@@ -16,6 +16,7 @@ from orionis.console.exceptions import CLIOrionisTypeError
16
16
  from orionis.console.request.cli_request import CLIRequest
17
17
  from orionis.foundation.contracts.application import IApplication
18
18
  from orionis.services.introspection.concretes.reflection import ReflectionConcrete
19
+ from orionis.services.introspection.instances.reflection import ReflectionInstance
19
20
  from orionis.services.introspection.modules.reflection import ReflectionModule
20
21
  from orionis.services.log.contracts.log_service import ILogger
21
22
  from orionis.support.performance.contracts.counter import IPerformanceCounter
@@ -76,20 +77,6 @@ class Reactor(IReactor):
76
77
  # List to hold fluent command definitions
77
78
  self.__fluent_commands: List[ICommand] = []
78
79
 
79
- # Load core commands immediately upon initialization
80
- self.__loadCoreCommands()
81
- self.__load__core_commands: bool = True
82
-
83
- # Load custom user-defined commands from the project's commands directory
84
- self.__loadCustomCommands()
85
- self.__load__custom_commands: bool = True
86
-
87
- # Flag to track if fluent commands have been loaded
88
- self.__loadFluentCommands()
89
- self.__load_fluent_commands: bool = True
90
-
91
- print("Clase inicializada reactor")
92
-
93
80
  def __loadCommands(self) -> None:
94
81
  """
95
82
  Loads all available commands into the reactor's internal registry.
@@ -126,17 +113,17 @@ class Reactor(IReactor):
126
113
  """
127
114
 
128
115
  # Load core commands if they have not been loaded yet
129
- if not self.__load__core_commands:
116
+ if not hasattr(self, '_Reactor__load__core_commands') or not self.__load__core_commands:
130
117
  self.__loadCoreCommands()
131
118
  self.__load__core_commands = True
132
119
 
133
120
  # Load custom user-defined commands if they have not been loaded yet
134
- if not self.__load__custom_commands:
121
+ if not hasattr(self, '_Reactor__load__custom_commands') or not self.__load__custom_commands:
135
122
  self.__loadCustomCommands()
136
123
  self.__load__custom_commands = True
137
124
 
138
125
  # Load fluent interface commands if they have not been loaded yet
139
- if not self.__load_fluent_commands:
126
+ if not hasattr(self, '_Reactor__load_fluent_commands') or not self.__load_fluent_commands:
140
127
  self.__loadFluentCommands()
141
128
  self.__load_fluent_commands = True
142
129
 
@@ -860,7 +847,10 @@ class Reactor(IReactor):
860
847
 
861
848
  # Inject parsed arguments into the command instance
862
849
  dict_args = self.__parseArgs(command, args)
863
- command_instance.setArguments(dict_args.copy())
850
+
851
+ # Only set arguments if the command instance has a setArguments method
852
+ if ReflectionInstance(command_instance).hasMethod('setArguments'):
853
+ command_instance.setArguments(dict_args.copy())
864
854
 
865
855
  # Inject a scoped CLIRequest instance into the application container for the command's context
866
856
  self.__app.scopedInstance(ICLIRequest, CLIRequest(
@@ -963,7 +953,10 @@ class Reactor(IReactor):
963
953
 
964
954
  # Inject parsed arguments into the command instance
965
955
  dict_args = self.__parseArgs(command, args)
966
- command_instance.setArguments(dict_args.copy())
956
+
957
+ # Only set arguments if the command instance has a setArguments method
958
+ if ReflectionInstance(command_instance).hasMethod('setArguments'):
959
+ command_instance.setArguments(dict_args.copy())
967
960
 
968
961
  # Inject a scoped CLIRequest instance into the application container for the command's context
969
962
  self.__app.scopedInstance(ICLIRequest, CLIRequest(
@@ -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,