mirror of
https://github.com/johndoe6345789/AutoMetabuilder.git
synced 2026-04-24 13:54:59 +00:00
Address code review feedback: improve encapsulation and caching
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
"""Workflow plugin: get current bot execution status."""
|
||||
from autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot import (
|
||||
_bot_process,
|
||||
_mock_running,
|
||||
_current_run_config,
|
||||
)
|
||||
from autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot import get_bot_state
|
||||
|
||||
|
||||
def run(_runtime, _inputs):
|
||||
@@ -15,8 +11,4 @@ def run(_runtime, _inputs):
|
||||
- config: dict - Current run configuration (empty if not running)
|
||||
- process: object - Bot process object (or None if not running)
|
||||
"""
|
||||
return {
|
||||
"is_running": _bot_process is not None or _mock_running,
|
||||
"config": _current_run_config,
|
||||
"process": _bot_process,
|
||||
}
|
||||
return get_bot_state()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""Workflow plugin: reset bot execution state."""
|
||||
from autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot import _reset_run_state
|
||||
from autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot import reset_bot_state
|
||||
|
||||
|
||||
def run(_runtime, _inputs):
|
||||
@@ -9,5 +9,5 @@ def run(_runtime, _inputs):
|
||||
Dictionary with:
|
||||
- reset: bool - Always True to indicate state was reset
|
||||
"""
|
||||
_reset_run_state()
|
||||
reset_bot_state()
|
||||
return {"reset": True}
|
||||
|
||||
@@ -15,9 +15,29 @@ _current_run_config = {}
|
||||
|
||||
def _reset_run_state() -> None:
|
||||
"""Reset the bot run state."""
|
||||
global _bot_process, _current_run_config
|
||||
global _bot_process, _current_run_config, _mock_running
|
||||
_bot_process = None
|
||||
_current_run_config = {}
|
||||
_mock_running = False
|
||||
|
||||
|
||||
def get_bot_state():
|
||||
"""Get the current bot state (public interface).
|
||||
|
||||
Returns:
|
||||
dict: Bot state with keys: is_running, config, process
|
||||
"""
|
||||
return {
|
||||
"is_running": _bot_process is not None or _mock_running,
|
||||
"config": _current_run_config,
|
||||
"process": _bot_process,
|
||||
}
|
||||
|
||||
|
||||
def reset_bot_state():
|
||||
"""Reset the bot state (public interface)."""
|
||||
_reset_run_state()
|
||||
|
||||
|
||||
|
||||
def _run_bot_task(mode: str, iterations: int, yolo: bool, stop_at_mvp: bool) -> None:
|
||||
|
||||
@@ -5,13 +5,19 @@ from autometabuilder.loaders.metadata_loader import load_metadata
|
||||
from autometabuilder.workflow.plugin_loader import load_plugin_callable
|
||||
from autometabuilder.roadmap_utils import is_mvp_reached
|
||||
|
||||
# Cache the get_bot_status plugin callable to avoid repeated loading
|
||||
_get_bot_status_plugin = None
|
||||
|
||||
|
||||
def run(runtime, _inputs):
|
||||
"""Create and return the context routes blueprint."""
|
||||
# Load the control.get_bot_status plugin
|
||||
get_bot_status_plugin = load_plugin_callable(
|
||||
"autometabuilder.workflow.plugins.control.control_get_bot_status.control_get_bot_status.run"
|
||||
)
|
||||
global _get_bot_status_plugin
|
||||
|
||||
# Load the control.get_bot_status plugin once
|
||||
if _get_bot_status_plugin is None:
|
||||
_get_bot_status_plugin = load_plugin_callable(
|
||||
"autometabuilder.workflow.plugins.control.control_get_bot_status.control_get_bot_status.run"
|
||||
)
|
||||
|
||||
context_bp = Blueprint("context", __name__)
|
||||
|
||||
@@ -34,7 +40,7 @@ def run(runtime, _inputs):
|
||||
packages = load_workflow_packages()
|
||||
|
||||
# Get bot status from plugin
|
||||
bot_status = get_bot_status_plugin(runtime, {})
|
||||
bot_status = _get_bot_status_plugin(runtime, {})
|
||||
|
||||
return {
|
||||
"logs": get_recent_logs(),
|
||||
|
||||
@@ -2,13 +2,19 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
from autometabuilder.workflow.plugin_loader import load_plugin_callable
|
||||
|
||||
# Cache the start_bot plugin callable to avoid repeated loading
|
||||
_start_bot_plugin = None
|
||||
|
||||
|
||||
def run(runtime, _inputs):
|
||||
"""Create and return the run routes blueprint."""
|
||||
# Load the control.start_bot plugin
|
||||
start_bot_plugin = load_plugin_callable(
|
||||
"autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot.run"
|
||||
)
|
||||
global _start_bot_plugin
|
||||
|
||||
# Load the control.start_bot plugin once
|
||||
if _start_bot_plugin is None:
|
||||
_start_bot_plugin = load_plugin_callable(
|
||||
"autometabuilder.workflow.plugins.control.control_start_bot.control_start_bot.run"
|
||||
)
|
||||
|
||||
run_bp = Blueprint("run", __name__)
|
||||
|
||||
@@ -21,7 +27,7 @@ def run(runtime, _inputs):
|
||||
stop_at_mvp = payload.get("stop_at_mvp", False)
|
||||
|
||||
# Call the control.start_bot plugin
|
||||
result = start_bot_plugin(runtime, {
|
||||
result = _start_bot_plugin(runtime, {
|
||||
"mode": mode,
|
||||
"iterations": iterations,
|
||||
"yolo": yolo,
|
||||
|
||||
Reference in New Issue
Block a user