1. import json
  2. def create_collection_config(collection_name, max_items, max_size_bytes):
  3. """
  4. Creates a configuration dictionary for a short-lived collection with hard-coded limits.
  5. Args:
  6. collection_name (str): The name of the collection.
  7. max_items (int): The maximum number of items allowed in the collection.
  8. max_size_bytes (int): The maximum size of the collection in bytes.
  9. Returns:
  10. dict: A dictionary containing the collection configuration.
  11. """
  12. config = {
  13. "collection_name": collection_name,
  14. "max_items": max_items,
  15. "max_size_bytes": max_size_bytes
  16. }
  17. return config
  18. def write_config_to_json(config, filepath):
  19. """
  20. Writes the collection configuration to a JSON file.
  21. Args:
  22. config (dict): The collection configuration dictionary.
  23. filepath (str): The path to the JSON file.
  24. """
  25. with open(filepath, 'w') as f:
  26. json.dump(config, f, indent=4)
  27. if __name__ == '__main__':
  28. # Example usage
  29. collection_name = "temp_data"
  30. max_items = 100
  31. max_size_bytes = 102400 # 100KB
  32. config = create_collection_config(collection_name, max_items, max_size_bytes)
  33. config_filepath = "temp_collection_config.json"
  34. write_config_to_json(config, config_filepath)

Add your comment