88
99import logging
1010import threading
11+ import time
12+ import uuid
1113from collections .abc import Callable
14+ from datetime import datetime , timezone
1215from enum import Enum
1316from pathlib import Path
1417from typing import TYPE_CHECKING , Any
1518
16- from rpaforge import config
19+ from rpaforge . config import get_runs_dir
1720from rpaforge .core .audit import RunRecord , StepRecord
1821from rpaforge .core .execution import (
1922 ActivityCall ,
@@ -318,8 +321,6 @@ def _handle_activity_start(self, activity: ActivityCall) -> None:
318321 self ._current_depth = len (self ._call_stack ) + 1
319322
320323 # Start tracking time for audit logging
321- import time
322-
323324 self ._step_start_time = time .time ()
324325
325326 frame = CallFrame (
@@ -356,8 +357,6 @@ def _handle_activity_end(self, result: dict[str, Any] | None = None) -> None:
356357 frame = self ._call_stack .pop ()
357358 # Record step completion for audit log.
358359 if self ._step_start_time is not None :
359- import time
360-
361360 duration_ms = int ((time .time () - self ._step_start_time ) * 1000 )
362361 node_id = frame .node_id or ""
363362 result = result or {}
@@ -482,9 +481,6 @@ def _notify_resume(self) -> None:
482481
483482 def _init_audit_run (self , process : Process ) -> None :
484483 """Initialize audit run record."""
485- import uuid
486- from datetime import datetime , timezone
487-
488484 run_id = str (uuid .uuid4 ())
489485 now = datetime .now (timezone .utc ).isoformat ()
490486 self ._current_run = RunRecord (
@@ -501,8 +497,6 @@ def _finalize_audit_run(self, result: ExecutionResult) -> None:
501497 if not self ._current_run :
502498 return
503499
504- from datetime import datetime , timezone
505-
506500 now = datetime .now (timezone .utc ).isoformat ()
507501 self ._current_run .finished_at = now
508502
@@ -516,7 +510,7 @@ def _finalize_audit_run(self, result: ExecutionResult) -> None:
516510
517511 # Save to disk
518512 try :
519- runs_dir = config . get_runs_dir ()
513+ runs_dir = get_runs_dir ()
520514 self ._last_audit_path = self ._current_run .save (runs_dir )
521515 self ._cleanup_old_runs (runs_dir , keep = 50 )
522516 except Exception as e :
0 commit comments