Skip to content

Commit 4020118

Browse files
committed
Fix LoggerManager and webapp URL imports
- Fix LoggerManager usage: use LoggerManager().get_logger() instead of LoggerManager.get_logger() - Fix webapp URL import: use get_absolute_userpod_api_url() instead of non-existent get_webapp_url() - All imports and functionality tests now pass
1 parent b525a20 commit 4020118

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

deepnote_toolkit/execution_timeout.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import requests
1212
from IPython.core.interactiveshell import ExecutionInfo, ExecutionResult
1313

14-
from .get_webapp_url import get_webapp_url
14+
from .get_webapp_url import get_absolute_userpod_api_url
1515
from .logging import LoggerManager
1616

1717

@@ -34,7 +34,7 @@ def __init__(
3434
timeout_seconds: Seconds after which to consider execution stuck (default: 300s = 5min)
3535
enable_auto_interrupt: Whether to automatically interrupt stuck executions (default: False)
3636
"""
37-
self.logger = LoggerManager.get_logger("execution_timeout")
37+
self.logger = LoggerManager().get_logger()
3838
self.warning_threshold = warning_threshold_seconds
3939
self.timeout_threshold = timeout_seconds
4040
self.enable_auto_interrupt = enable_auto_interrupt
@@ -152,19 +152,8 @@ def _report_to_webapp(
152152
warning: Whether this is a warning (True) or timeout (False)
153153
"""
154154
try:
155-
webapp_url = get_webapp_url()
156-
project_id = os.getenv("DEEPNOTE_PROJECT_ID")
157-
158-
if not webapp_url or not project_id:
159-
self.logger.debug(
160-
"Webapp URL or project ID not available, skipping report"
161-
)
162-
return
163-
164-
endpoint = (
165-
"warning" if warning else "timeout"
166-
)
167-
url = f"{webapp_url}/userpod-api/{project_id}/execution/{endpoint}"
155+
endpoint = "warning" if warning else "timeout"
156+
url = get_absolute_userpod_api_url(f"execution/{endpoint}")
168157

169158
payload = {
170159
"duration": duration,
@@ -209,7 +198,7 @@ def setup_execution_timeout_monitor(
209198

210199
ip = get_ipython()
211200
if ip is None:
212-
LoggerManager.get_logger("execution_timeout").warning(
201+
LoggerManager().get_logger().warning(
213202
"IPython instance not available, skipping timeout monitor setup"
214203
)
215204
return
@@ -224,14 +213,14 @@ def setup_execution_timeout_monitor(
224213
ip.events.register("pre_execute", _timeout_monitor.on_pre_execute)
225214
ip.events.register("post_execute", _timeout_monitor.on_post_execute)
226215

227-
LoggerManager.get_logger("execution_timeout").info(
216+
LoggerManager().get_logger().info(
228217
"Execution timeout monitor initialized: warning=%ds, timeout=%ds, auto_interrupt=%s",
229218
warning_threshold_seconds,
230219
timeout_seconds,
231220
enable_auto_interrupt,
232221
)
233222

234223
except Exception as e: # pylint: disable=broad-exception-caught
235-
LoggerManager.get_logger("execution_timeout").error(
224+
LoggerManager().get_logger().error(
236225
"Failed to set up timeout monitor: %s", e
237226
)

deepnote_toolkit/execution_tracking.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ExecutionTracker:
1717
"""Tracks execution state of notebook cells."""
1818

1919
def __init__(self):
20-
self.logger = LoggerManager.get_logger("execution_tracker")
20+
self.logger = LoggerManager().get_logger()
2121
self.current_execution: Optional[Dict[str, Any]] = None
2222
self.execution_count = 0
2323

@@ -109,7 +109,7 @@ def setup_execution_tracking() -> None:
109109

110110
ip = get_ipython()
111111
if ip is None:
112-
LoggerManager.get_logger("execution_tracking").warning(
112+
LoggerManager().get_logger().warning(
113113
"IPython instance not available, skipping execution tracking setup"
114114
)
115115
return
@@ -122,11 +122,11 @@ def setup_execution_tracking() -> None:
122122
ip.events.register("pre_run_cell", _execution_tracker.on_pre_run_cell)
123123
ip.events.register("post_run_cell", _execution_tracker.on_post_run_cell)
124124

125-
LoggerManager.get_logger("execution_tracking").info(
125+
LoggerManager().get_logger().info(
126126
"Execution tracking initialized successfully"
127127
)
128128

129129
except Exception as e: # pylint: disable=broad-exception-caught
130-
LoggerManager.get_logger("execution_tracking").error(
130+
LoggerManager().get_logger().error(
131131
"Failed to set up execution tracking: %s", e
132132
)

0 commit comments

Comments
 (0)