checkjobs

package
v0.0.0-...-a8496d4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package checkjobs provides read-only HTTP access to the check_jobs schedule table and aggregate stats over both the background jobs queue and the check schedule. It is admin-only and never exposes encrypted secret values.

Index

Constants

This section is empty.

Variables

View Source
var ErrCheckJobNotFound = errors.New("check job not found")

ErrCheckJobNotFound is returned when a check job cannot be found.

Functions

This section is empty.

Types

type CheckJobStats

type CheckJobStats struct {
	Total        int `json:"total"`
	DueNow       int `json:"dueNow"`
	InFlight     int `json:"inFlight"`
	Stalled      int `json:"stalled"`
	CrashLooping int `json:"crashLooping"`
}

CheckJobStats holds check-schedule counts.

type CheckJobView

type CheckJobView struct {
	UID             string         `json:"uid"`
	OrganizationUID string         `json:"organizationUid"`
	CheckUID        string         `json:"checkUid"`
	CheckName       *string        `json:"checkName"`
	Region          *string        `json:"region"`
	Type            string         `json:"type"`
	Config          models.JSONMap `json:"config"`
	EncryptedKeys   []string       `json:"encryptedKeys"`
	Encrypted       bool           `json:"encrypted"`
	PeriodSeconds   int64          `json:"periodSeconds"`
	ScheduledAt     *time.Time     `json:"scheduledAt"`
	LeaseWorkerUID  *string        `json:"leaseWorkerUid"`
	LeaseExpiresAt  *time.Time     `json:"leaseExpiresAt"`
	LeaseStarts     int            `json:"leaseStarts"`
	UpdatedAt       time.Time      `json:"updatedAt"`
	State           DerivedState   `json:"state"`
}

CheckJobView is the redacted, API-facing representation of a check_jobs row. It deliberately omits config_private / config_private_keys values and only exposes the *names* of encrypted keys.

type DerivedState

type DerivedState string

DerivedState describes the lease-derived health of a check job.

const (
	// StateIdle means the row has no active lease.
	StateIdle DerivedState = "idle"
	// StateInFlight means the row is leased and the lease has not expired.
	StateInFlight DerivedState = "inFlight"
	// StateStalled means the row is leased but the lease has expired.
	StateStalled DerivedState = "stalled"
	// StateCrashLooping means the row has been claimed too many times.
	StateCrashLooping DerivedState = "crashLooping"
)

type Handler

type Handler struct {
	base.HandlerBase
	// contains filtered or unexported fields
}

Handler exposes read-only check-job and stats endpoints.

func NewHandler

func NewHandler(svc Service, cfg *config.Config) *Handler

NewHandler creates a new check-jobs handler.

func (*Handler) GetCheckJob

func (h *Handler) GetCheckJob(writer http.ResponseWriter, req *http.Request) error

GetCheckJob returns a single check job (org-scoped). GET /api/v1/orgs/:org/check-jobs/:uid.

func (*Handler) GetSystemCheckJob

func (h *Handler) GetSystemCheckJob(writer http.ResponseWriter, req *http.Request) error

GetSystemCheckJob returns a single check job across all orgs (super-admin). GET /api/v1/system/check-jobs/:uid.

func (*Handler) ListCheckJobs

func (h *Handler) ListCheckJobs(writer http.ResponseWriter, req *http.Request) error

ListCheckJobs lists check jobs for the org (org-scoped). GET /api/v1/orgs/:org/check-jobs.

func (*Handler) ListSystemCheckJobs

func (h *Handler) ListSystemCheckJobs(writer http.ResponseWriter, req *http.Request) error

ListSystemCheckJobs lists check jobs across all orgs (super-admin). GET /api/v1/system/check-jobs.

func (*Handler) Stats

func (h *Handler) Stats(writer http.ResponseWriter, req *http.Request) error

Stats returns aggregate counts for the org (org-scoped). GET /api/v1/orgs/:org/jobs/stats.

func (*Handler) SystemStats

func (h *Handler) SystemStats(writer http.ResponseWriter, req *http.Request) error

SystemStats returns aggregate counts across all orgs (super-admin). GET /api/v1/system/jobs/stats.

type JobStats

type JobStats struct {
	Pending   int `json:"pending"`
	Running   int `json:"running"`
	Failed24h int `json:"failed24h"`
}

JobStats holds background-jobs queue counts.

type ListOptions

type ListOptions struct {
	Limit  int
	Offset int
}

ListOptions holds pagination options for listing check jobs.

type Service

type Service interface {
	// ListCheckJobs lists check jobs. When orgUID is empty, all orgs are
	// returned (system / super-admin mode).
	ListCheckJobs(ctx context.Context, orgUID string, opts ListOptions) ([]*CheckJobView, error)
	// GetCheckJob returns a single check job. When orgUID is non-empty, the
	// row must belong to that org or ErrCheckJobNotFound is returned.
	GetCheckJob(ctx context.Context, orgUID, uid string) (*CheckJobView, error)
	// Stats computes aggregate counts for the overview strip. When orgUID is
	// empty, counts span all orgs.
	Stats(ctx context.Context, orgUID string) (*Stats, error)
}

Service provides read-only check-job queries.

func NewService

func NewService(db *bun.DB) Service

NewService creates a new check-jobs read service.

type Stats

type Stats struct {
	Jobs   JobStats      `json:"jobs"`
	Checks CheckJobStats `json:"checks"`
}

Stats holds aggregate counts over background jobs and the check schedule.

Jump to

Keyboard shortcuts

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