Store artifacts for a program Args: program_id: ID of the program artifacts: Dictionary of artifact name to content
(self, program_id: str, artifacts: Dict[str, Union[str, bytes]])
| 2333 | # Artifact storage and retrieval methods |
| 2334 | |
| 2335 | def store_artifacts(self, program_id: str, artifacts: Dict[str, Union[str, bytes]]) -> None: |
| 2336 | """ |
| 2337 | Store artifacts for a program |
| 2338 | |
| 2339 | Args: |
| 2340 | program_id: ID of the program |
| 2341 | artifacts: Dictionary of artifact name to content |
| 2342 | """ |
| 2343 | if not artifacts: |
| 2344 | return |
| 2345 | |
| 2346 | program = self.get(program_id) |
| 2347 | if not program: |
| 2348 | logger.warning(f"Cannot store artifacts: program {program_id} not found") |
| 2349 | return |
| 2350 | |
| 2351 | # Check if artifacts are enabled via env var (default to true) |
| 2352 | artifacts_enabled = os.environ.get("ENABLE_ARTIFACTS", "true").lower() == "true" |
| 2353 | if not artifacts_enabled: |
| 2354 | logger.debug("Artifacts disabled, skipping storage") |
| 2355 | return |
| 2356 | |
| 2357 | # Split artifacts by size (store small in JSON, large on disk) |
| 2358 | small_artifacts = {} |
| 2359 | large_artifacts = {} |
| 2360 | size_threshold = getattr(self.config, "artifact_size_threshold", 32 * 1024) # 32KB default |
| 2361 | |
| 2362 | for key, value in artifacts.items(): |
| 2363 | size = self._get_artifact_size(value) |
| 2364 | if size <= size_threshold: |
| 2365 | small_artifacts[key] = value |
| 2366 | else: |
| 2367 | large_artifacts[key] = value |
| 2368 | |
| 2369 | # Store small artifacts as JSON |
| 2370 | if small_artifacts: |
| 2371 | program.artifacts_json = json.dumps(small_artifacts, default=self._artifact_serializer) |
| 2372 | logger.debug(f"Stored {len(small_artifacts)} small artifacts for program {program_id}") |
| 2373 | |
| 2374 | # Store large artifacts to disk |
| 2375 | if large_artifacts: |
| 2376 | artifact_dir = self._create_artifact_dir(program_id) |
| 2377 | program.artifact_dir = artifact_dir |
| 2378 | for key, value in large_artifacts.items(): |
| 2379 | self._write_artifact_file(artifact_dir, key, value) |
| 2380 | logger.debug(f"Stored {len(large_artifacts)} large artifacts for program {program_id}") |
| 2381 | |
| 2382 | def get_artifacts(self, program_id: str) -> Dict[str, Union[str, bytes]]: |
| 2383 | """ |
no test coverage detected