relui

package
v0.0.0-...-2921ab6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: BSD-3-Clause Imports: 61 Imported by: 0

Documentation

Index

Constants

View Source
const DatetimeLocalLayout = "2006-01-02T15:04"

Variables

View Source
var ErrScheduleNotFound = errors.New("schedule not found")
View Source
var Views = []*view.View{
	{
		Name:        "go-build/relui/http/server/latency",
		Description: "Latency distribution of HTTP requests",
		Measure:     ochttp.ServerLatency,
		TagKeys:     []tag.Key{ochttp.KeyServerRoute},
		Aggregation: ochttp.DefaultLatencyDistribution,
	},
	{
		Name:        "go-build/relui/http/server/response_count_by_status_code",
		Description: "Server response count by status code",
		TagKeys:     []tag.Key{ochttp.StatusCode, ochttp.KeyServerRoute},
		Measure:     ochttp.ServerLatency,
		Aggregation: view.Count(),
	},
	{
		Name:        "go-build/relui/db/query_latency",
		Description: "Latency distribution of database queries",
		TagKeys:     []tag.Key{kDBQueryName},
		Measure:     mDBLatency,
		Aggregation: ochttp.DefaultLatencyDistribution,
	},
}

Views should contain all measurements. All *view.View added to this slice will be registered and exported to the metric service.

Functions

func ApproveActionDep

func ApproveActionDep(p db.PGDBTX) func(*wf.TaskContext) error

ApproveActionDep returns a function for defining approval Actions.

ApproveActionDep takes a single *pgxpool.Pool argument, which is used to query the database to determine if a task has been marked approved.

ApproveActionDep marks the task as requiring approval in the database once the task is started. This can be used to show an "approve" control in the UI.

waitAction := wf.ActionN(wd, "Wait for Approval", ApproveActionDep(db), wf.After(someDependency))
func BaseLink(baseURL *url.URL) func(target string, extras ...string) string

func ConnectMaintenanceDB

func ConnectMaintenanceDB(ctx context.Context, cfg *pgx.ConnConfig, maintDB string) (*pgx.Conn, error)

ConnectMaintenanceDB connects to the maintenance database using the credentials from cfg. If maintDB is an empty string, the database with the name cfg.User will be used.

func CreateDBIfNotExists

func CreateDBIfNotExists(ctx context.Context, cfg *pgx.ConnConfig) error

CreateDBIfNotExists checks whether the given dbName is an existing database, and creates one if not.

func DropDB

func DropDB(ctx context.Context, cfg *pgx.ConnConfig) error

DropDB drops the database specified in cfg. An error returned if the database does not exist.

func InitDB

func InitDB(ctx context.Context, conn string) error

InitDB creates and applies all migrations to the database specified in conn.

If the database does not exist, one will be created using the credentials provided.

Any key/value or URI string compatible with libpq is valid.

func LogOnlyMailer

func LogOnlyMailer(header task.MailHeader, content task.MailContent) error

func MigrateDB

func MigrateDB(conn string, downUp bool) error

MigrateDB applies all migrations to the database specified in conn.

Any key/value or URI string compatible with libpq is a valid conn. If downUp is true, all migrations will be run, then the down and up migrations of the final migration are run.

func RegisterReleaseWorkflows

func RegisterReleaseWorkflows(ctx context.Context, h *DefinitionHolder, build *BuildReleaseTasks, milestone *task.MilestoneTasks, version *task.VersionTasks, comm task.CommunicationTasks) error

RegisterReleaseWorkflows registers workflows for issuing Go releases.

func UnmarshalWorkflow

func UnmarshalWorkflow(marshalled string, d *workflow.Definition) (map[string]any, error)

Types

type BuildReleaseTasks

type BuildReleaseTasks struct {
	GerritClient             task.GerritClient
	GerritProject            string
	GerritHTTPClient         *http.Client // GerritHTTPClient is an HTTP client that authenticates to Gerrit instances. (Both public and private.)
	PrivateGerritClient      task.GerritClient
	PrivateGerritProject     string
	GCSClient                *storage.Client
	ScratchFS                *task.ScratchFS
	SignedURL                string // SignedURL is a gs:// or file:// URL, no trailing slash.
	ServingURL               string // ServingURL is a gs:// or file:// URL, no trailing slash.
	DownloadURL              string
	ProxyPrefix              string // ProxyPrefix is the prefix at which module files are published, e.g. https://proxy.golang.org/golang.org/toolchain/@v
	PublishFile              func(task.WebsiteFile) error
	SignService              sign.Service
	GoogleDockerBuildProject string
	GoogleDockerBuildTrigger string
	CloudBuildClient         task.CloudBuildClient
	BuildBucketClient        task.BuildBucketClient
	SwarmingClient           task.SwarmingClient
	ApproveAction            func(*wf.TaskContext) error
}

BuildReleaseTasks serves as an adapter to the various build tasks in the task package.

type DefinitionHolder

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

DefinitionHolder holds workflow definitions.

func NewDefinitionHolder

func NewDefinitionHolder() *DefinitionHolder

NewDefinitionHolder creates a new DefinitionHolder, initialized with a sample "echo" wf.

func (*DefinitionHolder) Definition

func (h *DefinitionHolder) Definition(name string) *wf.Definition

Definition returns the initialized wf.Definition registered for a given name.

func (*DefinitionHolder) Definitions

func (h *DefinitionHolder) Definitions() map[string]*wf.Definition

Definitions returns the names of all registered definitions.

func (*DefinitionHolder) RegisterDefinition

func (h *DefinitionHolder) RegisterDefinition(name string, d *wf.Definition)

RegisterDefinition registers a definition with a name. If a definition with the same name already exists, RegisterDefinition panics.

type FailedToScheduleEntry

type FailedToScheduleEntry struct {
	WorkflowSchedule
	ParsedSchedule cron.Schedule
	LastRun        db.SchedulesLastRunRow
}

func (FailedToScheduleEntry) Next

func (e FailedToScheduleEntry) Next() time.Time

type Listener

type Listener interface {
	workflow.Listener

	WorkflowStarted(ctx context.Context, workflowID uuid.UUID, name string, params map[string]interface{}, scheduleID int) error
	WorkflowFinished(ctx context.Context, workflowID uuid.UUID, outputs map[string]interface{}, err error) error
}

type MetricsDB

type MetricsDB struct {
	db.PGDBTX
}

func (*MetricsDB) Exec

func (m *MetricsDB) Exec(ctx context.Context, s string, i ...any) (pgconn.CommandTag, error)

func (*MetricsDB) Query

func (m *MetricsDB) Query(ctx context.Context, s string, i ...any) (pgx.Rows, error)

func (*MetricsDB) QueryRow

func (m *MetricsDB) QueryRow(ctx context.Context, s string, i ...any) pgx.Row

type PGListener

type PGListener struct {
	DB db.PGDBTX

	BaseURL *url.URL

	ScheduleFailureMailHeader task.MailHeader
	SendMail                  func(task.MailHeader, task.MailContent) error
	// contains filtered or unexported fields
}

PGListener implements workflow.Listener for recording workflow state.

func (*PGListener) Logger

func (l *PGListener) Logger(workflowID uuid.UUID, taskName string) workflow.Logger

func (*PGListener) TaskStateChanged

func (l *PGListener) TaskStateChanged(workflowID uuid.UUID, taskName string, state *workflow.TaskState) error

TaskStateChanged is called whenever a task is updated by the workflow. The workflow.TaskState is persisted as a db.Task, creating or updating a row as necessary.

func (*PGListener) WorkflowFinished

func (l *PGListener) WorkflowFinished(ctx context.Context, workflowID uuid.UUID, outputs map[string]interface{}, workflowErr error) error

WorkflowFinished saves the final state of a workflow after its run has completed.

func (*PGListener) WorkflowStalled

func (l *PGListener) WorkflowStalled(workflowID uuid.UUID) error

WorkflowStalled is called when no tasks are runnable.

func (*PGListener) WorkflowStarted

func (l *PGListener) WorkflowStarted(ctx context.Context, workflowID uuid.UUID, name string, params map[string]interface{}, scheduleID int) error

WorkflowStarted persists a new workflow execution in the database.

type RunOnce

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

RunOnce is a cron.Schedule for running a job at a specific time.

func (*RunOnce) Next

func (r *RunOnce) Next(t time.Time) time.Time

Next returns the next time a job should run.

type Schedule

type Schedule struct {
	Once time.Time
	Cron string
	Type ScheduleType
}

Schedule represents the interval on which a job should be run. Only Type and one other field should be set.

func (Schedule) Parse

func (s Schedule) Parse() (cron.Schedule, error)

func (Schedule) Valid

func (s Schedule) Valid() error

type ScheduleEntry

type ScheduleEntry struct {
	// Entry is the cron entry.
	//
	// Its Job field holds a *WorkflowSchedule that describes the scheduled
	// workflow and how to start running a new instance of it.
	cron.Entry

	LastRun db.SchedulesLastRunRow
}

func (*ScheduleEntry) WorkflowJob

func (s *ScheduleEntry) WorkflowJob() *WorkflowSchedule

WorkflowJob returns a *WorkflowSchedule for the ScheduleEntry.

type ScheduleType

type ScheduleType string

ScheduleType determines whether a workflow runs immediately or on some future date or cadence.

const (
	ScheduleImmediate ScheduleType = "Immediate"
	ScheduleOnce      ScheduleType = "Future Date"
	ScheduleCron      ScheduleType = "Cron"
)

func (ScheduleType) ElementID

func (s ScheduleType) ElementID() string

ElementID returns a string suitable for a HTML element ID.

func (ScheduleType) FormField

func (s ScheduleType) FormField() string

FormField returns a string representing which datatype to present the user on the creation form.

type Scheduler

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

func NewScheduler

func NewScheduler(db db.PGDBTX, w *Worker) *Scheduler

NewScheduler returns a Scheduler ready to run jobs.

func (*Scheduler) Create

func (s *Scheduler) Create(ctx context.Context, sched Schedule, workflowName string, params map[string]any) (row db.Schedule, err error)

Create schedules a job and records it in the database.

func (*Scheduler) Delete

func (s *Scheduler) Delete(ctx context.Context, id int) error

Delete removes a schedule from the scheduler, preventing subsequent runs, and deletes the schedule from the database.

Jobs in progress are not interrupted, but will be prevented from starting again.

func (*Scheduler) Entries

func (s *Scheduler) Entries(ctx context.Context, workflowNames ...string) ([]ScheduleEntry, []FailedToScheduleEntry)

Entries returns a list of scheduled jobs, and a list of jobs that failed to schedule.

The scheduled jobs are filtered by workflowNames, if provided, otherwise all scheduled jobs are included.

func (*Scheduler) Resume

func (s *Scheduler) Resume(ctx context.Context) error

Resume fetches schedules from the database and schedules them.

type Server

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

Server implements the http handlers for relui.

func NewServer

func NewServer(p db.PGDBTX, w *Worker, baseURL *url.URL, header SiteHeader, ms *metrics.Service, cria *criadb.AuthDatabase) *Server

NewServer initializes a server with the provided connection pool, worker, base URL and site header.

The base URL may be nil, which is the same as "/".

cria may be nil, in which case workflows are unrestricted, this is mainly intended to ease development.

func (s *Server) BaseLink(target string, extras ...string) string

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
type SiteHeader struct {
	Title     string // Site title. For example, "Go Releases".
	CSSClass  string // Site header CSS class name. Optional.
	Subtitle  string
	NameParam string
}

SiteHeader configures the relui site header.

type Worker

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

Worker runs workflows, and persists their state.

func NewWorker

func NewWorker(dh *DefinitionHolder, db db.PGDBTX, l Listener) *Worker

NewWorker returns a Worker ready to accept and run workflows.

func (*Worker) Resume

func (w *Worker) Resume(ctx context.Context, id uuid.UUID) error

Resume resumes a workflow.

func (*Worker) ResumeAll

func (w *Worker) ResumeAll(ctx context.Context) error

ResumeAll resumes all workflows with unfinished tasks.

func (*Worker) RetryTask

func (w *Worker) RetryTask(ctx context.Context, id uuid.UUID, name string) error

RetryTask retries a task in a running workflow.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Run runs started workflows, waiting for new workflows to start.

On context cancellation, Run waits for all running workflows to finish.

func (*Worker) StartWorkflow

func (w *Worker) StartWorkflow(ctx context.Context, name string, params map[string]interface{}, scheduleID int) (uuid.UUID, error)

StartWorkflow persists and starts running a workflow.

type WorkflowSchedule

type WorkflowSchedule struct {
	Schedule db.Schedule
	Params   map[string]any
	// contains filtered or unexported fields
}

WorkflowSchedule represents the data needed to create a Workflow.

func (WorkflowSchedule) ParamDesc

func (w WorkflowSchedule) ParamDesc() string

ParamDesc returns a description of the parameters.

func (*WorkflowSchedule) Run

func (w *WorkflowSchedule) Run()

Run starts a Workflow.

func (WorkflowSchedule) ScheduleDesc

func (w WorkflowSchedule) ScheduleDesc() string

ScheduleDesc returns a description of the schedule.

Directories

Path Synopsis
Package groups contains group definitions for ACL purposes.
Package groups contains group definitions for ACL purposes.
Package sign provides implementations for servers which can sign Go release artifacts.
Package sign provides implementations for servers which can sign Go release artifacts.

Jump to

Keyboard shortcuts

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