import json
import os
def load_task_queue_config(config_file="task_queue_config.json"):
"""Loads task queue configuration from a JSON file."""
try:
with open(config_file, "r") as f:
config = json.load(f)
return config
except FileNotFoundError:
print(f"Error: Configuration file '{config_file}' not found.")
return {}
except json.JSONDecodeError:
print(f"Error: Invalid JSON format in '{config_file}'.")
return {}
def replace_task_queues(config):
"""Replaces task queues in a local utility based on the configuration."""
# Example usage - replace with your actual utility replacement logic
if not config:
print("No configuration loaded. Skipping replacement.")
return
# Assuming 'task_queues' is a key in the config file
if 'task_queues' in config:
task_queues = config['task_queues']
# Simulate replacing task queues in a local utility (replace with actual logic)
for module, queue in task_queues.items():
try:
# Example: Modify a file or environment variable
with open(module, "w") as f:
f.write(f"Using queue: {queue}\n")
print(f"Replaced task queue in {module} with {queue}")
except Exception as e:
print(f"Error replacing queue in {module}: {e}")
else:
print("No 'task_queues' section found in configuration.")
if __name__ == "__main__":
# Example usage
config = load_task_queue_config()
replace_task_queues(config)
Add your comment