Skip to content

feat: add custom Duration type for config values#989

Open
tmchow wants to merge 1 commit intogetprobo:mainfrom
tmchow:osc/234-custom-duration-type
Open

feat: add custom Duration type for config values#989
tmchow wants to merge 1 commit intogetprobo:mainfrom
tmchow:osc/234-custom-duration-type

Conversation

@tmchow
Copy link
Copy Markdown

@tmchow tmchow commented Apr 3, 2026

Adds a Duration type in pkg/duration that wraps time.Duration and unmarshals from both integer seconds (backward compatible) and Go duration strings like "30s", "5m", "1h".

Replaces the raw int fields in WebhookConfig and SlackConfig with the new type. Removes manual time.Duration(x) * time.Second conversions at use sites in probod.go.

The new type handles backward compatibility: existing configs that use integer seconds (e.g. 86400) continue to work. New configs can use readable strings (e.g. "24h").

Changes

  • pkg/duration/duration.go: Duration type with MarshalJSON, UnmarshalJSON, String()
  • pkg/duration/duration_test.go: tests for int, string, roundtrip, and invalid inputs
  • pkg/probod/notifications_config.go: WebhookConfig fields updated
  • pkg/probod/slack_config.go: SlackConfig.SenderInterval updated
  • pkg/probod/probod.go: removed manual second conversions
  • pkg/bootstrap/builder.go: env parsing handles both int and string durations
  • pkg/bootstrap/builder_test.go: updated assertions

Closes #234


Summary by cubic

Introduce a custom Duration type for config values, allowing both integer seconds and Go-style duration strings, and use it for Slack/Webhook intervals and TTL. This keeps existing configs working, simplifies parsing, and removes manual time conversions. Closes #234.

  • New Features

    • Added pkg/duration with JSON marshal/unmarshal supporting ints (seconds) and strings like "30s", "5m", "1h".
    • Replaced int with duration.Duration in SlackConfig.SenderInterval, WebhookConfig.SenderInterval, and WebhookConfig.CacheTTL.
    • Updated pkg/bootstrap/builder to parse env vars as either ints or duration strings; set defaults to 60s, 5s, and 24h.
    • Removed time.Second multiplications in probod.go; use time.Duration(cfgValue) directly.
  • Migration

    • No breaking changes: existing JSON/env ints (e.g., 86400) still work; strings (e.g., "24h") are now supported.
    • If any external tooling expects numeric JSON for these fields, update it to accept string durations.

Written for commit 9735795. Summary will update on new commits.

Create a Duration type in pkg/duration that wraps time.Duration and
unmarshals from both integer seconds (backward compatible) and Go
duration strings like "30s" or "1h".

Replace raw int fields in WebhookConfig and SlackConfig with the new
type. Remove manual time.Duration multiplication at use sites.

Closes getprobo#234
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create custom duration type

1 participant