fastpluggy-debug-tools 0.0.14__tar.gz

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.

Potentially problematic release.


This version of fastpluggy-debug-tools might be problematic. Click here for more details.

Files changed (38) hide show
  1. fastpluggy_debug_tools-0.0.14/MANIFEST.in +12 -0
  2. fastpluggy_debug_tools-0.0.14/PKG-INFO +12 -0
  3. fastpluggy_debug_tools-0.0.14/fastpluggy_debug_tools.egg-info/PKG-INFO +12 -0
  4. fastpluggy_debug_tools-0.0.14/fastpluggy_debug_tools.egg-info/SOURCES.txt +36 -0
  5. fastpluggy_debug_tools-0.0.14/fastpluggy_debug_tools.egg-info/dependency_links.txt +1 -0
  6. fastpluggy_debug_tools-0.0.14/fastpluggy_debug_tools.egg-info/entry_points.txt +2 -0
  7. fastpluggy_debug_tools-0.0.14/fastpluggy_debug_tools.egg-info/requires.txt +6 -0
  8. fastpluggy_debug_tools-0.0.14/fastpluggy_debug_tools.egg-info/top_level.txt +1 -0
  9. fastpluggy_debug_tools-0.0.14/pyproject.toml +36 -0
  10. fastpluggy_debug_tools-0.0.14/setup.cfg +4 -0
  11. fastpluggy_debug_tools-0.0.14/src/__init__.py +1 -0
  12. fastpluggy_debug_tools-0.0.14/src/config.py +14 -0
  13. fastpluggy_debug_tools-0.0.14/src/plugin.py +43 -0
  14. fastpluggy_debug_tools-0.0.14/src/requirements_tools.py +89 -0
  15. fastpluggy_debug_tools-0.0.14/src/router/__init__.py +274 -0
  16. fastpluggy_debug_tools-0.0.14/src/router/debug.py +94 -0
  17. fastpluggy_debug_tools-0.0.14/src/router/memory_tools.py +77 -0
  18. fastpluggy_debug_tools-0.0.14/src/router/menu_tools.py +48 -0
  19. fastpluggy_debug_tools-0.0.14/src/router/module_tools.py +70 -0
  20. fastpluggy_debug_tools-0.0.14/src/router/pool_info.py +59 -0
  21. fastpluggy_debug_tools-0.0.14/src/router/psutil_analyzer.py +43 -0
  22. fastpluggy_debug_tools-0.0.14/src/router/requirements.py +42 -0
  23. fastpluggy_debug_tools-0.0.14/src/router/task_thread_tools.py +94 -0
  24. fastpluggy_debug_tools-0.0.14/src/router/websocket_tool.py +46 -0
  25. fastpluggy_debug_tools-0.0.14/src/static/debug.css +0 -0
  26. fastpluggy_debug_tools-0.0.14/src/tasks/__init__.py +0 -0
  27. fastpluggy_debug_tools-0.0.14/src/tasks/locked_tasks.py +26 -0
  28. fastpluggy_debug_tools-0.0.14/src/tasks/progress.py +27 -0
  29. fastpluggy_debug_tools-0.0.14/src/tasks/sample_tasks.py +67 -0
  30. fastpluggy_debug_tools-0.0.14/src/tasks/task_sample.py +53 -0
  31. fastpluggy_debug_tools-0.0.14/src/templates/psutil_analyzer.html.j2 +243 -0
  32. fastpluggy_debug_tools-0.0.14/src/templates/widgets/debug/debug_panel.html.j2 +325 -0
  33. fastpluggy_debug_tools-0.0.14/src/templates/widgets/packages_view.html.j2 +207 -0
  34. fastpluggy_debug_tools-0.0.14/src/widgets/__init__.py +3 -0
  35. fastpluggy_debug_tools-0.0.14/src/widgets/debug/__init__.py +0 -0
  36. fastpluggy_debug_tools-0.0.14/src/widgets/debug/debug_panel.py +308 -0
  37. fastpluggy_debug_tools-0.0.14/src/widgets/packages_view.py +44 -0
  38. fastpluggy_debug_tools-0.0.14/src/widgets/psutil_analyzer.py +33 -0
@@ -0,0 +1,12 @@
1
+ # Include all Python files
2
+ recursive-include src *.py
3
+
4
+ # Include all template files
5
+ recursive-include src/templates *.html *.j2
6
+
7
+ # Include all static files (CSS, JS, etc.)
8
+ recursive-include src/static *
9
+
10
+ # Include README and license files
11
+ include README.md
12
+ include LICENSE
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastpluggy-debug-tools
3
+ Version: 0.0.14
4
+ Summary: Debug Tools plugin for Fastpluggy
5
+ Author: FastPluggy Team
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: FastPluggy>=0.2.50
9
+ Requires-Dist: psutil
10
+ Requires-Dist: packaging
11
+ Provides-Extra: all
12
+ Requires-Dist: pympler; extra == "all"
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastpluggy-debug-tools
3
+ Version: 0.0.14
4
+ Summary: Debug Tools plugin for Fastpluggy
5
+ Author: FastPluggy Team
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: FastPluggy>=0.2.50
9
+ Requires-Dist: psutil
10
+ Requires-Dist: packaging
11
+ Provides-Extra: all
12
+ Requires-Dist: pympler; extra == "all"
@@ -0,0 +1,36 @@
1
+ MANIFEST.in
2
+ pyproject.toml
3
+ fastpluggy_debug_tools.egg-info/PKG-INFO
4
+ fastpluggy_debug_tools.egg-info/SOURCES.txt
5
+ fastpluggy_debug_tools.egg-info/dependency_links.txt
6
+ fastpluggy_debug_tools.egg-info/entry_points.txt
7
+ fastpluggy_debug_tools.egg-info/requires.txt
8
+ fastpluggy_debug_tools.egg-info/top_level.txt
9
+ src/__init__.py
10
+ src/config.py
11
+ src/plugin.py
12
+ src/requirements_tools.py
13
+ src/router/__init__.py
14
+ src/router/debug.py
15
+ src/router/memory_tools.py
16
+ src/router/menu_tools.py
17
+ src/router/module_tools.py
18
+ src/router/pool_info.py
19
+ src/router/psutil_analyzer.py
20
+ src/router/requirements.py
21
+ src/router/task_thread_tools.py
22
+ src/router/websocket_tool.py
23
+ src/static/debug.css
24
+ src/tasks/__init__.py
25
+ src/tasks/locked_tasks.py
26
+ src/tasks/progress.py
27
+ src/tasks/sample_tasks.py
28
+ src/tasks/task_sample.py
29
+ src/templates/psutil_analyzer.html.j2
30
+ src/templates/widgets/packages_view.html.j2
31
+ src/templates/widgets/debug/debug_panel.html.j2
32
+ src/widgets/__init__.py
33
+ src/widgets/packages_view.py
34
+ src/widgets/psutil_analyzer.py
35
+ src/widgets/debug/__init__.py
36
+ src/widgets/debug/debug_panel.py
@@ -0,0 +1,2 @@
1
+ [fastpluggy.plugins]
2
+ debug_tools = fastpluggy_plugin.debug_tools.plugin:DebugToolsPlugin
@@ -0,0 +1,6 @@
1
+ FastPluggy>=0.2.50
2
+ psutil
3
+ packaging
4
+
5
+ [all]
6
+ pympler
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "fastpluggy-debug-tools"
3
+ version = "0.0.14"
4
+ description = "Debug Tools plugin for Fastpluggy"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ authors = [
8
+ {name = "FastPluggy Team"}
9
+ ]
10
+ dependencies = [
11
+ "FastPluggy>=0.2.50",
12
+ "psutil",
13
+ "packaging"
14
+ ]
15
+
16
+ [project.optional-dependencies]
17
+ all = [
18
+ "pympler",
19
+ ]
20
+
21
+ [tool.setuptools]
22
+ packages = ["fastpluggy_plugin.debug_tools"]
23
+ package-dir = { "fastpluggy_plugin.debug_tools" = "src" }
24
+ include-package-data = true
25
+
26
+ [tool.setuptools.package-data]
27
+ "fastpluggy_plugin.debug_tools" = ["**/*", "templates/**/*.html", "templates/**/*.j2", "static/**/*"]
28
+
29
+ [project.entry-points."fastpluggy.plugins"]
30
+ debug_tools = "fastpluggy_plugin.debug_tools.plugin:DebugToolsPlugin"
31
+
32
+
33
+
34
+ [tool.fastpluggy]
35
+ category = ['debug']
36
+ keywords = ['debug',]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .plugin import DebugToolsPlugin
@@ -0,0 +1,14 @@
1
+ from fastpluggy.core.config import BaseDatabaseSettings
2
+ from typing import Optional
3
+
4
+
5
+ class DebugToolsConfig(BaseDatabaseSettings):
6
+ # Enable/disable the Debug Panel Widget
7
+ show_debug_panel_widget: Optional[bool] = True
8
+
9
+ # Additional debug panel widget configuration options
10
+ debug_panel_max_depth: Optional[int] = 10
11
+ debug_panel_show_attributes: Optional[bool] = True
12
+ debug_panel_show_warnings: Optional[bool] = True
13
+ debug_panel_show_context: Optional[bool] = True
14
+ debug_panel_auto_expand: Optional[bool] = False
@@ -0,0 +1,43 @@
1
+ # plugin.py
2
+ from typing import Any, Annotated
3
+
4
+ from fastpluggy.core.global_registry import GlobalRegistry
5
+ from fastpluggy.core.module_base import FastPluggyBaseModule
6
+ from fastpluggy.core.tools.inspect_tools import InjectDependency
7
+ from fastpluggy.core.tools.install import is_installed
8
+ from fastpluggy.fastpluggy import FastPluggy
9
+
10
+
11
+ def get_debug_router():
12
+ from .router import debug_plugin_router
13
+ return debug_plugin_router
14
+
15
+
16
+ class DebugToolsPlugin(FastPluggyBaseModule):
17
+ module_name: str = "debug_tools"
18
+
19
+ module_menu_name: str = "Debug Tools"
20
+ module_menu_icon: str = "fas fa-tools"
21
+ module_menu_type: str = "admin"
22
+
23
+ module_router: Any = get_debug_router
24
+
25
+ def on_load_complete(self,
26
+ fast_pluggy: Annotated[FastPluggy, InjectDependency],
27
+ plugin: Annotated["PluginState", InjectDependency],
28
+ ) -> None:
29
+
30
+ if not is_installed('pympler'):
31
+ plugin.add_warning("pympler is not installed. Debug tools will not be available.")
32
+
33
+ from .widgets.debug.debug_panel import DebugPanelWidget
34
+ GlobalRegistry.extend_globals('list_widget_to_inject', items=[{
35
+ 'widget': DebugPanelWidget,
36
+ 'position': 0,
37
+ 'kwargs': {
38
+ 'inject_context': True,
39
+ },
40
+ 'tag': '#ROOT#'
41
+ }])
42
+
43
+
@@ -0,0 +1,89 @@
1
+ import os
2
+ from importlib.metadata import distributions
3
+ from typing import List
4
+
5
+ from loguru import logger
6
+ from packaging.requirements import Requirement
7
+ from packaging.version import Version
8
+
9
+ from fastpluggy.core.plugin_state import PluginState
10
+
11
+
12
+ def get_requirements_files(plugins_state: dict[str, PluginState]) -> List[str]:
13
+ """
14
+ Returns a list of requirements.txt file paths for enabled and loaded plugins.
15
+ """
16
+ requirements_files = []
17
+ for plugin in plugins_state.values():
18
+ if plugin.initialized :#and plugin.loaded:
19
+ req_path = os.path.join(plugin.path, "requirements.txt")
20
+ if os.path.isfile(req_path):
21
+ requirements_files.append(req_path)
22
+ return requirements_files
23
+
24
+
25
+ def get_installed_packages():
26
+ """
27
+ Returns a dictionary of installed packages with their metadata.
28
+ """
29
+ packages = {}
30
+ for dist in distributions():
31
+ name = dist.metadata["Name"]
32
+ packages[name.lower()] = {
33
+ "name": name,
34
+ "version": dist.version,
35
+ "summary": dist.metadata.get("Summary", ""),
36
+ "author": dist.metadata.get("Author", ""),
37
+ "home_page": dist.metadata.get("Home-page", ""),
38
+ }
39
+ return packages
40
+
41
+
42
+ def get_installed_packages_simple():
43
+ """
44
+ Returns a simple dictionary of installed packages (name: version).
45
+ Used for compatibility with existing code.
46
+ """
47
+ return {dist.metadata["Name"].lower(): dist.version for dist in distributions()}
48
+
49
+
50
+ def check_requirements_file(requirements_file: str) -> list[tuple[str, str | None, str]]:
51
+ """
52
+ Checks a requirements.txt file and returns a list of missing or incompatible packages.
53
+ Returns a list of (package_name, installed_version, required_specifier).
54
+ """
55
+ if not os.path.exists(requirements_file):
56
+ logger.warning(f"Requirements file not found: {requirements_file}")
57
+ return []
58
+
59
+ missing = []
60
+ installed = get_installed_packages_simple()
61
+
62
+ with open(requirements_file) as f:
63
+ lines = [line.strip() for line in f if line.strip() and not line.startswith("#")]
64
+
65
+ for line in lines:
66
+ try:
67
+ req = Requirement(line)
68
+ name = req.name.lower()
69
+ installed_version = installed.get(name)
70
+ if not installed_version:
71
+ missing.append((req.name, None, str(req.specifier)))
72
+ else:
73
+ if not req.specifier.contains(Version(installed_version), prereleases=True):
74
+ missing.append((req.name, installed_version, str(req.specifier)))
75
+ except Exception as e:
76
+ logger.error(f"Error parsing requirement line '{line}': {e}")
77
+ missing.append((line, "ERROR", "PARSE"))
78
+
79
+ return missing
80
+
81
+ def check_multiple_requirements_files(files: list[str]) -> dict[str, list[tuple[str, str | None, str]]]:
82
+ report = {}
83
+
84
+ for file in files:
85
+ issues = check_requirements_file(file)
86
+ if issues:
87
+ report[file] = issues
88
+
89
+ return report
@@ -0,0 +1,274 @@
1
+ # src/plugins/debug_plugin/router.py
2
+
3
+ import os
4
+ import sys
5
+
6
+ from fastapi import APIRouter, Request, Depends
7
+ from fastapi.responses import HTMLResponse
8
+ from fastapi.routing import APIRoute
9
+
10
+ from fastpluggy.core.auth import require_authentication
11
+ from fastpluggy.core.database import Base
12
+ from fastpluggy.core.dependency import get_view_builder, get_fastpluggy
13
+ from fastpluggy.core.tools.fastapi import _extract_route_metadata
14
+ from fastpluggy.core.tools.install import is_installed
15
+ from fastpluggy.core.widgets.render_field_tools import RenderFieldTools
16
+ from fastpluggy.core.view_builer.components.table import TableView
17
+ from fastpluggy.core.widgets import TableWidget
18
+ from fastpluggy.core.widgets.categories.data.debug import DebugView
19
+ from fastpluggy.core.widgets.categories.input.button import AutoLinkWidget
20
+ from fastpluggy.core.widgets.categories.input.button_list import ButtonListWidget
21
+ from .menu_tools import menu_debug_router
22
+ from .module_tools import debug_module_router
23
+ from .pool_info import pool_router
24
+ from .psutil_analyzer import psutil_analyzer_router
25
+ from .requirements import requirements_router
26
+ from .task_thread_tools import task_thread_tools_router
27
+ from ..router.websocket_tool import websocket_notification_button
28
+
29
+ debug_plugin_router = APIRouter()
30
+ debug_plugin_router.include_router(menu_debug_router)
31
+ debug_plugin_router.include_router(debug_module_router)
32
+ debug_plugin_router.include_router(pool_router)
33
+ debug_plugin_router.include_router(psutil_analyzer_router)
34
+ debug_plugin_router.include_router(requirements_router)
35
+ debug_plugin_router.include_router(task_thread_tools_router)
36
+
37
+ if is_installed('pympler'):
38
+ from .memory_tools import menu_memory_router
39
+ debug_plugin_router.include_router(menu_memory_router)
40
+
41
+
42
+ @debug_plugin_router.get("/", response_class=HTMLResponse)
43
+ def list_tools(
44
+ request: Request,
45
+ view_builder=Depends(get_view_builder)
46
+ ):
47
+ """
48
+ Main debug tools page listing available debug functions as buttons.
49
+ """
50
+ return view_builder.generate(
51
+ request,
52
+ widgets=[
53
+ ButtonListWidget(
54
+ buttons=[
55
+ AutoLinkWidget(route_name="list_tables", label="List Database Tables"),
56
+ AutoLinkWidget(route_name="list_env_vars", label="List Environment Variables"),
57
+ AutoLinkWidget(route_name="route_no_auth", label="List routes (with no auth,conflict)"),
58
+ AutoLinkWidget(route_name="list_session"),
59
+ AutoLinkWidget(route_name="pool_info"),
60
+ AutoLinkWidget(route_name="list_jinja2_templates", label="List Jinja2 Templates"),
61
+ ]
62
+ ),
63
+ ButtonListWidget(
64
+ title="Menu & Menu Entry",
65
+ buttons=[
66
+ AutoLinkWidget(route_name="list_menu", label="List menu"),
67
+ AutoLinkWidget(route_name="list_menu_entry", label="List _menu_entry "),
68
+ ],
69
+ ),
70
+ ButtonListWidget(
71
+ title="Modules",
72
+ buttons=[
73
+ AutoLinkWidget(route_name="list_modules_dependencies", label="Modules Dependencies"),
74
+ AutoLinkWidget(route_name="list_requirements", label="Modules requirements.txt"),
75
+ AutoLinkWidget(route_name="list_modules_package", label="Modules installed as package"),
76
+ ],
77
+ ),
78
+ ButtonListWidget(
79
+ title="WebSocket",
80
+ buttons=[websocket_notification_button(request=request)],
81
+ ),
82
+ ButtonListWidget(
83
+ buttons=[
84
+ AutoLinkWidget(route_name="list_global_registry"),
85
+ ]
86
+ ),
87
+ ButtonListWidget(
88
+ title="Threads & Coroutines",
89
+ buttons=[
90
+ AutoLinkWidget(route_name="list_all_tasks"),
91
+ AutoLinkWidget(route_name="psutil_analyzer_dashboard", label="PSUtil Memory Analyzer"),
92
+ ]
93
+ ),
94
+ ]
95
+ )
96
+
97
+
98
+ @debug_plugin_router.get("/list_tables", response_class=HTMLResponse, name="list_tables")
99
+ def list_tables(
100
+ request: Request,
101
+ view_builder=Depends(get_view_builder)
102
+ ):
103
+ """
104
+ Endpoint to list all database tables.
105
+ """
106
+ data = [{"table_name": table} for table in Base.metadata.tables.keys()]
107
+ return view_builder.generate(
108
+ request,
109
+ widgets=[
110
+ TableWidget(
111
+ data=data,
112
+ title="Database Tables"
113
+ )
114
+ ]
115
+ )
116
+
117
+
118
+ @debug_plugin_router.get("/list_modules", response_class=HTMLResponse, name="list_modules")
119
+ def list_modules(
120
+ request: Request,
121
+ view_builder=Depends(get_view_builder)
122
+ ):
123
+ """
124
+ Endpoint to list all loaded Python modules.
125
+ """
126
+ modules_info = [
127
+ {
128
+ "module_name": name,
129
+ "file_path": getattr(module, "__file__", "N/A"),
130
+ "package": getattr(module, "__package__", "N/A"),
131
+ "built_in": "yes" if name in sys.builtin_module_names else "no",
132
+ }
133
+ for name, module in sys.modules.items()
134
+ ]
135
+ return view_builder.generate(
136
+ request,
137
+ widgets=[
138
+ TableView(
139
+ data=modules_info,
140
+ title="Loaded Modules"
141
+ )
142
+ ]
143
+ )
144
+
145
+
146
+ @debug_plugin_router.get("/list_env_vars", response_class=HTMLResponse, name="list_env_vars")
147
+ def list_env_vars(
148
+ request: Request,
149
+ view_builder=Depends(get_view_builder)
150
+ ):
151
+ """
152
+ Endpoint to list all environment variables.
153
+ """
154
+ env_vars = [{"key": key, "value": value} for key, value in os.environ.items()]
155
+ return view_builder.generate(
156
+ request,
157
+ widgets=[
158
+ TableView(
159
+ data=env_vars,
160
+ title="Environment Variables"
161
+ )
162
+ ]
163
+ )
164
+
165
+
166
+ def have_auth(router):
167
+ if router and hasattr(router, 'dependencies'):
168
+ for dep in router.dependencies:
169
+ if dep.dependency == require_authentication:
170
+ return True
171
+ return False
172
+
173
+
174
+ @debug_plugin_router.get("/route_no_auth")
175
+ async def route_no_auth(
176
+ request: Request,
177
+ view_builder=Depends(get_view_builder),
178
+ fast_pluggy=Depends(get_fastpluggy),
179
+ ):
180
+ """
181
+ List routes of the application, including authentication check and conflict detection.
182
+ """
183
+ seen_routes = {}
184
+ route_items = []
185
+
186
+ for route in fast_pluggy.app.routes:
187
+ if not isinstance(route, APIRoute):
188
+ continue
189
+
190
+ metadata = _extract_route_metadata(route)
191
+ metadata["auth_required"] = have_auth(route) # You already use this
192
+ metadata["conflict"] = False # Default to no conflict
193
+
194
+ # Check for conflicts: same path + method
195
+ for method in metadata["methods"]:
196
+ key = f"{metadata['path']}::{method}"
197
+ if key in seen_routes:
198
+ seen_routes[key]["conflict"] = True
199
+ metadata["conflict"] = True
200
+ else:
201
+ seen_routes[key] = metadata
202
+
203
+ route_items.append(metadata)
204
+
205
+ return view_builder.generate(
206
+ request,
207
+ title="Routes without Auth + Conflict Detection",
208
+ widgets=[
209
+ TableView(
210
+ data=route_items,
211
+ field_callbacks={
212
+ "path": lambda v: f"<code>{v}</code>",
213
+ "methods": RenderFieldTools.render_http_verb_badges,
214
+ "auth_required": lambda v: "✅" if v else "❌",
215
+ "conflict": lambda v: "⚠️ Conflict" if v else "—",
216
+ },
217
+ fields=["name", "path", "methods", "auth_required", "conflict"]
218
+ )
219
+ ]
220
+ )
221
+
222
+
223
+ @debug_plugin_router.get("/list_session")
224
+ async def list_session(
225
+ request: Request,
226
+ view_builder=Depends(get_view_builder)):
227
+ return view_builder.generate(
228
+ request,
229
+ title="List session",
230
+ widgets=[
231
+ DebugView(
232
+ data=request.session,
233
+ )
234
+ ]
235
+ )
236
+
237
+
238
+ @debug_plugin_router.get("/list_global_registry")
239
+ async def list_global_registry(
240
+ request: Request,
241
+ view_builder=Depends(get_view_builder)):
242
+ from fastpluggy.fastpluggy import FastPluggy
243
+ return view_builder.generate(
244
+ request,
245
+ title="List global registry",
246
+ widgets=[
247
+ DebugView(
248
+ data=FastPluggy.get_all_globals(),
249
+ )
250
+ ]
251
+ )
252
+
253
+
254
+ @debug_plugin_router.get("/list_jinja2_templates")
255
+ async def list_jinja2_templates(
256
+ request: Request,
257
+ view_builder=Depends(get_view_builder),
258
+ fast_pluggy=Depends(get_fastpluggy)):
259
+ """
260
+ List all Jinja2 templates registered in the application.
261
+ """
262
+ templates = fast_pluggy.templates.env.list_templates()
263
+ templates_data = [{"template_path": template} for template in templates]
264
+
265
+ return view_builder.generate(
266
+ request,
267
+ title="Registered Jinja2 Templates",
268
+ widgets=[
269
+ TableView(
270
+ data=templates_data,
271
+ title="Jinja2 Templates"
272
+ )
273
+ ]
274
+ )
@@ -0,0 +1,94 @@
1
+ import threading
2
+
3
+ import psutil
4
+ from fastapi import APIRouter, Request, Depends
5
+ from sqlalchemy.orm import Session
6
+
7
+ from fastpluggy.core.auth import require_authentication
8
+ from fastpluggy.core.database import get_db
9
+ from fastpluggy.core.dependency import get_view_builder
10
+ from fastpluggy.core.widgets.render_field_tools import RenderFieldTools
11
+ from fastpluggy.core.view_builer.components.table import TableView
12
+ from fastpluggy.core.widgets import ButtonListWidget, AutoLinkWidget
13
+ from fastpluggy.core.widgets.categories.data.debug import DebugView
14
+ from fastpluggy.core.widgets.categories.layout.tabbed import TabbedWidget
15
+ from ..config import TasksRunnerSettings
16
+ from ..services.task_discovery import discover_celery_periodic_tasks
17
+ from ..services.task_discovery import discover_celery_tasks_from_app
18
+
19
+ # Set custom /proc path if provided
20
+ # custom_proc_path = os.getenv("PROCFS_PATH", "/proc")
21
+
22
+ debug_router = APIRouter(
23
+ prefix="/debug",
24
+ tags=["debug"],
25
+ dependencies=[Depends(require_authentication)],
26
+ )
27
+
28
+
29
+ @debug_router.get("/", name="list_threads")
30
+ async def list_threads(
31
+ request: Request,
32
+ db: Session = Depends(get_db),
33
+ view_builder=Depends(get_view_builder)
34
+ ):
35
+ # if host_proces:
36
+ # psutil.PROCFS_PATH = custom_proc_path
37
+
38
+ process = psutil.Process()
39
+ num_threads = process.num_threads()
40
+ process_dict = process.as_dict()
41
+ threads = process_dict['threads']
42
+ threads_dict = [item._asdict() for item in threads]
43
+ clean_threads_dict = threads_dict
44
+ #clean_threads_dict = get_list_task_by_pid(db, threads_dict)
45
+
46
+ threads_enum = [thread for thread in threading.enumerate()]
47
+
48
+ return view_builder.generate(
49
+ request,
50
+ title=f"Thread list (running {num_threads})",
51
+ widgets=[
52
+ ButtonListWidget(buttons=[
53
+ AutoLinkWidget(route_name="celery_list_tasks"),
54
+ ]),
55
+ TableView(
56
+ data=clean_threads_dict,
57
+ field_callbacks={'status': RenderFieldTools.render_enum},
58
+ links=[
59
+ AutoLinkWidget(
60
+ label="Details", route_name="task_details",
61
+ #param_mapping={'task_id': 'task_id'},
62
+ condition=lambda task: task['task_id'] is not None),
63
+ ]
64
+ ),
65
+ TabbedWidget(tabs=[
66
+ DebugView(data=threads_enum, title="Thread Enum"),
67
+ DebugView(data=clean_threads_dict, title="Clean threads dict"),
68
+ DebugView(data=process_dict, title="Process"),
69
+ DebugView(data=threads_dict, title="Thread"),
70
+ ]),
71
+ ButtonListWidget(buttons=[
72
+ AutoLinkWidget(label="Back to Task Dashboard", route_name="list_tools"),
73
+ ]),
74
+ ]
75
+ )
76
+
77
+ @debug_router.get("/celery_list_tasks", name="celery_list_tasks")
78
+ async def celery_list_tasks(
79
+ request: Request,
80
+ view_builder=Depends(get_view_builder)
81
+ ):
82
+ settings = TasksRunnerSettings()
83
+ data = discover_celery_tasks_from_app(settings.celery_app_path)
84
+ schedule = discover_celery_periodic_tasks(settings.celery_app_path)
85
+
86
+ return view_builder.generate(
87
+ request,
88
+ title="Celery list",
89
+ widgets=[
90
+ DebugView(data=data, title="Celery Tasks"),
91
+ DebugView(data=schedule, title="Celery Scheduled Tasks"),
92
+ ]
93
+ )
94
+