lightfall 0.1.1__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.
- lightfall/__init__.py +8 -0
- lightfall/__main__.py +10 -0
- lightfall/_version.py +24 -0
- lightfall/acquire/__init__.py +74 -0
- lightfall/acquire/buffer.py +363 -0
- lightfall/acquire/device_wrapper.py +416 -0
- lightfall/acquire/engine/__init__.py +155 -0
- lightfall/acquire/engine/base.py +587 -0
- lightfall/acquire/engine/bluesky.py +358 -0
- lightfall/acquire/engine/mock.py +165 -0
- lightfall/acquire/engine/plugins/__init__.py +9 -0
- lightfall/acquire/engine/plugins/bluesky_plugin.py +56 -0
- lightfall/acquire/engine/plugins/mock_plugin.py +55 -0
- lightfall/acquire/engine/protocol.py +145 -0
- lightfall/acquire/engine/registry.py +152 -0
- lightfall/acquire/engine/state.py +32 -0
- lightfall/acquire/engine/waiting_hook.py +225 -0
- lightfall/acquire/nats_bridge.py +62 -0
- lightfall/acquire/plan_ui.py +78 -0
- lightfall/acquire/plans/__init__.py +38 -0
- lightfall/acquire/plans/adaptive.py +288 -0
- lightfall/acquire/plans/example_plans.py +995 -0
- lightfall/acquire/plans/lightfall_plans.py +587 -0
- lightfall/acquire/plans/registry.py +543 -0
- lightfall/acquire/plans/standard_plans.py +186 -0
- lightfall/acquire/plans/user_plans.py +470 -0
- lightfall/acquire/runengine.py +36 -0
- lightfall/acquire/signals.py +452 -0
- lightfall/acquire/triggers/__init__.py +16 -0
- lightfall/acquire/triggers/base.py +25 -0
- lightfall/acquire/triggers/filter.py +37 -0
- lightfall/acquire/triggers/manager.py +73 -0
- lightfall/acquire/triggers/manual.py +36 -0
- lightfall/acquire/triggers/run_end.py +74 -0
- lightfall/acquire/triggers/run_start.py +52 -0
- lightfall/auth/__init__.py +38 -0
- lightfall/auth/policy.py +518 -0
- lightfall/auth/providers/__init__.py +30 -0
- lightfall/auth/providers/base.py +124 -0
- lightfall/auth/providers/keycloak.py +1017 -0
- lightfall/auth/providers/local.py +319 -0
- lightfall/auth/providers/pam.py +250 -0
- lightfall/auth/service_key.py +173 -0
- lightfall/auth/service_key_auth.py +79 -0
- lightfall/auth/session.py +656 -0
- lightfall/claude/__init__.py +52 -0
- lightfall/claude/_internal/__init__.py +1 -0
- lightfall/claude/_internal/serialization.py +195 -0
- lightfall/claude/_internal/threading.py +61 -0
- lightfall/claude/_internal/worker.py +757 -0
- lightfall/claude/_session_assembly.py +124 -0
- lightfall/claude/agent.py +596 -0
- lightfall/claude/lightfall_core_tools.py +410 -0
- lightfall/claude/markdown.py +103 -0
- lightfall/claude/permission_manager.py +588 -0
- lightfall/claude/tools/__init__.py +45 -0
- lightfall/claude/tools/controller.py +143 -0
- lightfall/claude/tools/interaction.py +177 -0
- lightfall/claude/tools/introspection.py +127 -0
- lightfall/claude/tools/logs.py +155 -0
- lightfall/claude/tools/screenshot.py +87 -0
- lightfall/claude/widget.py +851 -0
- lightfall/claude/widgets/__init__.py +5 -0
- lightfall/claude/widgets/permission_request.py +282 -0
- lightfall/claude/widgets/question_request.py +227 -0
- lightfall/claude/widgets/task_card.py +223 -0
- lightfall/config/__init__.py +23 -0
- lightfall/config/layers.py +317 -0
- lightfall/config/manager.py +244 -0
- lightfall/config/schema.py +154 -0
- lightfall/core/__init__.py +23 -0
- lightfall/core/application.py +727 -0
- lightfall/core/services.py +235 -0
- lightfall/devices/__init__.py +53 -0
- lightfall/devices/backends/__init__.py +17 -0
- lightfall/devices/backends/bcs.py +448 -0
- lightfall/devices/backends/happi.py +986 -0
- lightfall/devices/backends/mock.py +646 -0
- lightfall/devices/base.py +338 -0
- lightfall/devices/catalog.py +1039 -0
- lightfall/devices/connection_manager.py +676 -0
- lightfall/devices/model.py +290 -0
- lightfall/devices/monitoring.py +442 -0
- lightfall/devices/sim/__init__.py +26 -0
- lightfall/devices/sim/areadetector.py +436 -0
- lightfall/devices/sim/generators.py +223 -0
- lightfall/devices/sim/plugins.py +116 -0
- lightfall/epics/__init__.py +28 -0
- lightfall/epics/ca/__init__.py +10 -0
- lightfall/epics/ca/context.py +100 -0
- lightfall/epics/ca/pv.py +303 -0
- lightfall/epics/widgets/__init__.py +49 -0
- lightfall/epics/widgets/areadetector/__init__.py +16 -0
- lightfall/epics/widgets/areadetector/areadetector.py +281 -0
- lightfall/epics/widgets/areadetector/controls.py +478 -0
- lightfall/epics/widgets/areadetector/image_view.py +447 -0
- lightfall/epics/widgets/auto.py +319 -0
- lightfall/epics/widgets/base.py +404 -0
- lightfall/epics/widgets/checkbox.py +239 -0
- lightfall/epics/widgets/combobox.py +202 -0
- lightfall/epics/widgets/label.py +176 -0
- lightfall/epics/widgets/lineedit.py +253 -0
- lightfall/epics/widgets/motor.py +694 -0
- lightfall/epics/widgets/ophyd_base.py +469 -0
- lightfall/epics/widgets/ophyd_combobox.py +86 -0
- lightfall/epics/widgets/ophyd_label.py +54 -0
- lightfall/epics/widgets/ophyd_lineedit.py +170 -0
- lightfall/epics/widgets/ophyd_spinbox.py +79 -0
- lightfall/epics/widgets/slider.py +272 -0
- lightfall/epics/widgets/status_indicator.py +98 -0
- lightfall/epics/widgets/style.py +188 -0
- lightfall/exporter/__init__.py +1 -0
- lightfall/exporter/cli.py +67 -0
- lightfall/exporter/converters/__init__.py +26 -0
- lightfall/exporter/converters/base.py +39 -0
- lightfall/exporter/converters/noop.py +39 -0
- lightfall/exporter/converters/nxsas.py +73 -0
- lightfall/exporter/service.py +200 -0
- lightfall/exporter/tiled_utils.py +92 -0
- lightfall/ipc/__init__.py +6 -0
- lightfall/ipc/service.py +701 -0
- lightfall/ipc/trust.py +144 -0
- lightfall/logbook/__init__.py +46 -0
- lightfall/logbook/action_dialog.py +207 -0
- lightfall/logbook/action_logger.py +432 -0
- lightfall/logbook/block_mapper.py +562 -0
- lightfall/logbook/client.py +799 -0
- lightfall/logbook/converter.py +273 -0
- lightfall/logbook/editors/__init__.py +19 -0
- lightfall/logbook/editors/highlighter.py +305 -0
- lightfall/logbook/editors/markdown_editor.py +319 -0
- lightfall/logbook/editors/richtext_editor.py +1397 -0
- lightfall/logbook/entry_widget.py +1065 -0
- lightfall/logbook/event_listener.py +221 -0
- lightfall/logbook/fragment_widgets.py +925 -0
- lightfall/logbook/position_mapper.py +320 -0
- lightfall/logbook/protection.py +402 -0
- lightfall/logbook/style.py +394 -0
- lightfall/logbook/url.py +29 -0
- lightfall/logbook/visual_protection.py +330 -0
- lightfall/logbook/widget.py +680 -0
- lightfall/main.py +1091 -0
- lightfall/pipelines/__init__.py +4 -0
- lightfall/pipelines/client.py +148 -0
- lightfall/plugins/__init__.py +119 -0
- lightfall/plugins/agent_plugin.py +106 -0
- lightfall/plugins/agents/__init__.py +10 -0
- lightfall/plugins/agents/_mcp_helpers.py +52 -0
- lightfall/plugins/agents/alignment.py +94 -0
- lightfall/plugins/agents/autonomous_experiment/__init__.py +12 -0
- lightfall/plugins/agents/autonomous_experiment/nats_tools.py +210 -0
- lightfall/plugins/agents/autonomous_experiment/plugin.py +60 -0
- lightfall/plugins/agents/autonomous_experiment/prompts.py +164 -0
- lightfall/plugins/agents/current_esaf.py +435 -0
- lightfall/plugins/agents/device_tools.py +1043 -0
- lightfall/plugins/agents/engine_tools.py +720 -0
- lightfall/plugins/agents/ipython_tools.py +444 -0
- lightfall/plugins/agents/panel_builder.py +637 -0
- lightfall/plugins/agents/panel_design/references/cross_panel_patterns.md +95 -0
- lightfall/plugins/agents/panel_design/references/panel_design.md +680 -0
- lightfall/plugins/agents/panel_design.py +94 -0
- lightfall/plugins/agents/plan_design/references/plan_design.md +398 -0
- lightfall/plugins/agents/plan_design.py +90 -0
- lightfall/plugins/agents/plan_tools.py +878 -0
- lightfall/plugins/agents/scan_planning.py +101 -0
- lightfall/plugins/builtin_manifest.py +348 -0
- lightfall/plugins/controller_plugin.py +162 -0
- lightfall/plugins/engine_plugin.py +124 -0
- lightfall/plugins/errors.py +104 -0
- lightfall/plugins/info.py +112 -0
- lightfall/plugins/loader.py +878 -0
- lightfall/plugins/manifest.py +150 -0
- lightfall/plugins/panel_plugin.py +119 -0
- lightfall/plugins/plan_plugin.py +163 -0
- lightfall/plugins/registry.py +309 -0
- lightfall/plugins/settings_plugin.py +226 -0
- lightfall/plugins/statusbar_plugin.py +289 -0
- lightfall/plugins/theme_plugin.py +165 -0
- lightfall/plugins/types.py +136 -0
- lightfall/plugins/user_plugins.py +764 -0
- lightfall/project/__init__.py +37 -0
- lightfall/project/model.py +375 -0
- lightfall/project/service.py +427 -0
- lightfall/project/welcome.py +106 -0
- lightfall/resources/__init__.py +126 -0
- lightfall/resources/images/__init__.py +1 -0
- lightfall/resources/images/icon.ico +0 -0
- lightfall/resources/images/icon.png +0 -0
- lightfall/resources/images/logo.png +0 -0
- lightfall/services/__init__.py +33 -0
- lightfall/services/_alshub_client.py +73 -0
- lightfall/services/access_stamper.py +240 -0
- lightfall/services/als_beam_status.py +347 -0
- lightfall/services/ca_tunnel.py +325 -0
- lightfall/services/threaded_tiled_writer.py +174 -0
- lightfall/services/tiled_auth.py +21 -0
- lightfall/services/tiled_service.py +971 -0
- lightfall/services/tiled_writer_patch.py +301 -0
- lightfall/settings/__init__.py +1 -0
- lightfall/settings/image_helpers.py +30 -0
- lightfall/settings/user_settings_client.py +232 -0
- lightfall/ui/__init__.py +28 -0
- lightfall/ui/annotations.py +208 -0
- lightfall/ui/common/__init__.py +7 -0
- lightfall/ui/dialogs/__init__.py +26 -0
- lightfall/ui/dialogs/about_dialog.py +131 -0
- lightfall/ui/dialogs/add_trigger_dialog.py +152 -0
- lightfall/ui/dialogs/base.py +44 -0
- lightfall/ui/dialogs/bug_report_dialog.py +353 -0
- lightfall/ui/dialogs/create_plan_dialog.py +189 -0
- lightfall/ui/dialogs/device_edit_dialog.py +183 -0
- lightfall/ui/dialogs/export_dialog.py +565 -0
- lightfall/ui/dialogs/go_to_position_dialog.py +192 -0
- lightfall/ui/dialogs/login_dialog.py +756 -0
- lightfall/ui/dialogs/oauth_browser_dialog.py +305 -0
- lightfall/ui/dialogs/run_pipeline_dialog.py +131 -0
- lightfall/ui/dialogs/sample_metadata_dialog.py +316 -0
- lightfall/ui/docking/__init__.py +22 -0
- lightfall/ui/docking/icon_sidebar.py +806 -0
- lightfall/ui/docking/manager.py +682 -0
- lightfall/ui/docking/state.py +113 -0
- lightfall/ui/docking/theme.py +399 -0
- lightfall/ui/docking/widget.py +214 -0
- lightfall/ui/events.py +75 -0
- lightfall/ui/mainwindow.py +1006 -0
- lightfall/ui/models/__init__.py +49 -0
- lightfall/ui/models/device_selection.py +389 -0
- lightfall/ui/models/device_tree.py +1095 -0
- lightfall/ui/models/thread_model.py +667 -0
- lightfall/ui/models/tiled_model.py +384 -0
- lightfall/ui/panels/__init__.py +28 -0
- lightfall/ui/panels/base.py +525 -0
- lightfall/ui/panels/bluesky_panel.py +619 -0
- lightfall/ui/panels/claude/__init__.py +9 -0
- lightfall/ui/panels/claude/agent_registry.py +168 -0
- lightfall/ui/panels/claude_panel.py +887 -0
- lightfall/ui/panels/device_panel.py +370 -0
- lightfall/ui/panels/documents_panel.py +166 -0
- lightfall/ui/panels/ipython_panel.py +580 -0
- lightfall/ui/panels/logbook_entries_panel.py +84 -0
- lightfall/ui/panels/logbook_panel.py +627 -0
- lightfall/ui/panels/logging_panel.py +587 -0
- lightfall/ui/panels/pipeline_jobs_panel.py +160 -0
- lightfall/ui/panels/pipeline_triggers_panel.py +170 -0
- lightfall/ui/panels/plugins/__init__.py +34 -0
- lightfall/ui/panels/plugins/bluesky_plugin.py +27 -0
- lightfall/ui/panels/plugins/claude_plugin.py +29 -0
- lightfall/ui/panels/plugins/device_plugin.py +27 -0
- lightfall/ui/panels/plugins/documents_plugin.py +26 -0
- lightfall/ui/panels/plugins/ipython_plugin.py +27 -0
- lightfall/ui/panels/plugins/logbook_entries_plugin.py +23 -0
- lightfall/ui/panels/plugins/logbook_plugin.py +27 -0
- lightfall/ui/panels/plugins/logging_plugin.py +27 -0
- lightfall/ui/panels/plugins/pipeline_jobs_plugin.py +23 -0
- lightfall/ui/panels/plugins/pipeline_triggers_plugin.py +25 -0
- lightfall/ui/panels/plugins/queue_plugin.py +29 -0
- lightfall/ui/panels/plugins/synoptic_plugin.py +38 -0
- lightfall/ui/panels/plugins/threads_plugin.py +27 -0
- lightfall/ui/panels/plugins/tiled_browser_plugin.py +27 -0
- lightfall/ui/panels/plugins/visualization_plugin.py +27 -0
- lightfall/ui/panels/queue.py +754 -0
- lightfall/ui/panels/registry.py +483 -0
- lightfall/ui/panels/synoptic/__init__.py +27 -0
- lightfall/ui/panels/synoptic/editors.py +481 -0
- lightfall/ui/panels/synoptic/items.py +556 -0
- lightfall/ui/panels/synoptic/models.py +336 -0
- lightfall/ui/panels/synoptic/panel.py +889 -0
- lightfall/ui/panels/synoptic/serialization.py +300 -0
- lightfall/ui/panels/synoptic/view.py +504 -0
- lightfall/ui/panels/threads_panel.py +621 -0
- lightfall/ui/panels/tiled_browser_panel.py +854 -0
- lightfall/ui/panels/visualization_panel.py +508 -0
- lightfall/ui/preferences/__init__.py +24 -0
- lightfall/ui/preferences/backend.py +148 -0
- lightfall/ui/preferences/builtin.py +220 -0
- lightfall/ui/preferences/claude_settings.py +762 -0
- lightfall/ui/preferences/device_settings.py +461 -0
- lightfall/ui/preferences/dialog.py +234 -0
- lightfall/ui/preferences/editor_settings.py +227 -0
- lightfall/ui/preferences/ipc_settings.py +226 -0
- lightfall/ui/preferences/logbook_settings.py +232 -0
- lightfall/ui/preferences/login_settings.py +183 -0
- lightfall/ui/preferences/manager.py +562 -0
- lightfall/ui/preferences/plugin_settings.py +392 -0
- lightfall/ui/preferences/proxy_settings.py +561 -0
- lightfall/ui/preferences/skill_settings.py +28 -0
- lightfall/ui/preferences/tiled_settings.py +469 -0
- lightfall/ui/preferences/tool_settings.py +393 -0
- lightfall/ui/preferences/user_portable_backend.py +131 -0
- lightfall/ui/preferences/user_profile_settings.py +316 -0
- lightfall/ui/preferences/visualization_settings.py +159 -0
- lightfall/ui/resources/__init__.py +1 -0
- lightfall/ui/resources/logo.png +0 -0
- lightfall/ui/statusbar/__init__.py +11 -0
- lightfall/ui/statusbar/manager.py +379 -0
- lightfall/ui/statusbar/plugins/__init__.py +28 -0
- lightfall/ui/statusbar/plugins/als_beam_status.py +218 -0
- lightfall/ui/statusbar/plugins/auth_status.py +116 -0
- lightfall/ui/statusbar/plugins/connection_status.py +100 -0
- lightfall/ui/statusbar/plugins/thread_status.py +556 -0
- lightfall/ui/statusbar/plugins/tiled_status.py +179 -0
- lightfall/ui/statusbar/plugins/user_status.py +84 -0
- lightfall/ui/theater/__init__.py +28 -0
- lightfall/ui/theater/manager.py +124 -0
- lightfall/ui/theater/overlay.py +279 -0
- lightfall/ui/theater/proxy.py +111 -0
- lightfall/ui/theme/__init__.py +18 -0
- lightfall/ui/theme/builtin.py +1015 -0
- lightfall/ui/theme/manager.py +875 -0
- lightfall/ui/theme/registry.py +195 -0
- lightfall/ui/toast.py +221 -0
- lightfall/ui/tutorial.py +1100 -0
- lightfall/ui/widgets/__init__.py +110 -0
- lightfall/ui/widgets/base_control.py +259 -0
- lightfall/ui/widgets/camera/__init__.py +36 -0
- lightfall/ui/widgets/camera/base.py +815 -0
- lightfall/ui/widgets/camera/dark_frames.py +213 -0
- lightfall/ui/widgets/camera/image_view.py +649 -0
- lightfall/ui/widgets/camera/panels/__init__.py +14 -0
- lightfall/ui/widgets/camera/panels/cooler.py +320 -0
- lightfall/ui/widgets/camera/panels/temperature.py +192 -0
- lightfall/ui/widgets/camera/plan_based.py +202 -0
- lightfall/ui/widgets/compact_motor.py +522 -0
- lightfall/ui/widgets/controller_matcher.py +278 -0
- lightfall/ui/widgets/controller_registry.py +144 -0
- lightfall/ui/widgets/device_control.py +411 -0
- lightfall/ui/widgets/device_selector.py +438 -0
- lightfall/ui/widgets/device_tree_tab.py +461 -0
- lightfall/ui/widgets/document_stream.py +1028 -0
- lightfall/ui/widgets/favorites_tab.py +191 -0
- lightfall/ui/widgets/motor_control.py +1120 -0
- lightfall/ui/widgets/observers/__init__.py +8 -0
- lightfall/ui/widgets/observers/camera.py +48 -0
- lightfall/ui/widgets/observers/image_view.py +130 -0
- lightfall/ui/widgets/plan_config.py +954 -0
- lightfall/ui/widgets/plan_edit_dialog.py +294 -0
- lightfall/ui/widgets/plan_selector.py +452 -0
- lightfall/ui/widgets/profile_avatar.py +128 -0
- lightfall/ui/widgets/queue_view.py +647 -0
- lightfall/ui/widgets/runengine_control.py +549 -0
- lightfall/ui/widgets/signal_control.py +793 -0
- lightfall/ui/widgets/skill_trigger_button.py +183 -0
- lightfall/ui/widgets/tiled_filter_widget.py +314 -0
- lightfall/ui/widgets/tiled_status.py +149 -0
- lightfall/ui/widgets/warning_banner.py +185 -0
- lightfall/utils/__init__.py +53 -0
- lightfall/utils/crash_diagnostics.py +454 -0
- lightfall/utils/data_migration.py +22 -0
- lightfall/utils/editor_launcher.py +594 -0
- lightfall/utils/error_collector.py +245 -0
- lightfall/utils/git_tracker.py +197 -0
- lightfall/utils/log_buffer.py +233 -0
- lightfall/utils/logging.py +229 -0
- lightfall/utils/module_resolver.py +70 -0
- lightfall/utils/sentry.py +722 -0
- lightfall/utils/threads.py +991 -0
- lightfall/utils/tiled_helpers.py +96 -0
- lightfall/visualization/__init__.py +50 -0
- lightfall/visualization/base.py +5 -0
- lightfall/visualization/base_visualization.py +74 -0
- lightfall/visualization/fitting/__init__.py +24 -0
- lightfall/visualization/fitting/base.py +267 -0
- lightfall/visualization/fitting/fitters.py +325 -0
- lightfall/visualization/fitting/panel.py +265 -0
- lightfall/visualization/memory.py +392 -0
- lightfall/visualization/motor_mixin.py +524 -0
- lightfall/visualization/pg.py +156 -0
- lightfall/visualization/registry.py +144 -0
- lightfall/visualization/spec.py +79 -0
- lightfall/visualization/theme.py +266 -0
- lightfall/visualization/widgets/__init__.py +28 -0
- lightfall/visualization/widgets/adaptive/__init__.py +1 -0
- lightfall/visualization/widgets/adaptive/heatmap.py +655 -0
- lightfall/visualization/widgets/adaptive/plot.py +233 -0
- lightfall/visualization/widgets/heatmap.py +264 -0
- lightfall/visualization/widgets/image_stack.py +316 -0
- lightfall/visualization/widgets/image_view_toolbar.py +227 -0
- lightfall/visualization/widgets/lazy_image_view.py +590 -0
- lightfall/visualization/widgets/plot_1d.py +262 -0
- lightfall/visualization/widgets/scatter.py +247 -0
- lightfall/visualization/widgets/table.py +221 -0
- lightfall/visualization/widgets/time_axis.py +93 -0
- lightfall-0.1.1.dist-info/METADATA +223 -0
- lightfall-0.1.1.dist-info/RECORD +388 -0
- lightfall-0.1.1.dist-info/WHEEL +4 -0
- lightfall-0.1.1.dist-info/entry_points.txt +6 -0
- lightfall-0.1.1.dist-info/licenses/LEGAL.md +13 -0
- lightfall-0.1.1.dist-info/licenses/LICENSE.md +33 -0
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
"""Base engine implementation.
|
|
2
|
+
|
|
3
|
+
Provides a base class with common functionality for engines.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import uuid
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from queue import Empty, PriorityQueue
|
|
13
|
+
from typing import TYPE_CHECKING, Any
|
|
14
|
+
|
|
15
|
+
from PySide6.QtCore import QObject, Signal
|
|
16
|
+
|
|
17
|
+
from lightfall.acquire.engine.state import EngineState
|
|
18
|
+
from lightfall.utils.logging import logger
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from lightfall.ui.toast import ToastManager
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(order=True)
|
|
25
|
+
class PrioritizedProcedure:
|
|
26
|
+
"""A procedure with priority for queue ordering.
|
|
27
|
+
|
|
28
|
+
Attributes:
|
|
29
|
+
priority: Queue priority (lower = higher priority).
|
|
30
|
+
procedure: The procedure to execute (type is engine-specific).
|
|
31
|
+
kwargs: Additional keyword arguments for the procedure.
|
|
32
|
+
id: Unique identifier for this procedure (auto-generated UUID).
|
|
33
|
+
submitted_at: Timestamp when the procedure was submitted.
|
|
34
|
+
name: Human-readable name for the procedure (auto-detected or provided).
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
priority: int
|
|
38
|
+
procedure: Any = field(compare=False)
|
|
39
|
+
kwargs: dict[str, Any] = field(compare=False, default_factory=dict)
|
|
40
|
+
id: str = field(compare=False, default_factory=lambda: str(uuid.uuid4()))
|
|
41
|
+
submitted_at: datetime = field(compare=False, default_factory=datetime.now)
|
|
42
|
+
name: str = field(compare=False, default="")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class BaseEngine(QObject):
|
|
46
|
+
"""Base class for execution engines.
|
|
47
|
+
|
|
48
|
+
Provides common functionality:
|
|
49
|
+
- Priority queue management
|
|
50
|
+
- Subscription management
|
|
51
|
+
- Qt signal declarations
|
|
52
|
+
- State property implementation
|
|
53
|
+
|
|
54
|
+
Subclasses must implement:
|
|
55
|
+
- pause(): Pause execution
|
|
56
|
+
- resume(): Resume paused execution
|
|
57
|
+
- stop(): Graceful stop
|
|
58
|
+
- abort(): Immediate abort
|
|
59
|
+
- halt(): Emergency halt
|
|
60
|
+
|
|
61
|
+
Signals:
|
|
62
|
+
sigOutput(str, dict): Emitted for each (name, document) output pair.
|
|
63
|
+
sigStart(): Emitted when a procedure starts executing.
|
|
64
|
+
sigFinish(): Emitted when a procedure finishes successfully.
|
|
65
|
+
sigPause(): Emitted when execution is paused.
|
|
66
|
+
sigResume(): Emitted when execution resumes.
|
|
67
|
+
sigAbort(): Emitted when execution is aborted.
|
|
68
|
+
sigException(Exception): Emitted when an error occurs.
|
|
69
|
+
sigReady(): Emitted when queue is empty and engine is idle.
|
|
70
|
+
sigStateChanged(str): Emitted on any state change.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
# Qt Signals
|
|
74
|
+
sigOutput = Signal(str, dict)
|
|
75
|
+
sigStart = Signal()
|
|
76
|
+
sigFinish = Signal()
|
|
77
|
+
sigPause = Signal()
|
|
78
|
+
sigResume = Signal()
|
|
79
|
+
sigAbort = Signal()
|
|
80
|
+
sigException = Signal(Exception)
|
|
81
|
+
sigReady = Signal()
|
|
82
|
+
sigStateChanged = Signal(str)
|
|
83
|
+
sigQueueChanged = Signal() # Emitted when queue items are added/removed/reordered
|
|
84
|
+
|
|
85
|
+
def __init__(
|
|
86
|
+
self, name: str = "engine", *, toast_notifications: bool = True, **kwargs: Any
|
|
87
|
+
) -> None:
|
|
88
|
+
"""Initialize the base engine.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
name: Human-readable engine identifier.
|
|
92
|
+
toast_notifications: Whether to show toast notifications on run
|
|
93
|
+
completion, abort, and errors. Defaults to True.
|
|
94
|
+
**kwargs: Additional arguments (passed to QObject).
|
|
95
|
+
"""
|
|
96
|
+
super().__init__()
|
|
97
|
+
self._name = name
|
|
98
|
+
self._state = EngineState.IDLE
|
|
99
|
+
self._queue: PriorityQueue[PrioritizedProcedure] = PriorityQueue()
|
|
100
|
+
self._queue_items: list[PrioritizedProcedure] = [] # Parallel list for management
|
|
101
|
+
self._current_procedure: PrioritizedProcedure | None = None # Currently running
|
|
102
|
+
self._subscribers: dict[int, Callable[[str, dict], Any]] = {}
|
|
103
|
+
self._next_token = 0
|
|
104
|
+
self._pre_submit_callables: list[Callable[[str, dict[str, Any]], dict[str, Any] | None]] = []
|
|
105
|
+
self._toast_notifications = toast_notifications
|
|
106
|
+
self._toast_manager: ToastManager | None = None
|
|
107
|
+
|
|
108
|
+
# Connect state signals for ready check
|
|
109
|
+
self.sigFinish.connect(self._check_if_ready)
|
|
110
|
+
self.sigAbort.connect(self._check_if_ready)
|
|
111
|
+
self.sigException.connect(self._check_if_ready)
|
|
112
|
+
|
|
113
|
+
# Connect toast notification handlers
|
|
114
|
+
self.sigFinish.connect(self._on_finish_toast)
|
|
115
|
+
self.sigAbort.connect(self._on_abort_toast)
|
|
116
|
+
self.sigException.connect(self._on_exception_toast)
|
|
117
|
+
|
|
118
|
+
# === Properties ===
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def name(self) -> str:
|
|
122
|
+
"""Human-readable engine name."""
|
|
123
|
+
return self._name
|
|
124
|
+
|
|
125
|
+
@property
|
|
126
|
+
def state(self) -> EngineState:
|
|
127
|
+
"""Current engine state."""
|
|
128
|
+
return self._state
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def state_name(self) -> str:
|
|
132
|
+
"""Current state as lowercase string."""
|
|
133
|
+
return str(self._state)
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def is_idle(self) -> bool:
|
|
137
|
+
"""Whether engine is idle and ready for new procedures."""
|
|
138
|
+
return self._state == EngineState.IDLE
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def queue_size(self) -> int:
|
|
142
|
+
"""Number of procedures waiting in the queue."""
|
|
143
|
+
return self._queue.qsize()
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def toast_notifications(self) -> bool:
|
|
147
|
+
"""Whether toast notifications are enabled for run events."""
|
|
148
|
+
return self._toast_notifications
|
|
149
|
+
|
|
150
|
+
@toast_notifications.setter
|
|
151
|
+
def toast_notifications(self, value: bool) -> None:
|
|
152
|
+
"""Enable or disable toast notifications."""
|
|
153
|
+
self._toast_notifications = value
|
|
154
|
+
|
|
155
|
+
def _get_toast_manager(self) -> ToastManager:
|
|
156
|
+
"""Get the ToastManager instance (lazy initialization)."""
|
|
157
|
+
if self._toast_manager is None:
|
|
158
|
+
from lightfall.ui.toast import ToastManager
|
|
159
|
+
|
|
160
|
+
self._toast_manager = ToastManager.get_instance()
|
|
161
|
+
return self._toast_manager
|
|
162
|
+
|
|
163
|
+
# === Queue Operations ===
|
|
164
|
+
|
|
165
|
+
def submit(
|
|
166
|
+
self,
|
|
167
|
+
procedure: Any,
|
|
168
|
+
*,
|
|
169
|
+
priority: int = 1,
|
|
170
|
+
name: str = "",
|
|
171
|
+
skip_pre_submit: bool = False,
|
|
172
|
+
**kwargs: Any,
|
|
173
|
+
) -> str | None:
|
|
174
|
+
"""Submit a procedure for execution.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
procedure: The procedure to execute.
|
|
178
|
+
priority: Queue priority (lower = higher priority). Default is 1.
|
|
179
|
+
name: Human-readable name for the procedure. If not provided,
|
|
180
|
+
attempts to detect from generator function name.
|
|
181
|
+
skip_pre_submit: If True, bypass pre-submit hooks.
|
|
182
|
+
**kwargs: Additional procedure parameters.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
The unique ID of the submitted procedure, or None if cancelled
|
|
186
|
+
by a pre-submit hook.
|
|
187
|
+
"""
|
|
188
|
+
# Auto-detect name from generator if not provided
|
|
189
|
+
if not name:
|
|
190
|
+
name = self._get_procedure_name(procedure)
|
|
191
|
+
|
|
192
|
+
# Run pre-submit callables
|
|
193
|
+
if not skip_pre_submit:
|
|
194
|
+
if self._run_pre_submit_hooks(name, kwargs) is None:
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
item = PrioritizedProcedure(priority, procedure, kwargs, name=name)
|
|
198
|
+
self._queue.put(item)
|
|
199
|
+
self._queue_items.append(item)
|
|
200
|
+
self._queue_items.sort(key=lambda x: x.priority)
|
|
201
|
+
logger.debug(f"[{self._name}] Queued '{name}' with priority {priority}, id={item.id[:8]}")
|
|
202
|
+
self.sigQueueChanged.emit()
|
|
203
|
+
return item.id
|
|
204
|
+
|
|
205
|
+
def _get_procedure_name(self, procedure: Any) -> str:
|
|
206
|
+
"""Attempt to get a human-readable name for a procedure.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
procedure: The procedure (generator, callable, etc.)
|
|
210
|
+
|
|
211
|
+
Returns:
|
|
212
|
+
A name string, or "procedure" if unable to determine.
|
|
213
|
+
"""
|
|
214
|
+
# Check for generator's function name
|
|
215
|
+
if hasattr(procedure, "gi_code"):
|
|
216
|
+
return str(procedure.gi_code.co_name)
|
|
217
|
+
# Check for callable's name
|
|
218
|
+
if callable(procedure) and hasattr(procedure, "__name__"):
|
|
219
|
+
return str(procedure.__name__)
|
|
220
|
+
# Check for functools.partial
|
|
221
|
+
if hasattr(procedure, "func") and hasattr(procedure.func, "__name__"):
|
|
222
|
+
return str(procedure.func.__name__)
|
|
223
|
+
return "procedure"
|
|
224
|
+
|
|
225
|
+
def __call__(self, *args: Any, **kwargs: Any) -> None:
|
|
226
|
+
"""Convenience method for submit().
|
|
227
|
+
|
|
228
|
+
If a single positional argument is provided, it's used as the procedure.
|
|
229
|
+
Otherwise, all args are bundled as the procedure.
|
|
230
|
+
"""
|
|
231
|
+
skip_pre_submit = kwargs.pop("skip_pre_submit", False)
|
|
232
|
+
if args:
|
|
233
|
+
procedure = args[0] if len(args) == 1 else args
|
|
234
|
+
self.submit(procedure, skip_pre_submit=skip_pre_submit, **kwargs)
|
|
235
|
+
else:
|
|
236
|
+
raise ValueError("No procedure provided")
|
|
237
|
+
|
|
238
|
+
def clear_queue(self) -> int:
|
|
239
|
+
"""Clear all pending procedures from the queue.
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
Number of procedures removed.
|
|
243
|
+
"""
|
|
244
|
+
count = 0
|
|
245
|
+
while True:
|
|
246
|
+
try:
|
|
247
|
+
self._queue.get_nowait()
|
|
248
|
+
count += 1
|
|
249
|
+
except Empty:
|
|
250
|
+
break
|
|
251
|
+
self._queue_items.clear()
|
|
252
|
+
if count:
|
|
253
|
+
logger.info(f"[{self._name}] Cleared {count} procedures from queue")
|
|
254
|
+
self.sigQueueChanged.emit()
|
|
255
|
+
return count
|
|
256
|
+
|
|
257
|
+
def get_queue_items(self) -> list[PrioritizedProcedure]:
|
|
258
|
+
"""Get a copy of the current queue items.
|
|
259
|
+
|
|
260
|
+
Returns:
|
|
261
|
+
List of queued procedures sorted by priority.
|
|
262
|
+
"""
|
|
263
|
+
return list(self._queue_items)
|
|
264
|
+
|
|
265
|
+
def get_current_procedure(self) -> PrioritizedProcedure | None:
|
|
266
|
+
"""Get the currently running procedure, if any.
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
The currently executing procedure, or None if idle.
|
|
270
|
+
"""
|
|
271
|
+
return self._current_procedure
|
|
272
|
+
|
|
273
|
+
def get_procedure_by_id(self, procedure_id: str) -> PrioritizedProcedure | None:
|
|
274
|
+
"""Get a queued procedure by its ID.
|
|
275
|
+
|
|
276
|
+
Args:
|
|
277
|
+
procedure_id: The procedure's unique ID.
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
The procedure if found, None otherwise.
|
|
281
|
+
"""
|
|
282
|
+
for item in self._queue_items:
|
|
283
|
+
if item.id == procedure_id:
|
|
284
|
+
return item
|
|
285
|
+
return None
|
|
286
|
+
|
|
287
|
+
def remove_from_queue(self, procedure_id: str) -> bool:
|
|
288
|
+
"""Remove a procedure from the queue by ID.
|
|
289
|
+
|
|
290
|
+
Args:
|
|
291
|
+
procedure_id: The ID of the procedure to remove.
|
|
292
|
+
|
|
293
|
+
Returns:
|
|
294
|
+
True if the procedure was found and removed.
|
|
295
|
+
"""
|
|
296
|
+
# Find the item in our tracking list
|
|
297
|
+
item_to_remove = None
|
|
298
|
+
for item in self._queue_items:
|
|
299
|
+
if item.id == procedure_id:
|
|
300
|
+
item_to_remove = item
|
|
301
|
+
break
|
|
302
|
+
|
|
303
|
+
if item_to_remove is None:
|
|
304
|
+
logger.warning(f"[{self._name}] Procedure {procedure_id[:8]} not found in queue")
|
|
305
|
+
return False
|
|
306
|
+
|
|
307
|
+
# Remove from tracking list
|
|
308
|
+
self._queue_items.remove(item_to_remove)
|
|
309
|
+
|
|
310
|
+
# Rebuild the priority queue without this item
|
|
311
|
+
self._rebuild_priority_queue()
|
|
312
|
+
|
|
313
|
+
logger.info(f"[{self._name}] Removed procedure {procedure_id[:8]} from queue")
|
|
314
|
+
self.sigQueueChanged.emit()
|
|
315
|
+
return True
|
|
316
|
+
|
|
317
|
+
def update_priority(self, procedure_id: str, new_priority: int) -> bool:
|
|
318
|
+
"""Update the priority of a queued procedure.
|
|
319
|
+
|
|
320
|
+
Args:
|
|
321
|
+
procedure_id: The ID of the procedure to update.
|
|
322
|
+
new_priority: The new priority value (lower = higher priority).
|
|
323
|
+
|
|
324
|
+
Returns:
|
|
325
|
+
True if the procedure was found and updated.
|
|
326
|
+
"""
|
|
327
|
+
# Find the item in our tracking list
|
|
328
|
+
for item in self._queue_items:
|
|
329
|
+
if item.id == procedure_id:
|
|
330
|
+
old_priority = item.priority
|
|
331
|
+
# Create new item with updated priority (dataclass is frozen by order=True)
|
|
332
|
+
# We need to modify the object directly since we're using it in a list
|
|
333
|
+
object.__setattr__(item, "priority", new_priority)
|
|
334
|
+
|
|
335
|
+
# Re-sort the tracking list
|
|
336
|
+
self._queue_items.sort(key=lambda x: x.priority)
|
|
337
|
+
|
|
338
|
+
# Rebuild the priority queue
|
|
339
|
+
self._rebuild_priority_queue()
|
|
340
|
+
|
|
341
|
+
logger.debug(
|
|
342
|
+
f"[{self._name}] Updated priority for {procedure_id[:8]}: "
|
|
343
|
+
f"{old_priority} -> {new_priority}"
|
|
344
|
+
)
|
|
345
|
+
self.sigQueueChanged.emit()
|
|
346
|
+
return True
|
|
347
|
+
|
|
348
|
+
logger.warning(f"[{self._name}] Procedure {procedure_id[:8]} not found in queue")
|
|
349
|
+
return False
|
|
350
|
+
|
|
351
|
+
def _rebuild_priority_queue(self) -> None:
|
|
352
|
+
"""Rebuild the PriorityQueue from the tracking list.
|
|
353
|
+
|
|
354
|
+
Called after removing items or updating priorities.
|
|
355
|
+
"""
|
|
356
|
+
# Drain the old queue
|
|
357
|
+
while True:
|
|
358
|
+
try:
|
|
359
|
+
self._queue.get_nowait()
|
|
360
|
+
except Empty:
|
|
361
|
+
break
|
|
362
|
+
|
|
363
|
+
# Re-add all items
|
|
364
|
+
for item in self._queue_items:
|
|
365
|
+
self._queue.put(item)
|
|
366
|
+
|
|
367
|
+
def _pop_next_procedure(self) -> PrioritizedProcedure | None:
|
|
368
|
+
"""Pop the next procedure from the queue.
|
|
369
|
+
|
|
370
|
+
Also removes from tracking list and sets as current.
|
|
371
|
+
Called by subclasses when starting execution.
|
|
372
|
+
|
|
373
|
+
Returns:
|
|
374
|
+
The next procedure to execute, or None if queue is empty.
|
|
375
|
+
"""
|
|
376
|
+
try:
|
|
377
|
+
item = self._queue.get_nowait()
|
|
378
|
+
# Remove from tracking list
|
|
379
|
+
if item in self._queue_items:
|
|
380
|
+
self._queue_items.remove(item)
|
|
381
|
+
self._current_procedure = item
|
|
382
|
+
self.sigQueueChanged.emit()
|
|
383
|
+
return item
|
|
384
|
+
except Empty:
|
|
385
|
+
return None
|
|
386
|
+
|
|
387
|
+
def _clear_current_procedure(self) -> None:
|
|
388
|
+
"""Clear the current procedure reference.
|
|
389
|
+
|
|
390
|
+
Called by subclasses when execution finishes.
|
|
391
|
+
"""
|
|
392
|
+
self._current_procedure = None
|
|
393
|
+
|
|
394
|
+
# === Subscription Management ===
|
|
395
|
+
|
|
396
|
+
def subscribe(self, callback: Callable[[str, dict], Any]) -> int:
|
|
397
|
+
"""Subscribe to output stream.
|
|
398
|
+
|
|
399
|
+
Args:
|
|
400
|
+
callback: Function called with (name, document) for each output.
|
|
401
|
+
|
|
402
|
+
Returns:
|
|
403
|
+
Subscription token for unsubscribing.
|
|
404
|
+
"""
|
|
405
|
+
token = self._next_token
|
|
406
|
+
self._next_token += 1
|
|
407
|
+
self._subscribers[token] = callback
|
|
408
|
+
logger.debug(f"[{self._name}] Added subscriber with token {token}")
|
|
409
|
+
return token
|
|
410
|
+
|
|
411
|
+
def unsubscribe(self, token: int) -> None:
|
|
412
|
+
"""Remove an output subscription.
|
|
413
|
+
|
|
414
|
+
Args:
|
|
415
|
+
token: Token returned by subscribe().
|
|
416
|
+
"""
|
|
417
|
+
if self._subscribers.pop(token, None) is not None:
|
|
418
|
+
logger.debug(f"[{self._name}] Removed subscriber with token {token}")
|
|
419
|
+
|
|
420
|
+
# === Pre-Submit Hooks ===
|
|
421
|
+
|
|
422
|
+
def _run_pre_submit_hooks(self, name: str, kwargs: dict[str, Any]) -> dict[str, Any] | None:
|
|
423
|
+
"""Run pre-submit callables, merging results into kwargs.
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
name: Plan name.
|
|
427
|
+
kwargs: Current kwargs dict (mutated in place).
|
|
428
|
+
|
|
429
|
+
Returns:
|
|
430
|
+
The updated kwargs dict, or None if a hook cancelled submission.
|
|
431
|
+
"""
|
|
432
|
+
for callable_ in self._pre_submit_callables:
|
|
433
|
+
try:
|
|
434
|
+
result = callable_(name, kwargs)
|
|
435
|
+
if result is None:
|
|
436
|
+
logger.info(f"[{self._name}] Submission cancelled by pre-submit hook")
|
|
437
|
+
return None
|
|
438
|
+
kwargs.update(result)
|
|
439
|
+
except Exception as ex:
|
|
440
|
+
logger.warning(f"[{self._name}] Error in pre-submit callable: {ex}")
|
|
441
|
+
return None
|
|
442
|
+
return kwargs
|
|
443
|
+
|
|
444
|
+
def register_pre_submit(
|
|
445
|
+
self, callable_: Callable[[str, dict[str, Any]], dict[str, Any] | None]
|
|
446
|
+
) -> None:
|
|
447
|
+
"""Register a callable invoked before each plan submission.
|
|
448
|
+
|
|
449
|
+
The callable receives (plan_name, kwargs) and must return:
|
|
450
|
+
- dict: additional kwargs to merge into the submission
|
|
451
|
+
- None: cancel the submission
|
|
452
|
+
|
|
453
|
+
Callables run on the calling thread in registration order.
|
|
454
|
+
|
|
455
|
+
Args:
|
|
456
|
+
callable_: Function with signature (str, dict) -> dict | None.
|
|
457
|
+
"""
|
|
458
|
+
self._pre_submit_callables.append(callable_)
|
|
459
|
+
|
|
460
|
+
def unregister_pre_submit(
|
|
461
|
+
self, callable_: Callable[[str, dict[str, Any]], dict[str, Any] | None]
|
|
462
|
+
) -> None:
|
|
463
|
+
"""Remove a pre-submit callable.
|
|
464
|
+
|
|
465
|
+
Args:
|
|
466
|
+
callable_: The callable to remove.
|
|
467
|
+
"""
|
|
468
|
+
try:
|
|
469
|
+
self._pre_submit_callables.remove(callable_)
|
|
470
|
+
except ValueError:
|
|
471
|
+
pass
|
|
472
|
+
|
|
473
|
+
def _emit_output(self, name: str, doc: dict[str, Any]) -> None:
|
|
474
|
+
"""Emit output to signal and subscribers.
|
|
475
|
+
|
|
476
|
+
Args:
|
|
477
|
+
name: Output name (e.g., 'start', 'event', 'stop').
|
|
478
|
+
doc: Output document dictionary.
|
|
479
|
+
"""
|
|
480
|
+
# Emit Qt signal
|
|
481
|
+
self.sigOutput.emit(name, doc)
|
|
482
|
+
|
|
483
|
+
# Call direct subscribers
|
|
484
|
+
for callback in self._subscribers.values():
|
|
485
|
+
try:
|
|
486
|
+
callback(name, doc)
|
|
487
|
+
except Exception as ex:
|
|
488
|
+
logger.warning(f"[{self._name}] Subscriber error: {ex}")
|
|
489
|
+
|
|
490
|
+
# === State Management ===
|
|
491
|
+
|
|
492
|
+
def _set_state(self, new_state: EngineState) -> None:
|
|
493
|
+
"""Update state and emit signal.
|
|
494
|
+
|
|
495
|
+
Args:
|
|
496
|
+
new_state: The new engine state.
|
|
497
|
+
"""
|
|
498
|
+
if self._state != new_state:
|
|
499
|
+
old_state = self._state
|
|
500
|
+
self._state = new_state
|
|
501
|
+
self.sigStateChanged.emit(str(new_state))
|
|
502
|
+
logger.debug(f"[{self._name}] State: {old_state} -> {new_state}")
|
|
503
|
+
|
|
504
|
+
def _check_if_ready(self, *args: Any) -> None:
|
|
505
|
+
"""Check if queue is empty and emit sigReady if so."""
|
|
506
|
+
if self._state == EngineState.IDLE and self._queue.empty():
|
|
507
|
+
self.sigReady.emit()
|
|
508
|
+
|
|
509
|
+
# === Toast Notification Handlers ===
|
|
510
|
+
|
|
511
|
+
def _on_finish_toast(self) -> None:
|
|
512
|
+
"""Show toast notification when a run finishes successfully."""
|
|
513
|
+
if not self._toast_notifications:
|
|
514
|
+
return
|
|
515
|
+
try:
|
|
516
|
+
toast = self._get_toast_manager()
|
|
517
|
+
toast.success("Run Complete", f"{self._name}: Run finished successfully")
|
|
518
|
+
except Exception as ex:
|
|
519
|
+
logger.warning(f"[{self._name}] Failed to show finish toast: {ex}")
|
|
520
|
+
|
|
521
|
+
def _on_abort_toast(self) -> None:
|
|
522
|
+
"""Show toast notification when a run is aborted."""
|
|
523
|
+
if not self._toast_notifications:
|
|
524
|
+
return
|
|
525
|
+
try:
|
|
526
|
+
toast = self._get_toast_manager()
|
|
527
|
+
toast.warning("Run Aborted", f"{self._name}: Run was aborted")
|
|
528
|
+
except Exception as ex:
|
|
529
|
+
logger.warning(f"[{self._name}] Failed to show abort toast: {ex}")
|
|
530
|
+
|
|
531
|
+
def _on_exception_toast(self, exception: Exception) -> None:
|
|
532
|
+
"""Show toast notification when a run encounters an error.
|
|
533
|
+
|
|
534
|
+
Args:
|
|
535
|
+
exception: The exception that occurred.
|
|
536
|
+
"""
|
|
537
|
+
if not self._toast_notifications:
|
|
538
|
+
return
|
|
539
|
+
try:
|
|
540
|
+
toast = self._get_toast_manager()
|
|
541
|
+
error_msg = str(exception) if str(exception) else type(exception).__name__
|
|
542
|
+
toast.error("Run Failed", f"{self._name}: {error_msg}")
|
|
543
|
+
except Exception as ex:
|
|
544
|
+
logger.warning(f"[{self._name}] Failed to show exception toast: {ex}")
|
|
545
|
+
|
|
546
|
+
# === Methods to Override ===
|
|
547
|
+
|
|
548
|
+
def pause(self, defer: bool = False) -> None:
|
|
549
|
+
"""Pause execution.
|
|
550
|
+
|
|
551
|
+
Subclasses must override this method.
|
|
552
|
+
|
|
553
|
+
Args:
|
|
554
|
+
defer: If True, pause at next safe point. If False, pause immediately.
|
|
555
|
+
"""
|
|
556
|
+
raise NotImplementedError("Subclasses must implement pause()")
|
|
557
|
+
|
|
558
|
+
def resume(self) -> None:
|
|
559
|
+
"""Resume paused execution.
|
|
560
|
+
|
|
561
|
+
Subclasses must override this method.
|
|
562
|
+
"""
|
|
563
|
+
raise NotImplementedError("Subclasses must implement resume()")
|
|
564
|
+
|
|
565
|
+
def stop(self) -> None:
|
|
566
|
+
"""Request graceful stop at next safe point.
|
|
567
|
+
|
|
568
|
+
Subclasses must override this method.
|
|
569
|
+
"""
|
|
570
|
+
raise NotImplementedError("Subclasses must implement stop()")
|
|
571
|
+
|
|
572
|
+
def abort(self, reason: str = "") -> None:
|
|
573
|
+
"""Abort execution immediately.
|
|
574
|
+
|
|
575
|
+
Subclasses must override this method.
|
|
576
|
+
|
|
577
|
+
Args:
|
|
578
|
+
reason: Optional reason for the abort.
|
|
579
|
+
"""
|
|
580
|
+
raise NotImplementedError("Subclasses must implement abort()")
|
|
581
|
+
|
|
582
|
+
def halt(self) -> None:
|
|
583
|
+
"""Emergency halt - immediately terminate execution.
|
|
584
|
+
|
|
585
|
+
Subclasses must override this method.
|
|
586
|
+
"""
|
|
587
|
+
raise NotImplementedError("Subclasses must implement halt()")
|