jobs

package
v0.0.0-...-c2fab7e Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: GPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Longer running tasks.

The job system allows go routines running custom logic, called jobs, to be started. See JobRunner for usage instructions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job interface {
	// Do job. Data argument holds arbitrary data. It is up to each job
	// to define what data it takes.
	Do(data []byte) error
}

Job is a piece of logic

type JobRunner

type JobRunner struct {

	// Ctx
	Ctx context.Context

	// Logger
	Logger golog.Logger

	// Cfg is the server configuration
	Cfg *config.Config

	// Metrics holds internal Prometheus metrics recorders
	Metrics metrics.Metrics

	// GH is a GitHub API client
	GH *github.Client

	// MDbApps is used to access the apps collection
	MDbApps *mongo.Collection
	// contains filtered or unexported fields
}

JobRunner manages starting jobs and shutting down gracefully

func (*JobRunner) Init

func (r *JobRunner) Init()

Init initializes a JobRunner. The Submit() and Run() methods will not work properly unless this method is called.

func (JobRunner) Run

func (r JobRunner) Run()

Run reads requests off the Queue and starts go routines to run jobs If the JobRunner.Ctx is canceled JobRunner will stop accepting jobs and return when there are no more jobs running. Should be run in a goroutine b/c this method blocks to run jobs.

func (JobRunner) Submit

func (r JobRunner) Submit(t JobTypeT, data []byte) *JobStartRequest

Submit new job

type JobStartRequest

type JobStartRequest struct {
	// Type of job to start
	Type JobTypeT

	// Data required to start job
	Data []byte

	// CompleteChan will close when the job has been completed. This
	// does not guarantee the job finished successfully
	CompleteChan chan interface{}
}

JobStartRequest provides informtion required to start a job

type JobTypeT

type JobTypeT string

JobTypeT is used to specify what type of job to start

const (
	JobTypeUpdateApps JobTypeT = "update_apps"
	JobTypeValidate            = "validate"
)

Job types identify different jobs which can be run

type UpdateAppsJob

type UpdateAppsJob struct {
	// Ctx
	Ctx context.Context

	// Cfg is the server configuration
	Cfg *config.Config

	// GH is a GitHub API client
	GH *github.Client

	// MDbApps is used to access the apps collection
	MDbApps *mongo.Collection
}

UpdateAppsJob updates the apps collection based on the current master branch state The data field is optional. If provided must be a JSON encoded UpdateAppsJobDefinition.

func (UpdateAppsJob) Do

func (j UpdateAppsJob) Do(data []byte) error

Do job actions

type UpdateAppsJobDefinition

type UpdateAppsJobDefinition struct {
	// NoBotAPINotify when true indicates that the job should not make a request
	// to the bot API new apps endpoint
	NoBotAPINotify bool
}

UpdateAppsJobDefinition specifies the behavior of an UpdateAppsJob

type ValidateJob

type ValidateJob struct {
	// Ctx
	Ctx context.Context

	// Logger
	Logger golog.Logger

	// Cfg is the server configuration
	Cfg *config.Config

	// GH is a GitHub API client
	GH *github.Client
}

ValidateJob updates the apps collection based on the current master branch state Expects the data passed to Do() to be a github.PullRequest in JSON form. This pull request will be validated.

func (ValidateJob) Do

func (j ValidateJob) Do(data []byte) error

Do implments Job

Jump to

Keyboard shortcuts

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