jobs

package
v0.0.0-...-c208585 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package jobs controls the execution and error handling of a job

Index

Constants

This section is empty.

Variables

View Source
var Actives sync.Map

Actives is the map of jobs map[webhooks.RefID]*Job

View Source
var Pending sync.Map

Pending is the map of backlog jobs map[webhooks.RefID]*webhooks.GitRef

View Source
var Promotions = make(chan Promotion)

Promotions channel

View Source
var Recents sync.Map

Recents are jobs that are dead, but recent map[webhooks.RevID]*Job

Functions

func Debounce

func Debounce(hook webhooks.Ref)

Debounce puts a job in the queue, in time

func Promote

func Promote(msg webhooks.Ref, promoteTo string)

Promote will run the promote script

func Remove

func Remove(gitID webhooks.URLSafeRefID)

Remove will put a job on death row

func Run

func Run(runOpts *options.ServerConfig)

Run starts the job loop and waits for it to be stopped

func SetReport

func SetReport(urlRefID webhooks.URLSafeRefID, result *Result) error

SetReport will update jobs' logs

func Start

func Start(runOpts *options.ServerConfig)

Start starts the job loop, channels, and cleanup routines

func Stop

func Stop()

Stop will cancel the job loop and its timers

Types

type Job

type Job struct {
	// normal json
	StartedAt *time.Time    `json:"started_at,omitempty"` // empty when pending
	ID        string        `json:"id"`                   // could be URLSafeRefID or URLSafeRevID
	GitRef    *webhooks.Ref `json:"ref"`                  // always present
	PromoteTo string        `json:"promote_to,omitempty"` // empty when deploy and test
	Promote   bool          `json:"promote,omitempty"`    // empty when deploy and test
	EndedAt   *time.Time    `json:"ended_at,omitempty"`   // empty when running
	ExitCode  *int          `json:"exit_code,omitempty"`  // empty when running
	// full json
	Logs   []Log   `json:"logs,omitempty"`   // exist when requested
	Report *Result `json:"report,omitempty"` // empty unless given
	// contains filtered or unexported fields
}

Job represents a job started by the git webhook and also the JSON we send back through the API about jobs

func All

func All(then time.Time) []*Job

All returns all jobs, including active, recent, and (TODO) historical

func LoadLogs

func LoadLogs(runOpts *options.ServerConfig, safeID webhooks.URLSafeGitID) (*Job, error)

LoadLogs will log logs for a job

func WalkLogs

func WalkLogs(runOpts *options.ServerConfig) ([]*Job, error)

WalkLogs creates partial webhooks.Refs from walking the log dir

type Log

type Log struct {
	Timestamp time.Time `json:"timestamp"`
	Stderr    bool      `json:"stderr"`
	Text      string    `json:"text"`
}

Log is a log message

type Promotion

type Promotion struct {
	PromoteTo string
	GitRef    *webhooks.Ref
}

Promotion is a channel message

type Result

type Result struct {
	Name    string      `json:"name"`
	Status  string      `json:"status,omitempty"`
	Message string      `json:"message,omitempty"`
	Results []Result    `json:"results,omitempty"`
	Detail  interface{} `json:"_detail,omitempty"`
}

Result may have many items and sub-items

Jump to

Keyboard shortcuts

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