diff --git a/cluster/v9_advanced_coordinator.py b/cluster/v9_advanced_coordinator.py index 3da60fe..31b3fc1 100755 --- a/cluster/v9_advanced_coordinator.py +++ b/cluster/v9_advanced_coordinator.py @@ -64,6 +64,29 @@ def send_telegram_message(message: str): except Exception as e: print(f"⚠️ Error sending Telegram notification: {e}") + +def is_worker_allowed_to_run(worker_name: str) -> bool: + """Check if worker is allowed to run based on time restrictions""" + worker = WORKERS[worker_name] + + # If no time restriction, always allowed + if not worker.get('time_restricted', False): + return True + + # Check current hour (local time) + current_hour = datetime.now().hour + start_hour = worker['allowed_start_hour'] + end_hour = worker['allowed_end_hour'] + + # Handle time range that crosses midnight (e.g., 19:00 - 06:00) + if start_hour > end_hour: + # Allowed if current hour >= start OR current hour < end + allowed = current_hour >= start_hour or current_hour < end_hour + else: + # Normal range (e.g., 8:00 - 17:00) + allowed = start_hour <= current_hour < end_hour + + return allowed def signal_handler(sig, frame): """Handle termination signals""" message = (