models

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package models contains the models and auto generated models for the app.

Index

Constants

View Source
const (
	WorkspaceUpdated      = "WORKSPACE_UPDATED"
	ProjectUpdated        = "PROJECT_UPDATED"
	TaskUpdated           = "TASK_UPDATED"
	JobUpserted           = "JOB_UPSERTED"
	JobMetricsUpdated     = "JOB_METRICS_UPDATED"
	ProcessGroupUpserted  = "PROCESS_GROUP_UPSERTED"
	ProcessUpserted       = "PROCESS_UPSERTED"
	ProcessMetricsUpdated = "PROCESS_METRICS_UPDATED"
	LogEntryAdded         = "LOG_ENTRY_ADDED"
	LogMetricsUpdated     = "LOG_METRICS_UPDATED"
)

Message types.

Variables

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrType          = errors.New("wrong type")
	ErrFirstNegative = errors.New("first cannot be negative")
	ErrLastNegative  = errors.New("last cannot be negative")
	ErrNotRunning    = errors.New("project isn't running")
	ErrNotStopped    = errors.New("project isn't stopped")
)

Errors.

Functions

func CreateLineWriter

func CreateLineWriter(
	write func(ownerID, message string, a ...interface{}) string,
	ownerID string,
	a ...interface{},
) io.WriteCloser

CreateLineWriter creates a writer with a line splitter. Remember to call close().

Types

type Config

type Config struct {
	Filename   string `json:"filename"`
	Workspaces []struct {
		Slug        string  `json:"slug"`
		Name        string  `json:"name"`
		Description string  `json:"description"`
		Notes       *string `json:"notes"`
		Projects    []struct {
			Slug        string  `json:"slug"`
			Repository  string  `json:"repository"`
			Branch      string  `json:"branch"`
			Description *string `json:"description"`
		} `json:"projects"`
		Tasks []struct {
			Name  string `json:"name"`
			Steps []struct {
				Projects []string `json:"projects"`
				Commands []string `json:"commands"`
			} `json:"tasks"`
		} `json:"tasks"`
	} `json:"workspaces"`
}

Config contains all the data in a YAML config file.

func LoadConfigYAML

func LoadConfigYAML(filename string) (Config, error)

LoadConfigYAML loads a config from a YAML file.

func (Config) CreateNodes

func (c Config) CreateNodes(nodes *NodeManager, userID string) error

CreateNodes creates nodes for the content of the config. The user node must already exists

type DateTime

type DateTime time.Time

DateTime holds a date.

func (DateTime) MarshalGQL

func (d DateTime) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface.

func (*DateTime) UnmarshalGQL

func (d *DateTime) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Marshaler interface.

type Hash

type Hash string

Hash holds a Git hash. TODO: change to bytes.

func (Hash) MarshalGQL

func (h Hash) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface.

func (*Hash) UnmarshalGQL

func (h *Hash) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Marshaler interface.

type Job

type Job struct {
	ID        string      `json:"id"`
	Name      string      `json:"name"`
	CreatedAt DateTime    `json:"createdAt"`
	UpdatedAt DateTime    `json:"updatedAt"`
	Status    JobStatus   `json:"status"`
	Priority  JobPriority `json:"priority"`
	OwnerID   string      `json:"ownerID"`
}

Job represents a job in the app.

func (Job) IsNode

func (Job) IsNode()

IsNode tells gqlgen that it implements Node.

func (Job) Owner

func (j Job) Owner(nodes *NodeManager) Node

Owner returns the node associated with the job.

type JobManager

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

JobManager manages creating and running jobs.

func NewJobManager

func NewJobManager(
	nodes *NodeManager,
	log *Logger,
	subs *pubsub.PubSub,
	concurrency int,
	systemID string,
) *JobManager

NewJobManager creates a JobManager with given concurrency.

func (*JobManager) Add

func (j *JobManager) Add(
	name string,
	ownerID string,
	priority JobPriority,
	fn func(ctx context.Context) error,
) string

Add adds a job to the queue and returns the job's ID.

func (*JobManager) Stop

func (j *JobManager) Stop(id string) error

Stop cancels a running job.

func (*JobManager) Work

func (j *JobManager) Work(ctx context.Context) error

Work starts running jobs and blocks until the context is done.

type LogEntry

type LogEntry struct {
	ID        string   `json:"id"`
	Level     LogLevel `json:"level"`
	CreatedAt DateTime `json:"createdAt"`
	Message   string   `json:"message"`
	OwnerID   string   `json:"ownerID"`
}

LogEntry represents a log entry in the app.

func (LogEntry) IsNode

func (LogEntry) IsNode()

IsNode tells gqlgen that it implements Node.

func (LogEntry) Owner

func (l LogEntry) Owner(nodes *NodeManager) Node

Owner returns the node associated with the LogEntry.

type Logger

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

Logger logs messages.

func NewLogger

func NewLogger(
	nodes *NodeManager,
	subs *pubsub.PubSub,
	cap int,
	level LogLevel,
	systemID string,
) *Logger

NewLogger creates a Logger with given capacity and level.

func (*Logger) Add

func (l *Logger) Add(
	level LogLevel,
	ownerID string,
	message string,
) (string, error)

Add adds a log entry.

func (*Logger) Debug

func (l *Logger) Debug(message string, a ...interface{}) string

Debug adds a debug entry.

func (*Logger) DebugWithOwner

func (l *Logger) DebugWithOwner(ownerID string, message string, a ...interface{}) string

DebugWithOwner adds a debug entry with an owner.

func (*Logger) Error

func (l *Logger) Error(message string, a ...interface{}) string

Error adds an error entry.

func (*Logger) ErrorWithOwner

func (l *Logger) ErrorWithOwner(ownerID string, message string, a ...interface{}) string

ErrorWithOwner adds an error entry with an owner.

func (*Logger) Info

func (l *Logger) Info(message string, a ...interface{}) string

Info adds an info entry.

func (*Logger) InfoWithOwner

func (l *Logger) InfoWithOwner(ownerID string, message string, a ...interface{}) string

InfoWithOwner adds an info entry with an owner.

func (*Logger) Warning

func (l *Logger) Warning(message string, a ...interface{}) string

Warning adds a warning entry.

func (*Logger) WarningWithOwner

func (l *Logger) WarningWithOwner(ownerID string, message string, a ...interface{}) string

WarningWithOwner adds a warning entry with an owner.

type NodeManager

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

NodeManager helps manage nodes with global IDs.

func (*NodeManager) Load

func (n *NodeManager) Load(id string) (Node, bool)

Load loads a node.

func (*NodeManager) Lock

func (n *NodeManager) Lock(ids ...string)

Lock locks the given IDs.

func (*NodeManager) MustLoad

func (n *NodeManager) MustLoad(id string) Node

MustLoad loads a node or panics if it doesn't exist.

func (*NodeManager) RLock

func (n *NodeManager) RLock(ids ...string)

RLock read-locks the given IDs.

func (*NodeManager) RUnlock

func (n *NodeManager) RUnlock(ids ...string)

RUnlock read-unlocks the given IDs.

func (*NodeManager) Unlock

func (n *NodeManager) Unlock(ids ...string)

Unlock unlocks the given IDs.

type Process

type Process struct {
	ID             string        `json:"id"`
	Command        string        `json:"command"`
	ProcessGroupID string        `json:"processGroupID"`
	ProjectID      string        `json:"projectID"`
	Status         ProcessStatus `json:"status"`
}

Process represents a process in the app.

func (Process) IsNode

func (Process) IsNode()

IsNode tells gqlgen that it implements Node.

func (Process) ProcessGroup

func (p Process) ProcessGroup(nodes *NodeManager) ProcessGroup

ProcessGroup returns the ProcessGroup associated with the Process.

func (Process) Project

func (p Process) Project(nodes *NodeManager) Project

Project returns the Project associated with the Process.

type ProcessGroup

type ProcessGroup struct {
	ID         string   `json:"id"`
	CreatedAt  DateTime `json:"createdAt"`
	TaskID     string   `json:"taskID"`
	ProcessIDs []string `json:"processIDs"`
}

ProcessGroup represents a ProcessGroup in the app.

func (ProcessGroup) IsNode

func (ProcessGroup) IsNode()

IsNode tells gqlgen that it implements Node.

func (ProcessGroup) Processes

func (p ProcessGroup) Processes(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (ProcessConnection, error)

Processes returns the ProcessGroup's processes.

func (ProcessGroup) Status

func (p ProcessGroup) Status(nodes *NodeManager) ProcessStatus

Status returns the status of the ProcessGroup.

func (ProcessGroup) Task

func (p ProcessGroup) Task(nodes *NodeManager) Task

Task returns the Task associated with the ProcessGroup.

type ProcessManager

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

ProcessManager manages creating and running jobs.

func NewProcessManager

func NewProcessManager(
	nodes *NodeManager,
	log *Logger,
	subs *pubsub.PubSub,
	getProjectPath ProjectPathGetter,
	systemID string,
) *ProcessManager

NewProcessManager creates a ProcessManager. TODO: Add Clean() method to terminate all processes on shutdown.

func (*ProcessManager) Clean

func (p *ProcessManager) Clean(ctx context.Context)

Clean terminates all running processes.

func (*ProcessManager) CreateGroup

func (p *ProcessManager) CreateGroup(taskID string) string

CreateGroup creates a new ProcessGroup and returns its ID.

func (*ProcessManager) Run

func (p *ProcessManager) Run(
	command string,
	processGroupID string,
	projectID string,
) string

Run launches a new Process and adds it to a ProcessGroup.

func (*ProcessManager) Start

func (p *ProcessManager) Start(processID string) error

Start starts a process that was stopped.

func (*ProcessManager) Stop

func (p *ProcessManager) Stop(processID string) error

Stop stops a running process.

type Project

type Project struct {
	ID               string   `json:"id"`
	Slug             string   `json:"slug"`
	Repository       string   `json:"repository"`
	Branch           string   `json:"branch"`
	Description      *string  `json:"description"`
	WorkspaceID      string   `json:"workspaceID"`
	CommitIDs        []string `json:"commitIDs"`
	Tasks            []Task   `json:"projects"`
	IsLoadingCommits bool     `json:"isLoadingCommits"`
	IsCloning        bool     `json:"isCloning"`
	IsPulling        bool     `json:"isPulling"`
	IsBehind         bool     `json:"isBehind"`
	IsAhead          bool     `json:"isAhead"`
}

Project represents a project in the app.

func (Project) Commits

func (p Project) Commits(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (CommitConnection, error)

Commits returns paginated commits.

func (Project) IsCloned

func (p Project) IsCloned(
	nodes *NodeManager,
	getProjectPath ProjectPathGetter,
) bool

IsCloned checks if the project is cloned.

func (Project) IsNode

func (Project) IsNode()

IsNode tells gqlgen that it implements Node.

func (Project) Workspace

func (p Project) Workspace(nodes *NodeManager) Workspace

Workspace returns the workspace associated with the project.

type ProjectPathGetter

type ProjectPathGetter func(workspaceSlug, repo, branch string) string

ProjectPathGetter is a function that returns the path to a project.

type Step

type Step struct {
	ID         string   `json:"id"`
	ProjectIDs []string `json:"projectIDs"`
	CommandIDs []string `json:"commandIDs"`
	TaskID     string   `json:"taskID"`
}

Step represents a task step in the app.

func (Step) Commands

func (s Step) Commands(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (CommandConnection, error)

Commands returns the step's commands.

func (Step) IsNode

func (Step) IsNode()

IsNode tells gqlgen that it implements Node.

func (Step) Projects

func (s Step) Projects(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (ProjectConnection, error)

Projects returns the step's projects.

func (Step) Task

func (s Step) Task(nodes *NodeManager) Task

Task returns the step's taks.

type System

type System struct {
	ID               string   `json:"id"`
	JobIDs           []string `json:"jobsIDs"`
	JobMetricsID     string   `json:"jobMetricsID"`
	ProcessGroupIDs  []string `json:"processGroupIDs"`
	ProcessMetricsID string   `json:"processMetricsID"`
	LogEntryIDs      []string `json:"logEntryIDs"`
	LogMetricsID     string   `json:"logMetricsID"`
}

System contains information about the running app.

func (System) IsNode

func (System) IsNode()

IsNode tells gqlgen that it implements Node.

func (System) JobMetrics

func (s System) JobMetrics(nodes *NodeManager) JobMetrics

JobMetrics returns the JobMetrics node.

func (System) Jobs

func (s System) Jobs(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
	status []JobStatus,
) (JobConnection, error)

Jobs returns paginated jobs.

func (System) LogEntries

func (s System) LogEntries(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
	level []LogLevel,
	ownerID *string,
) (LogEntryConnection, error)

LogEntries returns paginated log entries.

func (System) LogMetrics

func (s System) LogMetrics(nodes *NodeManager) LogMetrics

LogMetrics returns the LogMetrics node.

func (System) ProcessGroups

func (s System) ProcessGroups(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
	status []ProcessStatus,
) (ProcessGroupConnection, error)

ProcessGroups returns paginated process groups.

func (System) ProcessMetrics

func (s System) ProcessMetrics(nodes *NodeManager) ProcessMetrics

ProcessMetrics returns the ProcessMetrics node.

type Task

type Task struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	StepIDs     []string `json:"stepIDs"`
	WorkspaceID string   `json:"workspace"`
	IsRunning   bool     `json:"isRunning"`
}

Task represents a workspace task in the app.

func (Task) IsNode

func (Task) IsNode()

IsNode tells gqlgen that it implements Node.

func (Task) Steps

func (t Task) Steps(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (StepConnection, error)

Steps returns the task's steps.

func (Task) Workspace

func (t Task) Workspace(nodes *NodeManager) Workspace

Workspace returns the task's workspace.

type User

type User struct {
	ID           string   `json:"id"`
	WorkspaceIDs []string `json:"workspaceIDs"`
}

User contains all the data of the person using the app.

func (User) IsNode

func (User) IsNode()

IsNode tells gqlgen that it implements Node.

func (User) Projects

func (u User) Projects(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (ProjectConnection, error)

Projects returns the user's projects.

func (User) Workspace

func (u User) Workspace(nodes *NodeManager, slug string) *Workspace

Workspace finds a workspace.

func (User) Workspaces

func (u User) Workspaces(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (WorkspaceConnection, error)

Workspaces returns the user's workspaces.

type Workspace

type Workspace struct {
	ID          string   `json:"id"`
	Slug        string   `json:"slug"`
	Name        string   `json:"name"`
	ProjectIDs  []string `json:"projectIDs"`
	TaskIDs     []string `json:"taskIDs"`
	Description string   `json:"description"`
	Notes       *string  `json:"notes"`
}

Workspace represents a workspace in the app.

func (Workspace) IsAhead

func (w Workspace) IsAhead(nodes *NodeManager) bool

IsAhead returns true if any of the projects is ahead origin.

func (Workspace) IsBehind

func (w Workspace) IsBehind(nodes *NodeManager) bool

IsBehind returns true if any of the projects is behind origin.

func (Workspace) IsCloned

func (w Workspace) IsCloned(nodes *NodeManager, getProjectPath ProjectPathGetter) bool

IsCloned returns true if all the projects are cloned.

func (Workspace) IsCloning

func (w Workspace) IsCloning(nodes *NodeManager) bool

IsCloning returns true if any of the projects is cloning.

func (Workspace) IsNode

func (Workspace) IsNode()

IsNode tells gqlgen that it implements Node.

func (Workspace) IsPulling

func (w Workspace) IsPulling(nodes *NodeManager) bool

IsPulling returns true if any of the projects is pulling.

func (Workspace) Projects

func (w Workspace) Projects(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (ProjectConnection, error)

Projects returns the workspace's projects.

func (Workspace) Tasks

func (w Workspace) Tasks(
	nodes *NodeManager,
	after *string,
	before *string,
	first *int,
	last *int,
) (TaskConnection, error)

Tasks returns the workspace's tasks.

Jump to

Keyboard shortcuts

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