Coverage for src/dataknobs_fsm/storage/file.py: 36%

14 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-20 16:46 -0600

1"""File storage backend for execution history. 

2 

3This is a thin wrapper around UnifiedDatabaseStorage that uses 

4dataknobs_data's file backend. 

5""" 

6 

7from dataknobs_fsm.storage.base import StorageBackend, StorageConfig, StorageFactory 

8from dataknobs_fsm.storage.database import UnifiedDatabaseStorage 

9 

10 

11class FileStorage(UnifiedDatabaseStorage): 

12 """File storage implementation using dataknobs_data's file backend. 

13  

14 This storage backend uses dataknobs_data's AsyncFileDatabase which 

15 stores records as JSON or YAML files with support for: 

16 - Directory-based organization 

17 - File rotation policies 

18 - Compression 

19 - Indexing via metadata files 

20 """ 

21 

22 def __init__(self, config: StorageConfig): 

23 """Initialize file storage. 

24  

25 Args: 

26 config: Storage configuration. 

27 """ 

28 # Ensure we use the file backend 

29 if 'type' not in config.connection_params: 

30 config.connection_params['type'] = 'file' 

31 

32 # Set default file path if not provided 

33 if 'path' not in config.connection_params: 

34 config.connection_params['path'] = './fsm_history' 

35 

36 # Set file format (json or yaml) 

37 if 'format' not in config.connection_params: 

38 config.connection_params['format'] = 'json' 

39 

40 # Enable compression by default for file storage 

41 if 'compress' not in config.connection_params: 

42 config.connection_params['compress'] = config.compression 

43 

44 super().__init__(config) 

45 

46 

47# Register file backend 

48StorageFactory.register(StorageBackend.FILE, FileStorage)