ExStorageService.Storage.Lifecycle (ex_storage_service v0.6.4)

Copy Markdown View Source

GenServer that periodically evaluates lifecycle rules for buckets.

Lifecycle rules support object expiration and internal transition to packed storage for cold objects.

Rules are stored in Concord under "lifecycle:{bucket}" as a list of rule maps.

Rule format: %{

id: "rule-id",
prefix: "logs/",          # optional prefix filter
status: "Enabled",        # "Enabled" or "Disabled"
expiration_days: 30,      # delete objects older than N days
transition_days: 7,       # pack objects older than N days
transition_storage_class: "PACKED"

}

Summary

Functions

Returns a specification to start this module under a supervisor.

Delete lifecycle rules for a bucket.

Evaluate rules for a specific bucket. Can be called directly without GenServer.

Evaluate lifecycle rules now (for testing or manual trigger).

Get lifecycle rules for a bucket.

Set lifecycle rules for a bucket.

Check if an object matches any lifecycle expiration rule. Exported for testing.

Check if an object matches any lifecycle transition rule. Exported for testing.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

delete_rules(bucket)

@spec delete_rules(String.t()) :: :ok

Delete lifecycle rules for a bucket.

evaluate_bucket(bucket)

@spec evaluate_bucket(String.t()) :: {:ok, non_neg_integer()}

Evaluate rules for a specific bucket. Can be called directly without GenServer.

evaluate_now(server \\ __MODULE__)

Evaluate lifecycle rules now (for testing or manual trigger).

get_rules(bucket)

@spec get_rules(String.t()) :: {:ok, [map()]} | {:error, :not_found}

Get lifecycle rules for a bucket.

put_rules(bucket, rules)

@spec put_rules(String.t(), [map()]) :: :ok | {:error, term()}

Set lifecycle rules for a bucket.

should_expire?(key, meta, rules, now)

@spec should_expire?(String.t(), map(), [map()], DateTime.t()) :: boolean()

Check if an object matches any lifecycle expiration rule. Exported for testing.

should_transition?(key, meta, rules, now)

@spec should_transition?(String.t(), map(), [map()], DateTime.t()) :: boolean()

Check if an object matches any lifecycle transition rule. Exported for testing.

start_link(opts \\ [])