check / check (push) Successful in 3m27s
A database target's rotation setting (none, monthly, daily or hourly) puts the UTC period of each event's receive time in its archive file name, so each file holds exactly its period's events. It is on the new webhook page and both target forms, and shown in the target list. Renames move every one of a target's files and move them all back if one fails. The sweep prunes one file at a time under the target's lock and deletes a rotated file it leaves empty. Download opens one file at a time, oldest period first, finding each again under the target's current name. The target list names the current file and totals all of them. Model: opus-5-5
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package handlers
|
|
|
|
const (
|
|
// archiveExpiryNever is the archive expiry that keeps archived
|
|
// events forever. A stored empty expiry means the same.
|
|
archiveExpiryNever = "never"
|
|
|
|
// tmplKeyArchiveExpiryChoices is the template data key for the
|
|
// entries of a page's archive expiry select.
|
|
tmplKeyArchiveExpiryChoices = "ArchiveExpiryChoices"
|
|
)
|
|
|
|
// archiveChoice is one entry of a database target's archive expiry
|
|
// or archive rotation select: the value stored, the label shown, and
|
|
// whether the select starts on it.
|
|
type archiveChoice struct {
|
|
Value string
|
|
Label string
|
|
Selected bool
|
|
}
|
|
|
|
// archiveExpiryChoices lists the archive expiries offered by the new
|
|
// webhook page, the add target form and the target edit form.
|
|
func archiveExpiryChoices() []archiveChoice {
|
|
return []archiveChoice{
|
|
{Value: archiveExpiryNever, Label: archiveExpiryNever},
|
|
{Value: "1h", Label: "1h"},
|
|
{Value: "12h", Label: "12h"},
|
|
{Value: "24h", Label: "24h"},
|
|
{Value: "720h", Label: "30d"},
|
|
{Value: "2160h", Label: "90d"},
|
|
{Value: "8760h", Label: "365d"},
|
|
}
|
|
}
|
|
|
|
// archiveExpiryOptions returns the choices with expiry selected; an
|
|
// empty expiry selects never. An expiry that is not one of the
|
|
// choices comes first as its own selected entry, so saving the form
|
|
// unchanged keeps it.
|
|
func archiveExpiryOptions(expiry string) []archiveChoice {
|
|
if expiry == "" {
|
|
expiry = archiveExpiryNever
|
|
}
|
|
|
|
options := archiveExpiryChoices()
|
|
|
|
for i := range options {
|
|
if options[i].Value == expiry {
|
|
options[i].Selected = true
|
|
|
|
return options
|
|
}
|
|
}
|
|
|
|
own := archiveChoice{Value: expiry, Label: expiry, Selected: true}
|
|
|
|
return append([]archiveChoice{own}, options...)
|
|
}
|