sla

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricFirstResponse = "first_response"
	MetricResolution    = "resolution"
	MetricNextResponse  = "next_response"
	MetricAll           = "all"

	NotificationTypeWarning = "warning"
	NotificationTypeBreach  = "breach"
)

Variables

View Source
var (
	ErrInvalidSLADuration = fmt.Errorf("invalid SLA duration")
	ErrMaxIterations      = fmt.Errorf("sla: exceeded maximum iterations - check configuration")
	ErrInvalidTime        = fmt.Errorf("invalid time")
)
View Source
var (
	ErrUnmetSLAEventAlreadyExists = errors.New("unmet SLA event already exists, cannot create a new one for the same applied SLA and metric")
	ErrLatestSLAEventNotFound     = errors.New("latest SLA event not found for the applied SLA and metric")
)

Functions

This section is empty.

Types

type Breaches

type Breaches struct {
	FirstResponse null.Time
	Resolution    null.Time
	NextResponse  null.Time
}

Breaches holds the breach timestamps for an SLA policy.

type Deadlines

type Deadlines struct {
	FirstResponse null.Time
	Resolution    null.Time
	NextResponse  null.Time
}

Deadlines holds the deadlines for an SLA policy.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func New

func New(
	opts Opts,
	teamStore teamStore,
	appSettingsStore appSettingsStore,
	businessHrsStore businessHrsStore,
	template *template.Manager,
	userStore userStore,
	dispatcher *notifier.Dispatcher,
) (*Manager, error)

New creates a new SLA manager.

func (*Manager) ApplySLA

func (m *Manager) ApplySLA(startTime time.Time, conversationID, assignedTeamID, slaPolicyID int) (models.SLAPolicy, error)

ApplySLA applies an SLA policy to a conversation by calculating and setting the deadlines.

func (*Manager) CalculateDeadline

func (m *Manager) CalculateDeadline(start time.Time, slaMinutes int, businessHours models.BusinessHours, timeZone string) (time.Time, error)

CalculateDeadline computes the SLA deadline from a start time and SLA duration in minutes considering the provided holidays, working hours, and time zone.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the SLA evaluation loop by stopping the worker pool.

func (*Manager) Create

func (m *Manager) Create(name, description string, firstResponseTime, resolutionTime, nextResponseTime null.String, notifications models.SlaNotifications) (models.SLAPolicy, error)

Create creates a new SLA policy.

func (*Manager) CreateNextResponseSLAEvent

func (m *Manager) CreateNextResponseSLAEvent(conversationID, appliedSLAID, slaPolicyID, assignedTeamID int) (time.Time, error)

CreateNextResponseSLAEvent creates a next response SLA event for a conversation.

func (*Manager) Delete

func (m *Manager) Delete(id int) error

Delete deletes an SLA policy.

func (*Manager) Get

func (m *Manager) Get(id int) (models.SLAPolicy, error)

Get retrieves an SLA by ID.

func (*Manager) GetAll

func (m *Manager) GetAll() ([]models.SLAPolicy, error)

GetAll fetches all SLA policies.

func (*Manager) GetDeadlines

func (m *Manager) GetDeadlines(startTime time.Time, slaPolicyID, assignedTeamID int) (Deadlines, error)

GetDeadlines returns the deadline for a given start time, sla policy and assigned team.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, interval time.Duration)

Run starts Applied SLA and SLA event evaluation loops in separate goroutines.

func (*Manager) SendNotification

func (m *Manager) SendNotification(scheduledNotification models.ScheduledSLANotification) error

SendNotification sends a SLA notification to agents, a schedule notification is always linked to an applied SLA and optionally to a SLA event.

func (*Manager) SendNotifications

func (m *Manager) SendNotifications(ctx context.Context) error

SendNotifications picks scheduled SLA notifications from the database and sends them to agents as emails.

func (*Manager) SetLatestSLAEventMetAt

func (m *Manager) SetLatestSLAEventMetAt(appliedSLAID int, metric string) (time.Time, error)

SetLatestSLAEventMetAt marks the latest SLA event as met for a given applied SLA.

func (*Manager) Update

func (m *Manager) Update(id int, name, description string, firstResponseTime, resolutionTime, nextResponseTime null.String, notifications models.SlaNotifications) (models.SLAPolicy, error)

Update updates a SLA policy.

type Opts

type Opts struct {
	DB   *sqlx.DB
	Lo   *logf.Logger
	I18n *i18n.I18n
}

Opts defines the options for creating SLA manager.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL