-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.py
More file actions
63 lines (47 loc) · 2.02 KB
/
Copy pathruntime.py
File metadata and controls
63 lines (47 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Public runtime layout contract for consumer profiles."""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
__all__ = ["RetentionPolicy", "RuntimeLayout"]
DEFAULT_MAX_BUNDLES = 20
DEFAULT_MAX_AGE_SECONDS = 30 * 24 * 60 * 60
DEFAULT_MAX_TOTAL_BYTES = 512 * 1024 * 1024
@dataclass(frozen=True)
class RetentionPolicy:
"""Bounds for complete invocation bundles.
``None`` disables an individual bound. Protected bundles (the active
invocation, inherited parent bundles, and bundles marked ``preserve`` in
``run.json``) are always retained, even when that means a bound cannot be
met exactly.
"""
max_bundles: int | None = None
max_age_seconds: float | None = None
max_total_bytes: int | None = None
@classmethod
def safe_defaults(cls) -> RetentionPolicy:
"""Return the bounded policy used by a durable :class:`App` by default."""
return cls(
max_bundles=DEFAULT_MAX_BUNDLES,
max_age_seconds=DEFAULT_MAX_AGE_SECONDS,
max_total_bytes=DEFAULT_MAX_TOTAL_BYTES,
)
def __post_init__(self) -> None:
if self.max_bundles is not None and self.max_bundles < 1:
raise ValueError("max_bundles must be greater than 0 when set.")
if self.max_age_seconds is not None and self.max_age_seconds < 0:
raise ValueError("max_age_seconds must be non-negative when set.")
if self.max_total_bytes is not None and self.max_total_bytes < 1:
raise ValueError("max_total_bytes must be greater than 0 when set.")
@dataclass(frozen=True)
class RuntimeLayout:
"""Filesystem locations owned by one base-cli runtime binding.
Profiles may construct this value themselves or return it from a custom
runtime resolver. The layout deliberately contains paths only; ownership,
retention, and persistence policy remain profile decisions.
"""
owner_root: Path
run_root: Path
state_dir: Path
log_dir: Path
cache_dir: Path
temp_dir: Path