orionis 0.511.0__py3-none-any.whl → 0.513.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.
Files changed (47) hide show
  1. orionis/console/base/command.py +1 -1
  2. orionis/console/base/scheduler.py +1 -1
  3. orionis/console/base/scheduler_event_listener.py +136 -0
  4. orionis/console/commands/scheduler_work.py +37 -25
  5. orionis/console/contracts/event.py +3032 -9
  6. orionis/console/contracts/schedule.py +34 -0
  7. orionis/console/contracts/schedule_event_listener.py +320 -0
  8. orionis/console/contracts/scheduler.py +140 -0
  9. orionis/console/core/reactor.py +1 -1
  10. orionis/console/entities/all_jobs_removed.py +23 -0
  11. orionis/console/entities/executor_added.py +23 -0
  12. orionis/console/entities/executor_removed.py +25 -0
  13. orionis/console/entities/job_added.py +24 -0
  14. orionis/console/entities/job_error.py +35 -0
  15. orionis/console/entities/job_event_data.py +40 -0
  16. orionis/console/entities/job_executed.py +31 -0
  17. orionis/console/entities/job_max_instances.py +27 -0
  18. orionis/console/entities/job_missed.py +25 -0
  19. orionis/console/entities/job_modified.py +23 -0
  20. orionis/console/entities/job_pause.py +22 -0
  21. orionis/console/entities/job_removed.py +22 -0
  22. orionis/console/entities/job_resume.py +25 -0
  23. orionis/console/entities/job_store_added.py +24 -0
  24. orionis/console/entities/job_store_removed.py +25 -0
  25. orionis/console/entities/job_submitted.py +24 -0
  26. orionis/console/entities/scheduler_event_data.py +33 -0
  27. orionis/console/entities/scheduler_paused.py +17 -0
  28. orionis/console/entities/scheduler_resumed.py +24 -0
  29. orionis/console/entities/scheduler_shutdown.py +23 -0
  30. orionis/console/entities/scheduler_started.py +21 -0
  31. orionis/console/enums/listener.py +75 -0
  32. orionis/console/tasks/event.py +3703 -21
  33. orionis/console/tasks/schedule.py +701 -52
  34. orionis/foundation/application.py +1 -1
  35. orionis/metadata/framework.py +1 -1
  36. {orionis-0.511.0.dist-info → orionis-0.513.0.dist-info}/METADATA +1 -1
  37. {orionis-0.511.0.dist-info → orionis-0.513.0.dist-info}/RECORD +42 -22
  38. orionis/console/base/contracts/__init__.py +0 -0
  39. orionis/console/base/contracts/scheduler.py +0 -38
  40. orionis/console/contracts/listener.py +0 -132
  41. orionis/console/entities/listeners.py +0 -241
  42. orionis/console/tasks/exception_report.py +0 -94
  43. /orionis/console/{base/contracts → contracts}/command.py +0 -0
  44. {orionis-0.511.0.dist-info → orionis-0.513.0.dist-info}/WHEEL +0 -0
  45. {orionis-0.511.0.dist-info → orionis-0.513.0.dist-info}/licenses/LICENCE +0 -0
  46. {orionis-0.511.0.dist-info → orionis-0.513.0.dist-info}/top_level.txt +0 -0
  47. {orionis-0.511.0.dist-info → orionis-0.513.0.dist-info}/zip-safe +0 -0
@@ -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):
@@ -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
- Scheduler = app.getScheduler()
78
+ scheduler = app.getScheduler()
78
79
 
79
80
  # Create an instance of the ISchedule service
80
- schedule_serice: ISchedule = app.make(ISchedule)
81
+ schedule_service: ISchedule = app.make(ISchedule)
81
82
 
82
83
  # Register scheduled tasks using the Scheduler's tasks method
83
- Scheduler.tasks(schedule_serice)
84
+ await scheduler.tasks(schedule_service)
84
85
 
85
86
  # Retrieve the list of scheduled jobs/events
86
- list_tasks = schedule_serice.events()
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
- # Display a start message for the scheduler worker
96
- console.line()
97
- start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
98
- panel_content = Text.assemble(
99
- (" Orionis Scheduler Worker ", "bold white on green"),
100
- ("\n\n", ""),
101
- ("The scheduled tasks worker has started successfully.\n", "white"),
102
- (f"Started at: {start_time}\n", "dim"),
103
- ("To stop the worker, press ", "white"),
104
- ("Ctrl+C", "bold yellow"),
105
- (".", "white")
106
- )
107
- console.print(
108
- Panel(panel_content, border_style="green", padding=(1, 2))
109
- )
110
- console.line()
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 schedule_serice.start()
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}"