check / check (push) Waiting to run
Target.MaxRetries (max_retries) becomes Target.MaxAttempts (max_attempts), and the form field, parser and ceiling are renamed to match. The column is NOT NULL and a check constraint refuses a value below 1, so every target, whatever its type, is stored with at least 1. 1 is a single attempt with no circuit breaker; above 1 retries behind the breaker up to that many attempts. Both target forms refuse 0 and less; a blank field on the add target form gives 1, and on the edit form keeps the stored value. The target page shows the plain number, and the README's two paragraphs on 0 against 1 become one sentence. Model: opus-5-5
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
package database
|
|
|
|
// TargetType represents the type of delivery target
|
|
type TargetType string
|
|
|
|
// Target type values.
|
|
const (
|
|
TargetTypeHTTP TargetType = "http"
|
|
TargetTypeDatabase TargetType = "database"
|
|
TargetTypeLog TargetType = "log"
|
|
TargetTypeSlack TargetType = "slack"
|
|
)
|
|
|
|
// Target represents a delivery target for a webhook
|
|
type Target struct {
|
|
BaseModel
|
|
|
|
WebhookID string `gorm:"type:uuid;not null" json:"webhookId"`
|
|
Name string `gorm:"not null" json:"name"`
|
|
Type TargetType `gorm:"not null" json:"type"`
|
|
Active bool `gorm:"default:true" json:"active"`
|
|
|
|
// Configuration fields (JSON stored based on type).
|
|
//
|
|
// json:"-" because the blob holds the target's credential — a
|
|
// Slack incoming-webhook URL, or an http destination whose path
|
|
// segments are the secret. delivery.TargetView is the masking
|
|
// barrier for the HTML path; this tag is the barrier for any
|
|
// handler that marshals the model itself.
|
|
Config string `gorm:"type:text" json:"-"` // JSON configuration
|
|
|
|
// MaxAttempts is how many times an HTTP or Slack target attempts
|
|
// each delivery in all, at least 1. 1 is a single attempt with no
|
|
// circuit breaker; above 1, a failed attempt is retried with
|
|
// backoff behind the breaker. The table's check constraint refuses
|
|
// a target saved with less than 1, whatever its type.
|
|
MaxAttempts int `gorm:"not null;check:max_attempts >= 1" json:"maxAttempts,omitempty"`
|
|
|
|
// Relations. No model marshals the record it belongs to:
|
|
// Webhook.Targets leads back here, and the JSON could loop.
|
|
Webhook Webhook `json:"-"`
|
|
Deliveries []Delivery `json:"deliveries,omitempty"`
|
|
}
|