Skip to content
Merged

Dev #492

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 6 additions & 50 deletions src/primary/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Removed keys_manager import as settings_manager handles API details
from src.primary.state import check_state_reset, calculate_reset_time
from src.primary.stats_manager import check_hourly_cap_exceeded
from src.primary.utils.instance_list_generator import generate_instance_list
# Instance list generator has been removed
from src.primary.scheduler_engine import start_scheduler, stop_scheduler
from src.primary.migrate_configs import migrate_json_configs # Import the migration function
# from src.primary.utils.app_utils import get_ip_address # No longer used here
Expand All @@ -40,8 +40,7 @@
# Hourly cap scheduler thread
hourly_cap_scheduler_thread = None

# Instance list generator thread
instance_list_generator_thread = None
# Instance list generator has been removed

def app_specific_loop(app_type: str) -> None:
"""
Expand Down Expand Up @@ -612,45 +611,9 @@ def hourly_cap_scheduler_loop():

logger.info("Hourly API cap scheduler stopped")

def instance_list_generator_loop():
"""
Main loop for the instance list generator thread
Updates the instance list periodically (every 5 minutes)
"""
interval = 300 # 5 minutes in seconds

logger.debug("Starting instance list generator loop")

while not stop_event.is_set():
try:
# Generate the instance list
instances = generate_instance_list()
logger.debug(f"Generated instance list with {sum(len(apps) for apps in instances.values())} total instances")
except Exception as e:
logger.error(f"Error generating instance list: {e}")

# Wait for next interval or until stop event
stop_event.wait(interval)

logger.debug("Instance list generator loop stopped")
# The instance list generator loop has been removed as it's no longer needed

def start_instance_list_generator():
"""Start the instance list generator thread"""
global instance_list_generator_thread

if instance_list_generator_thread and instance_list_generator_thread.is_alive():
logger.debug("Instance list generator already running")
return

# Create and start the generator thread
instance_list_generator_thread = threading.Thread(
target=instance_list_generator_loop,
name="InstanceListGenerator",
daemon=True
)
instance_list_generator_thread.start()

logger.debug(f"Instance list generator started. Thread is alive: {instance_list_generator_thread.is_alive()}")
# The start_instance_list_generator function has been removed as it's no longer needed

def start_hourly_cap_scheduler():
"""Start the hourly API cap scheduler thread"""
Expand Down Expand Up @@ -701,15 +664,8 @@ def start_huntarr():
except Exception as e:
logger.error(f"Failed to start schedule action engine: {e}")

# Start the instance list generator
try:
# Generate instance list immediately
generate_instance_list()
# Then start the background thread for periodic updates
start_instance_list_generator()
logger.debug("Instance list generator started successfully")
except Exception as e:
logger.error(f"Failed to start instance list generator: {e}")
# Instance list generator has been removed
logger.debug("Instance list generator has been removed and is no longer needed")

# Log initial configuration for all known apps
for app_name in settings_manager.KNOWN_APP_TYPES: # Corrected attribute name
Expand Down
19 changes: 2 additions & 17 deletions src/primary/routes/scheduler_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
# Create blueprint
scheduler_api = Blueprint('scheduler_api', __name__)

# Import instance list generator to access its functions
from src.primary.utils.instance_list_generator import generate_instance_list
# No longer using instance list generator

# Configuration file path
# Use the centralized path configuration
Expand Down Expand Up @@ -93,21 +92,7 @@ def get_scheduler_history():
scheduler_logger.error(error_msg)
return jsonify({"error": error_msg}), 500

@scheduler_api.route('/api/scheduling/list', methods=['GET'])
def get_scheduler_instance_list():
"""Return the list of app instances for the scheduler UI"""
try:
# Generate the instance list (this will create list.json in the scheduling directory)
instances = generate_instance_list()

# Return the generated data directly as JSON
return jsonify(instances)
except Exception as e:
scheduler_logger.error(f"Error generating instance list: {str(e)}")
return jsonify({
'error': f"Failed to generate instance list: {str(e)}",
'order': ['sonarr', 'radarr', 'readarr', 'lidarr', 'whisparr', 'eros']
}), 500
# API route for instance list generation has been removed

@scheduler_api.route('/api/scheduler/save', methods=['POST'])
def save_schedules():
Expand Down
14 changes: 7 additions & 7 deletions src/primary/scheduler_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Scheduler constants
SCHEDULE_CHECK_INTERVAL = 60 # Check schedule every minute
# Use the centralized path configuration
from src.primary.utils.config_paths import SCHEDULER_DIR, CONFIG_PATH
from src.primary.utils.config_paths import SCHEDULER_DIR, CONFIG_PATH, SETTINGS_DIR

# Convert Path object to string for compatibility with os.path functions
SCHEDULE_DIR = str(SCHEDULER_DIR)
Expand Down Expand Up @@ -135,7 +135,7 @@ def execute_action(action_entry):
try:
apps = ['sonarr', 'radarr', 'lidarr', 'readarr', 'whisparr', 'eros']
for app in apps:
config_file = os.path.join(str(CONFIG_PATH), f"{app}.json")
config_file = os.path.join(str(SETTINGS_DIR), f"{app}.json")
if os.path.exists(config_file):
with open(config_file, 'r') as f:
config_data = json.load(f)
Expand All @@ -162,7 +162,7 @@ def execute_action(action_entry):
message = f"Executing disable action for {app_type}"
scheduler_logger.info(message)
try:
config_file = os.path.join(str(CONFIG_PATH), f"{app_type}.json")
config_file = os.path.join(str(SETTINGS_DIR), f"{app_type}.json")
if os.path.exists(config_file):
with open(config_file, 'r') as f:
config_data = json.load(f)
Expand Down Expand Up @@ -195,7 +195,7 @@ def execute_action(action_entry):
try:
apps = ['sonarr', 'radarr', 'lidarr', 'readarr', 'whisparr', 'eros']
for app in apps:
config_file = os.path.join(str(CONFIG_PATH), f"{app}.json")
config_file = os.path.join(str(SETTINGS_DIR), f"{app}.json")
if os.path.exists(config_file):
with open(config_file, 'r') as f:
config_data = json.load(f)
Expand All @@ -222,7 +222,7 @@ def execute_action(action_entry):
message = f"Executing enable action for {app_type}"
scheduler_logger.info(message)
try:
config_file = os.path.join(str(CONFIG_PATH), f"{app_type}.json")
config_file = os.path.join(str(SETTINGS_DIR), f"{app_type}.json")
if os.path.exists(config_file):
with open(config_file, 'r') as f:
config_data = json.load(f)
Expand Down Expand Up @@ -262,7 +262,7 @@ def execute_action(action_entry):
try:
apps = ['sonarr', 'radarr', 'lidarr', 'readarr', 'whisparr', 'eros']
for app in apps:
config_file = os.path.join(str(CONFIG_PATH), f"{app}.json")
config_file = os.path.join(str(SETTINGS_DIR), f"{app}.json")
if os.path.exists(config_file):
with open(config_file, 'r') as f:
config_data = json.load(f)
Expand All @@ -281,7 +281,7 @@ def execute_action(action_entry):
message = f"Setting API cap for {app_type} to {api_limit}"
scheduler_logger.info(message)
try:
config_file = os.path.join(str(CONFIG_PATH), f"{app_type}.json")
config_file = os.path.join(str(SETTINGS_DIR), f"{app_type}.json")
if os.path.exists(config_file):
with open(config_file, 'r') as f:
config_data = json.load(f)
Expand Down
2 changes: 1 addition & 1 deletion src/primary/utils/config_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
SETTINGS_DIR = CONFIG_PATH
STATEFUL_DIR = CONFIG_PATH / "stateful"
RESET_DIR = CONFIG_PATH / "reset"
SCHEDULER_DIR = CONFIG_PATH / "scheduling"
SCHEDULER_DIR = CONFIG_PATH / "scheduler"
SWAPARR_STATE_DIR = CONFIG_PATH / "swaparr"

# Create essential directories
Expand Down
141 changes: 0 additions & 141 deletions src/primary/utils/instance_list_generator.py

This file was deleted.

2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.8
7.0.9