diff --git a/README.md b/README.md index a498df2..dc8f4fa 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Successor to the `*-keepalive` family: one binary, one image, six datastore adap By default, keepalive reads the first config file it finds: `config.yml`, `config.yaml`, `/config.yml`, then `/config.yaml`. One deployment can keep any number of services alive. ```yaml +# Default interval for every service. interval: 1m counter_key: counter @@ -21,6 +22,8 @@ services: namespace: keepalive - adapter: valkey + # One service can override the global interval. + interval: 30s config: url: valkey://default@valkey-a.example.com:6379 @@ -50,7 +53,11 @@ services: `name` is optional. When omitted, keepalive generates a name from `adapter` and the connection host, such as `redis-redis-a-example-com`. Duplicate generated names get suffixes like `redis-redis-a-example-com-2`. -`interval` and `counter_key` can be set globally or per service. Per-service values override global values. +`interval` at the root sets the default schedule for every service and defaults to `1m`. +`interval` inside a service overrides that default only for that service. +In the example above, every service runs every `1m` except `valkey`, which runs every `30s`. + +`counter_key` can be set globally or per service. Per-service values override global values. ## Supported adapters diff --git a/config.example.yml b/config.example.yml index 1f7cca6..3276f5a 100644 --- a/config.example.yml +++ b/config.example.yml @@ -1,4 +1,4 @@ -# Optional defaults shared by every service. +# Optional default interval shared by every service. interval: 1m counter_key: counter @@ -9,6 +9,8 @@ services: namespace: keepalive - adapter: valkey + # Example: this service runs every 30s while others use the root interval. + interval: 30s config: url: valkey://default@valkey-a.example.com:6379 diff --git a/config_test.go b/config_test.go index 727ac00..8a04d38 100644 --- a/config_test.go +++ b/config_test.go @@ -42,6 +42,15 @@ func TestConfigExampleYMLParses(t *testing.T) { t.Fatalf("services[%d].AdapterType = %q, want %q", i, services[i].AdapterType, want) } } + if services[0].Interval != time.Minute { + t.Fatalf("services[0].Interval = %s, want 1m", services[0].Interval) + } + if services[1].Interval != 30*time.Second { + t.Fatalf("services[1].Interval = %s, want 30s", services[1].Interval) + } + if services[2].Interval != time.Minute { + t.Fatalf("services[2].Interval = %s, want 1m", services[2].Interval) + } } func TestFirstExistingConfigFileFindsYMLFallback(t *testing.T) {