ReusePolicy
Configure a task environment for container reuse across multiple task invocations.
When environment creation is expensive relative to task runtime, reusable containers keep a pool of warm containers ready, avoiding cold-start overhead. The Python process may be reused by subsequent task invocations.
Attributes
| Attribute | Type | Description |
|---|---|---|
| replicas | Union[int, Tuple[int, int]] = 2 | Number of container replicas to maintain. Can be a fixed integer count or a tuple specifying an auto-scaling range (min, max). Default is 2. A minimum of 2 replicas is recommended to avoid starvation when the parent task occupies one replica. |
| idle_ttl | Union[int, timedelta] = 30 | Environment-level idle timeout, specified as seconds (int) or timedelta, which shuts down all replicas when the entire environment has been idle for this duration. Minimum 30 seconds. Default is 30 seconds. |
| concurrency | int = 1 | Maximum concurrent tasks per replica; values greater than 1 are only supported for async tasks. Default is 1. |
| scaledown_ttl | Union[int, timedelta] = 30 | Per-replica scale-down delay, specified as seconds (int) or timedelta, which is the minimum time to wait before removing an individual idle replica to prevent rapid scale-down during task bursts. Default is 30 seconds. |
Constructor
Signature
def ReusePolicy(
replicas: Union[int, Tuple[int, int]] = 2,
idle_ttl: Union[int, timedelta] = 30,
concurrency: int = 1,
scaledown_ttl: Union[int, timedelta] = 30
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| replicas | Union[int, Tuple[int, int]] = 2 | Number of container replicas to maintain. - int: Fixed replica count, always running (e.g., replicas=3). - tuple(min, max): Auto-scaling range (e.g., replicas=(1, 5)). Scales between min and max based on demand. Default is 2. A minimum of 2 replicas is recommended to avoid starvation when the parent task occupies one replica. |
| idle_ttl | Union[int, timedelta] = 30 | Environment-level idle timeout — shuts down all replicas when the entire environment has been idle for this duration. Specified as seconds (int) or timedelta. Minimum 30 seconds. Default is 30 seconds. |
| concurrency | int = 1 | Maximum concurrent tasks per replica. Values greater than 1 are only supported for async tasks. Default is 1. |
| scaledown_ttl | Union[int, timedelta] = 30 | Per-replica scale-down delay — minimum time to wait before removing an individual idle replica. Prevents rapid scale-down when tasks arrive in bursts. Specified as seconds (int) or timedelta. Default is 30 seconds. Note the distinction: idle_ttl controls when the whole environment shuts down; scaledown_ttl controls when individual replicas are removed during auto-scaling. |
Methods
min_replicas()
@classmethod
def min_replicas() - > int
Returns the minimum number of replicas.
Returns
| Type | Description |
|---|---|
int | The minimum number of replicas configured for the reuse policy. |
get_scaledown_ttl()
@classmethod
def get_scaledown_ttl() - > timedelta | None
Returns the scaledown TTL as a timedelta. If scaledown_ttl is not set, returns None.
Returns
| Type | Description |
|---|---|
| `timedelta | None` |
max_replicas()
@classmethod
def max_replicas() - > int
Returns the maximum number of replicas.
Returns
| Type | Description |
|---|---|
int | The maximum number of replicas configured for the reuse policy. |