orionis 0.482.0__py3-none-any.whl → 0.483.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.
@@ -0,0 +1,139 @@
1
+ import importlib
2
+ import os
3
+ from pathlib import Path
4
+ from rich.console import Console
5
+ from rich.panel import Panel
6
+ from rich.table import Table
7
+ from orionis.console.base.command import BaseCommand
8
+ from orionis.console.contracts.schedule import ISchedule
9
+ from orionis.console.exceptions import CLIOrionisRuntimeError
10
+ from orionis.foundation.contracts.application import IApplication
11
+
12
+ class ScheduleListCommand(BaseCommand):
13
+ """
14
+ Command class to display usage information for the Orionis CLI.
15
+
16
+ Methods
17
+ -------
18
+ handle(orionis: IApplication, console: Console) -> bool
19
+ Displays a table of scheduled tasks defined in the application.
20
+ Imports the scheduler module, retrieves scheduled jobs, and prints them
21
+ in a formatted table using the rich library.
22
+
23
+ Returns
24
+ -------
25
+ bool
26
+ Returns True if the scheduled jobs are listed successfully or if no jobs are found.
27
+ Raises CLIOrionisRuntimeError if an error occurs during execution.
28
+ """
29
+
30
+ # Indicates whether timestamps will be shown in the command output
31
+ timestamps: bool = False
32
+
33
+ # Command signature and description
34
+ signature: str = "schedule:list"
35
+
36
+ # Command description
37
+ description: str = "Executes the scheduled tasks defined in the application."
38
+
39
+ def handle(self, orionis: IApplication, console: Console) -> bool:
40
+ """
41
+ Displays a table of scheduled jobs defined in the application.
42
+
43
+ This method dynamically imports the scheduler module, retrieves the list of
44
+ scheduled jobs using the ISchedule service, and prints the jobs in a formatted
45
+ table. If no jobs are found, a message is displayed. Handles and reports errors
46
+ encountered during the process.
47
+
48
+ Parameters
49
+ ----------
50
+ orionis : IApplication
51
+ The application instance providing configuration and service resolution.
52
+ console : Console
53
+ The rich Console instance used for output.
54
+
55
+ Returns
56
+ -------
57
+ bool
58
+ Returns True if the scheduled jobs are listed successfully or if no jobs are found.
59
+ Raises CLIOrionisRuntimeError if an error occurs during execution.
60
+ """
61
+
62
+ try:
63
+
64
+ # Get the absolute path of the scheduler from the application configuration
65
+ scheduler_path = orionis.path('console_scheduler')
66
+
67
+ # Get the base path from the current working directory
68
+ base_path = Path(os.getcwd()).resolve()
69
+ scheduler_path = Path(scheduler_path).resolve()
70
+ rel_path = scheduler_path.relative_to(base_path)
71
+
72
+ # Convert the path to a module name (replace separators with dots, remove .py)
73
+ module_name = ".".join(rel_path.with_suffix('').parts)
74
+
75
+ # Dynamically import the scheduler module
76
+ scheduler_module = importlib.import_module(module_name)
77
+
78
+ # Retrieve the Scheduler class from the imported module
79
+ Scheduler = getattr(scheduler_module, "Scheduler", None)
80
+
81
+ # Raise an error if the Scheduler class is not found
82
+ if Scheduler is None:
83
+ raise CLIOrionisRuntimeError(f"Scheduler class not found in module {module_name}")
84
+
85
+ # Retrieve the 'tasks' method from the Scheduler class
86
+ task_method = getattr(Scheduler, "tasks", None)
87
+
88
+ # Raise an error if the 'tasks' method is not found
89
+ if task_method is None:
90
+ raise CLIOrionisRuntimeError(f"Method 'tasks' not found in Scheduler class in module {module_name}")
91
+
92
+ # Create an instance of ISchedule using the application container
93
+ schedule_serice: ISchedule = orionis.make(ISchedule)
94
+
95
+ # Initialize the scheduled tasks by calling the 'tasks' method
96
+ task_method(schedule_serice)
97
+
98
+ # Retrieve the list of scheduled jobs/events
99
+ list_tasks = schedule_serice.events()
100
+
101
+ # Display a message if no scheduled jobs are found
102
+ if not list_tasks:
103
+ console.line()
104
+ console.print(Panel("No scheduled jobs found.", border_style="green"))
105
+ console.line()
106
+ return True
107
+
108
+ # Create and configure a table to display scheduled jobs
109
+ table = Table(title="Scheduled Jobs", show_lines=True)
110
+ table.add_column("Signature", style="cyan", no_wrap=True)
111
+ table.add_column("Arguments", style="magenta")
112
+ table.add_column("Purpose", style="green")
113
+ table.add_column("Random Delay", style="yellow")
114
+ table.add_column("Start Date", style="white")
115
+ table.add_column("End Date", style="white")
116
+ table.add_column("Details", style="dim")
117
+
118
+ # Populate the table with job details
119
+ for job in list_tasks:
120
+ signature = str(job.get("signature", ""))
121
+ args = ", ".join(map(str, job.get("args", [])))
122
+ purpose = str(job.get("purpose", ""))
123
+ random_delay = str(job.get("random_delay", ""))
124
+ start_date = str(job.get("start_date", "")) if job.get("start_date") else "-"
125
+ end_date = str(job.get("end_date", "")) if job.get("end_date") else "-"
126
+ details = str(job.get("details", ""))
127
+
128
+ table.add_row(signature, args, purpose, random_delay, start_date, end_date, details)
129
+
130
+ # Print the table to the console
131
+ console.line()
132
+ console.print(table)
133
+ console.line()
134
+ return True
135
+
136
+ except Exception as exc:
137
+
138
+ # Catch any unexpected exceptions and raise as a CLIOrionisRuntimeError
139
+ raise CLIOrionisRuntimeError(f"An unexpected error occurred while clearing the cache: {exc}")
@@ -1,18 +1,41 @@
1
1
  import importlib
2
2
  import os
3
+ from datetime import datetime
3
4
  from pathlib import Path
5
+ from rich.console import Console
6
+ from rich.panel import Panel
7
+ from rich.text import Text
4
8
  from orionis.console.base.command import BaseCommand
5
9
  from orionis.console.contracts.schedule import ISchedule
6
10
  from orionis.console.exceptions import CLIOrionisRuntimeError
7
11
  from orionis.foundation.contracts.application import IApplication
8
- from rich.console import Console
9
- from rich.panel import Panel
10
- from rich.text import Text
11
- from datetime import datetime
12
12
 
13
13
  class ScheduleWorkCommand(BaseCommand):
14
14
  """
15
- Command class to display usage information for the Orionis CLI.
15
+ Executes the scheduled tasks defined in the application's scheduler.
16
+
17
+ This command dynamically loads the scheduler module specified in the application's configuration,
18
+ retrieves the `Scheduler` class and its `tasks` method, registers the scheduled tasks with the
19
+ ISchedule service, and starts the scheduler worker. It provides user feedback via the console and
20
+ handles errors by raising CLIOrionisRuntimeError exceptions.
21
+
22
+ Parameters
23
+ ----------
24
+ orionis : IApplication
25
+ The application instance providing configuration and service resolution.
26
+ console : Console
27
+ The Rich console instance used for displaying output to the user.
28
+
29
+ Returns
30
+ -------
31
+ bool
32
+ Returns True if the scheduler worker starts successfully. If an error occurs during the process,
33
+ a CLIOrionisRuntimeError is raised.
34
+
35
+ Raises
36
+ ------
37
+ CLIOrionisRuntimeError
38
+ If the scheduler module, class, or tasks method cannot be found, or if any unexpected error occurs.
16
39
  """
17
40
 
18
41
  # Indicates whether timestamps will be shown in the command output
@@ -25,44 +48,66 @@ class ScheduleWorkCommand(BaseCommand):
25
48
  description: str = "Executes the scheduled tasks defined in the application."
26
49
 
27
50
  async def handle(self, orionis: IApplication, console: Console) -> bool:
28
-
51
+ """
52
+ Executes the scheduled tasks defined in the application's scheduler.
53
+
54
+ This method dynamically loads the scheduler module specified in the application's configuration,
55
+ retrieves the `Scheduler` class and its `tasks` method, registers the scheduled tasks with the
56
+ ISchedule service, and starts the scheduler worker. It provides user feedback via the console and
57
+ handles errors by raising CLIOrionisRuntimeError exceptions.
58
+
59
+ Parameters
60
+ ----------
61
+ orionis : IApplication
62
+ The application instance providing configuration and service resolution.
63
+ console : Console
64
+ The Rich console instance used for displaying output to the user.
65
+
66
+ Returns
67
+ -------
68
+ bool
69
+ Returns True if the scheduler worker starts successfully. If an error occurs during the process,
70
+ a CLIOrionisRuntimeError is raised.
71
+
72
+ Raises
73
+ ------
74
+ CLIOrionisRuntimeError
75
+ If the scheduler module, class, or tasks method cannot be found, or if any unexpected error occurs.
76
+ """
29
77
  try:
30
-
31
- # Obtener la ruta absoluta del scheduler desde la configuración de la aplicación
78
+ # Get the absolute path to the scheduler module from the application configuration
32
79
  scheduler_path = orionis.path('console_scheduler')
33
80
 
34
- # Obtener la base path desde la variable de entorno o desde la configuración local
81
+ # Resolve the base path (current working directory)
35
82
  base_path = Path(os.getcwd()).resolve()
36
83
  scheduler_path = Path(scheduler_path).resolve()
84
+
85
+ # Compute the relative path from the base path to the scheduler module
37
86
  rel_path = scheduler_path.relative_to(base_path)
38
87
 
39
- # Reemplazar los separadores por puntos y quitar la extensión .py
88
+ # Convert the relative path to a Python module name (dot notation, no .py extension)
40
89
  module_name = ".".join(rel_path.with_suffix('').parts)
41
90
 
42
- # Importar el módulo del scheduler
91
+ # Dynamically import the scheduler module
43
92
  scheduler_module = importlib.import_module(module_name)
44
93
 
45
- # Obtener la clase Scheduler del módulo importado
94
+ # Retrieve the Scheduler class from the imported module
46
95
  Scheduler = getattr(scheduler_module, "Scheduler", None)
47
-
48
- # Check if the Scheduler class was found
49
96
  if Scheduler is None:
50
97
  raise CLIOrionisRuntimeError(f"Scheduler class not found in module {module_name}")
51
98
 
52
- # Obtener el método tasks de la clase Scheduler
99
+ # Retrieve the 'tasks' method from the Scheduler class
53
100
  task_method = getattr(Scheduler, "tasks", None)
54
-
55
- # Check if the method exists
56
101
  if task_method is None:
57
102
  raise CLIOrionisRuntimeError(f"Method 'tasks' not found in Scheduler class in module {module_name}")
58
103
 
59
- # Crear una instancia de ISchedule
104
+ # Create an instance of the ISchedule service
60
105
  schedule_serice: ISchedule = orionis.make(ISchedule)
61
106
 
62
- # Inicializar el metodo
107
+ # Register scheduled tasks using the Scheduler's tasks method
63
108
  task_method(schedule_serice)
64
109
 
65
- # Display a professional start message for the scheduler worker
110
+ # Display a start message for the scheduler worker
66
111
  console.line()
67
112
  start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
68
113
  panel_content = Text.assemble(
@@ -79,10 +124,10 @@ class ScheduleWorkCommand(BaseCommand):
79
124
  )
80
125
  console.line()
81
126
 
82
- # Iniciar el scheduler
127
+ # Start the scheduler worker asynchronously
83
128
  await schedule_serice.start()
129
+ return True
84
130
 
85
131
  except Exception as exc:
86
-
87
- # Catch any unexpected exceptions and raise as a CLIOrionisRuntimeError
132
+ # Raise any unexpected exceptions as CLIOrionisRuntimeError
88
133
  raise CLIOrionisRuntimeError(f"An unexpected error occurred while clearing the cache: {exc}")
@@ -112,6 +112,7 @@ class Reactor(IReactor):
112
112
  from orionis.console.commands.workflow import WorkFlowGithubCommand
113
113
  from orionis.console.commands.cache import CacheClearCommand
114
114
  from orionis.console.commands.scheduler_work import ScheduleWorkCommand
115
+ from orionis.console.commands.scheduler_list import ScheduleListCommand
115
116
 
116
117
  # List of core command classes to load (extend this list as more core commands are added)
117
118
  core_commands = [
@@ -121,7 +122,8 @@ class Reactor(IReactor):
121
122
  PublisherCommand,
122
123
  WorkFlowGithubCommand,
123
124
  CacheClearCommand,
124
- ScheduleWorkCommand
125
+ ScheduleWorkCommand,
126
+ ScheduleListCommand
125
127
  ]
126
128
 
127
129
  # Iterate through the core command classes and register them
@@ -5,7 +5,7 @@
5
5
  NAME = "orionis"
6
6
 
7
7
  # Current version of the framework
8
- VERSION = "0.482.0"
8
+ VERSION = "0.483.0"
9
9
 
10
10
  # Full name of the author or maintainer of the project
11
11
  AUTHOR = "Raul Mauricio Uñate Castro"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orionis
3
- Version: 0.482.0
3
+ Version: 0.483.0
4
4
  Summary: Orionis Framework – Elegant, Fast, and Powerful.
5
5
  Home-page: https://github.com/orionis-framework/framework
6
6
  Author: Raul Mauricio Uñate Castro
@@ -14,7 +14,8 @@ orionis/console/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
14
14
  orionis/console/commands/cache.py,sha256=8DsYoRzSBLn0P9qkGVItRbo0R6snWBDBg0_Xa7tmVhs,2322
15
15
  orionis/console/commands/help.py,sha256=ooPoenP08ArMAWiL89_oUGD9l1Faen2QjLTG90i4zCQ,3187
16
16
  orionis/console/commands/publisher.py,sha256=FUg-EUzK7LLXsla10ZUZro8V0Z5S-KjmsaSdRHSSGbA,21381
17
- orionis/console/commands/scheduler_work.py,sha256=768TntiL2dguqJ2BlMVR7zEx_xlE71CCDsZ57ZXu9As,3573
17
+ orionis/console/commands/scheduler_list.py,sha256=SXaD1XJFV1bbyjlDuQhlHz2y1kW-VVCxQxuKJMtQRtA,5956
18
+ orionis/console/commands/scheduler_work.py,sha256=cymbGHaLmwv2WtEenZTtm7iNVfs8gG8_oWXU18Jtzd0,5746
18
19
  orionis/console/commands/test.py,sha256=_Tb-I9vabiqhqGeLfRbV5Y1LEVCdhZhBAwoEQZCzQuM,2435
19
20
  orionis/console/commands/version.py,sha256=SUuNDJ40f2uq69OQUmPQXJKaa9Bm_iVRDPmBd7zc1Yc,3658
20
21
  orionis/console/commands/workflow.py,sha256=NYOmjTSvm2o6AE4h9LSTZMFSYPQreNmEJtronyOxaYk,2451
@@ -24,7 +25,7 @@ orionis/console/contracts/kernel.py,sha256=mh4LlhEYHh3FuGZZQ0GBhD6ZLa5YQvaNj2r01
24
25
  orionis/console/contracts/reactor.py,sha256=Xeq7Zrw6WE5MV_XOQfiQEchAFbb6-0TjLpjWOxYW--g,4554
25
26
  orionis/console/contracts/schedule.py,sha256=eGjcOH7kgdf0fWDZRfOFUQsIx4E8G38ayX5JwpkpN8E,4977
26
27
  orionis/console/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
- orionis/console/core/reactor.py,sha256=v_y3LDydBeKmtCfA0rIi8Nicy38DEfflp_zwx2OM7NQ,30257
28
+ orionis/console/core/reactor.py,sha256=XE4VvUPnOSQ_qmkLMYEDfwKaqDZyFxCiVtoSJVqpk_M,30372
28
29
  orionis/console/dumper/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
30
  orionis/console/dumper/dump.py,sha256=CATERiQ6XuIrKQsDaWcVxzTtlAJI9qLJX44fQxEX8ws,22443
30
31
  orionis/console/dumper/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -199,7 +200,7 @@ orionis/foundation/providers/scheduler_provider.py,sha256=72SoixFog9IOE9Ve9Xcfw6
199
200
  orionis/foundation/providers/testing_provider.py,sha256=SrJRpdvcblx9WvX7x9Y3zc7OQfiTf7la0HAJrm2ESlE,3725
200
201
  orionis/foundation/providers/workers_provider.py,sha256=oa_2NIDH6UxZrtuGkkoo_zEoNIMGgJ46vg5CCgAm7wI,3926
201
202
  orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
202
- orionis/metadata/framework.py,sha256=_5YbwWTtix0nrC_iOD_3NIidY-aj0jZHYz4I8YgV7ME,4109
203
+ orionis/metadata/framework.py,sha256=Omguwj98GlVjFh8nCMjYoLHSqVMJ57Duo0GXurO-QLk,4109
203
204
  orionis/metadata/package.py,sha256=k7Yriyp5aUcR-iR8SK2ec_lf0_Cyc-C7JczgXa-I67w,16039
204
205
  orionis/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
205
206
  orionis/services/asynchrony/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -371,7 +372,7 @@ orionis/test/validators/web_report.py,sha256=n9BfzOZz6aEiNTypXcwuWbFRG0OdHNSmCNu
371
372
  orionis/test/validators/workers.py,sha256=rWcdRexINNEmGaO7mnc1MKUxkHKxrTsVuHgbnIfJYgc,1206
372
373
  orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
373
374
  orionis/test/view/render.py,sha256=f-zNhtKSg9R5Njqujbg2l2amAs2-mRVESneLIkWOZjU,4082
374
- orionis-0.482.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
375
+ orionis-0.483.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
375
376
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
376
377
  tests/container/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
377
378
  tests/container/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -518,8 +519,8 @@ tests/testing/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
518
519
  tests/testing/validators/test_testing_validators.py,sha256=WPo5GxTP6xE-Dw3X1vZoqOMpb6HhokjNSbgDsDRDvy4,16588
519
520
  tests/testing/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
520
521
  tests/testing/view/test_render.py,sha256=tnnMBwS0iKUIbogLvu-7Rii50G6Koddp3XT4wgdFEYM,1050
521
- orionis-0.482.0.dist-info/METADATA,sha256=G2omW6axkClb2bZufamTZKGAw4zPQPxlI-QGmAzf_VE,4801
522
- orionis-0.482.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
523
- orionis-0.482.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
524
- orionis-0.482.0.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
525
- orionis-0.482.0.dist-info/RECORD,,
522
+ orionis-0.483.0.dist-info/METADATA,sha256=3XeBNGAmPP22h8aO4LHXJ9ynNTdYmmYjWQzrzLe5KhA,4801
523
+ orionis-0.483.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
524
+ orionis-0.483.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
525
+ orionis-0.483.0.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
526
+ orionis-0.483.0.dist-info/RECORD,,