dockworker

package module
v0.0.0-...-f5b5a7a Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2016 License: MIT Imports: 15 Imported by: 0

README

dockworker

A worker queue API which runs jobs in Docker containers.

TODO

  • env vars
  • container logs
  • hypermedia links jobs
  • working dir for commands
  • stopping jobs
  • files from job container
  • persistence of jobs
  • graceful shutdowns and restarts
  • container IDs which ran the job (for debugging)
  • image IDs which ran the job
  • webhooks
  • websocket for stream of job events
  • cleanup of containers/images
  • more documentation

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrJobNotFound indicates the specificed job
	// could not be found
	ErrJobNotFound = fmt.Errorf("No job with that ID")

	// ErrInvalidJobID indicates the job ID was
	// specificed in an invalid format
	ErrInvalidJobID = fmt.Errorf("Invalid job ID")
)

Functions

func InitWSContainer

func InitWSContainer() *restful.Container

InitWSContainer sets up the program

func SendWebhook

func SendWebhook(job Job)

SendWebhook performs the webhook request for the given Job

Types

type Cmd

type Cmd []string

Cmd is a command to run in the job

type CmdResult

type CmdResult int

CmdResult represents the result of running a command

type Container

type Container string

Container represents the ID of the Job

type DockerEventListener

type DockerEventListener interface {
	Start() error
	Stop()
	RegisterListener(listener chan *docker.APIEvents)
	UnregisterListener(listener chan *docker.APIEvents)
}

DockerEventListener wraps the underlying Docker event listener

func NewEventListener

func NewEventListener(client *docker.Client) DockerEventListener

NewEventListener returns a new EventListener

type ImageName

type ImageName string

ImageName represents the ID of a Docker image

type Job

type Job struct {
	ID         JobID             `json:"id"`
	ImageName  string            `json:"image"`
	Env        map[string]string `json:"env"`
	Status     JobStatus         `json:"status"`
	Cmds       []Cmd             `json:"cmds"`
	Message    string            `json:"message"`
	Results    []CmdResult       `json:"results"`
	Containers []Container       `json:"containers"`
	Images     []ImageName       `json:"images"`
	WebhookURL string            `json:"webhook_url"`
	StartTime  time.Time         `json:"start_time"`
	EndTime    time.Time         `json:"end_time"`
}

Job is a job

type JobAPI

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

JobAPI is a jobs api

func NewJobAPI

func NewJobAPI(jobService JobService, logService LogService,
	stopService StopService) JobAPI

NewJobAPI creates a new JobAPI

func (JobAPI) Register

func (api JobAPI) Register(container *restful.Container)

Register registers the job api's routes

type JobID

type JobID int

JobID represents the ID of the Job

type JobManager

type JobManager interface {
	NotifyNewJob(job Job)
	Start()
	Stop()
}

JobManager manages Jobs

func NewJobManager

func NewJobManager(jobStore JobStore, client *docker.Client, eventListner DockerEventListener, jobUpdater JobUpdater, stopEventListener StopEventListener) JobManager

NewJobManager returns a new JobManager

type JobService

type JobService interface {
	Add(job Job) (Job, error)
	Find(ID JobID) (Job, error)
	UpdateStatus(job Job) error
}

JobService handles the jobs

func NewJobService

func NewJobService(jobStore JobStore, jobManager JobManager) JobService

NewJobService returns a new JobService

type JobStatus

type JobStatus string

JobStatus represents the status of the Job

const (
	// JobStatusQueued state indicates the job is queued waiting to be run
	JobStatusQueued JobStatus = "queued"
	// JobStatusRunning state indicates the job is running
	JobStatusRunning JobStatus = "running"
	// JobStatusSuccessful state indicates the job has completed successfully
	JobStatusSuccessful JobStatus = "successful"
	// JobStatusFailed state indicates the job has completed with a failure
	JobStatusFailed JobStatus = "failed"
	// JobStatusError state indicates the job could not be run properly
	JobStatusError JobStatus = "error"
	// JobStatusStopped state indicates the job was stoped
	JobStatusStopped JobStatus = "stopped"
)

type JobStore

type JobStore interface {
	Add(job Job) (Job, error)
	Find(ID JobID) (Job, error)
	Update(job Job) error
}

JobStore stores jobs

func NewJobStore

func NewJobStore() JobStore

NewJobStore creates a new JobStore

type JobUpdater

type JobUpdater interface {
	UpdateStatus(job *Job, status JobStatus) error
	UpdateStartTime(job *Job, startTime time.Time) error
	UpdateEndTime(job *Job, endTime time.Time) error
	AddCmdResult(job *Job, result CmdResult) error
	AddContainer(job *Job, container Container) error
	AddImage(job *Job, image ImageName) error
}

JobUpdater handles updating jobs

func NewJobUpdater

func NewJobUpdater(jobStore JobStore) JobUpdater

NewJobUpdater returns a new JobUpdater

type LogService

type LogService interface {
	GetLogs(job Job, output io.Writer) error
}

LogService handles retrieving logs from containers

func NewLogService

func NewLogService(jobStore JobStore, client *docker.Client) LogService

NewLogService returns a new LogService

type StopEventListener

type StopEventListener interface {
	Start() error
	Stop()
	RegisterListener(listener chan JobID)
	UnregisterListener(listener chan JobID)
}

StopEventListener handles requests to stop running jobs

func NewStopEventListener

func NewStopEventListener(stopEventChan chan JobID) StopEventListener

NewStopEventListener returns a new StopEventListener

type StopService

type StopService interface {
	Stop(JobID) error
}

StopService handles stopping jobs

func NewStopService

func NewStopService(stopEventChan chan JobID) StopService

NewStopService returns a new StopService

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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