task

package
v0.0.0-...-366f0b0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGuessDur           = time.Minute * 20
	TaskBookkeepingCollection = "task_bk"
)
View Source
const (
	Collection    = "tasks"
	OldCollection = "old_tasks"
	TestLogPath   = "/test_log/"
)
View Source
const (

	// tasks should be unscheduled after ~a week
	UnschedulableThreshold = 7 * 24 * time.Hour
)

Variables

View Source
var (
	// BSON fields for the task struct
	IdKey                   = bsonutil.MustHaveTag(Task{}, "Id")
	SecretKey               = bsonutil.MustHaveTag(Task{}, "Secret")
	CreateTimeKey           = bsonutil.MustHaveTag(Task{}, "CreateTime")
	DispatchTimeKey         = bsonutil.MustHaveTag(Task{}, "DispatchTime")
	ScheduledTimeKey        = bsonutil.MustHaveTag(Task{}, "ScheduledTime")
	StartTimeKey            = bsonutil.MustHaveTag(Task{}, "StartTime")
	FinishTimeKey           = bsonutil.MustHaveTag(Task{}, "FinishTime")
	ActivatedTimeKey        = bsonutil.MustHaveTag(Task{}, "ActivatedTime")
	VersionKey              = bsonutil.MustHaveTag(Task{}, "Version")
	ProjectKey              = bsonutil.MustHaveTag(Task{}, "Project")
	RevisionKey             = bsonutil.MustHaveTag(Task{}, "Revision")
	LastHeartbeatKey        = bsonutil.MustHaveTag(Task{}, "LastHeartbeat")
	ActivatedKey            = bsonutil.MustHaveTag(Task{}, "Activated")
	BuildIdKey              = bsonutil.MustHaveTag(Task{}, "BuildId")
	DistroIdKey             = bsonutil.MustHaveTag(Task{}, "DistroId")
	BuildVariantKey         = bsonutil.MustHaveTag(Task{}, "BuildVariant")
	DependsOnKey            = bsonutil.MustHaveTag(Task{}, "DependsOn")
	OverrideDependenciesKey = bsonutil.MustHaveTag(Task{}, "OverrideDependencies")
	NumDepsKey              = bsonutil.MustHaveTag(Task{}, "NumDependents")
	DisplayNameKey          = bsonutil.MustHaveTag(Task{}, "DisplayName")
	HostIdKey               = bsonutil.MustHaveTag(Task{}, "HostId")
	ExecutionKey            = bsonutil.MustHaveTag(Task{}, "Execution")
	RestartsKey             = bsonutil.MustHaveTag(Task{}, "Restarts")
	OldTaskIdKey            = bsonutil.MustHaveTag(Task{}, "OldTaskId")
	ArchivedKey             = bsonutil.MustHaveTag(Task{}, "Archived")
	RevisionOrderNumberKey  = bsonutil.MustHaveTag(Task{}, "RevisionOrderNumber")
	RequesterKey            = bsonutil.MustHaveTag(Task{}, "Requester")
	StatusKey               = bsonutil.MustHaveTag(Task{}, "Status")
	DetailsKey              = bsonutil.MustHaveTag(Task{}, "Details")
	AbortedKey              = bsonutil.MustHaveTag(Task{}, "Aborted")
	TimeTakenKey            = bsonutil.MustHaveTag(Task{}, "TimeTaken")
	ExpectedDurationKey     = bsonutil.MustHaveTag(Task{}, "ExpectedDuration")
	DurationPredictionKey   = bsonutil.MustHaveTag(Task{}, "DurationPrediction")
	PriorityKey             = bsonutil.MustHaveTag(Task{}, "Priority")
	ActivatedByKey          = bsonutil.MustHaveTag(Task{}, "ActivatedBy")
	CostKey                 = bsonutil.MustHaveTag(Task{}, "Cost")
	SpawnedHostCostKey      = bsonutil.MustHaveTag(Task{}, "SpawnedHostCost")
	ExecutionTasksKey       = bsonutil.MustHaveTag(Task{}, "ExecutionTasks")
	DisplayOnlyKey          = bsonutil.MustHaveTag(Task{}, "DisplayOnly")
	TaskGroupKey            = bsonutil.MustHaveTag(Task{}, "TaskGroup")
	GenerateTaskKey         = bsonutil.MustHaveTag(Task{}, "GenerateTask")
	GeneratedTasksKey       = bsonutil.MustHaveTag(Task{}, "GeneratedTasks")
	GeneratedByKey          = bsonutil.MustHaveTag(Task{}, "GeneratedBy")
	ResetWhenFinishedKey    = bsonutil.MustHaveTag(Task{}, "ResetWhenFinished")
	LogsKey                 = bsonutil.MustHaveTag(Task{}, "Logs")

	// BSON fields for the test result struct
	TestResultStatusKey    = bsonutil.MustHaveTag(TestResult{}, "Status")
	TestResultLineNumKey   = bsonutil.MustHaveTag(TestResult{}, "LineNum")
	TestResultTestFileKey  = bsonutil.MustHaveTag(TestResult{}, "TestFile")
	TestResultURLKey       = bsonutil.MustHaveTag(TestResult{}, "URL")
	TestResultLogIdKey     = bsonutil.MustHaveTag(TestResult{}, "LogId")
	TestResultURLRawKey    = bsonutil.MustHaveTag(TestResult{}, "URLRaw")
	TestResultExitCodeKey  = bsonutil.MustHaveTag(TestResult{}, "ExitCode")
	TestResultStartTimeKey = bsonutil.MustHaveTag(TestResult{}, "StartTime")
	TestResultEndTimeKey   = bsonutil.MustHaveTag(TestResult{}, "EndTime")
)
View Source
var (
	// BSON fields for task status details struct
	TaskEndDetailStatus      = bsonutil.MustHaveTag(apimodels.TaskEndDetail{}, "Status")
	TaskEndDetailTimedOut    = bsonutil.MustHaveTag(apimodels.TaskEndDetail{}, "TimedOut")
	TaskEndDetailType        = bsonutil.MustHaveTag(apimodels.TaskEndDetail{}, "Type")
	TaskEndDetailDescription = bsonutil.MustHaveTag(apimodels.TaskEndDetail{}, "Description")
)
View Source
var (
	SelectorTaskInProgress = bson.M{
		"$in": []string{evergreen.TaskStarted, evergreen.TaskDispatched},
	}

	FinishedOpts = []bson.M{{
		StatusKey: bson.M{
			"$in": []string{
				evergreen.TaskFailed,
				evergreen.TaskSucceeded,
			},
		},
	},
	}
	CompletedStatuses = []string{evergreen.TaskSucceeded, evergreen.TaskFailed}
)
View Source
var (
	AgentHeartbeat = "heartbeat"
)
View Source
var All = db.Query(nil)

All returns all tasks.

View Source
var (
	AllStatuses = "*"
)
View Source
var (
	IsDispatchedOrStarted = db.Query(bson.M{
		StatusKey: bson.M{"$in": []string{evergreen.TaskStarted, evergreen.TaskDispatched}},
	})
)

Functions

func AbortBuild

func AbortBuild(buildId, caller string) error

AbortBuild sets the abort flag on all tasks associated with the build which are in an abortable state

func Aggregate

func Aggregate(pipeline []bson.M, results interface{}) error

func ByAborted

func ByAborted(aborted bool) db.Q

ByAborted creates a query to return tasks with an aborted state

func ByActivatedBeforeRevisionWithStatuses

func ByActivatedBeforeRevisionWithStatuses(revisionOrder int, statuses []string, buildVariant string, displayName string, project string) db.Q

func ByActivation

func ByActivation(active bool) db.Q

ByAborted creates a query to return tasks with an aborted state

func ByBeforeRevision

func ByBeforeRevision(revisionOrder int, buildVariant, displayName, project, requester string) db.Q

func ByBeforeRevisionWithStatusesAndRequesters

func ByBeforeRevisionWithStatusesAndRequesters(revisionOrder int, statuses []string, buildVariant, displayName, project string, requesters []string) db.Q

func ByBuildId

func ByBuildId(buildId string) db.Q

ByBuildId creates a query to return tasks with a certain build id

func ByBuildIdAfterTaskId

func ByBuildIdAfterTaskId(buildId, taskId string) db.Q

ByBuildIdAfterTaskId provides a way to get an ordered list of tasks from a build. Providing a taskId allows indexing into the list of tasks that naturally exists when tasks are sorted by taskId.

func ByCommit

func ByCommit(revision, buildVariant, displayName, project, requester string) db.Q

ByCommit creates a query on Evergreen as the requester on a revision, buildVariant, displayName and project.

func ByDifferentFailedBuildVariants

func ByDifferentFailedBuildVariants(revision, buildVariant, displayName, project, requester string) db.Q

ByDifferentFailedBuildVariants returns a query for all failed tasks on a revision that are not of a buildVariant

func ByDispatchedWithIdsVersionAndStatus

func ByDispatchedWithIdsVersionAndStatus(taskIds []string, versionId string, statuses []string) db.Q

func ByExecutionTask

func ByExecutionTask(taskId string) db.Q

func ById

func ById(id string) db.Q

ById creates a query that finds a task by its _id.

func ByIds

func ByIds(ids []string) db.Q

ByIds creates a query that finds all tasks with the given ids.

func ByIdsBuildAndStatus

func ByIdsBuildAndStatus(taskIds []string, buildId string, statuses []string) db.Q

ByIdsBuildIdAndStatus creates a query to return tasks with a certain build id and statuses

func ByIntermediateRevisions

func ByIntermediateRevisions(previousRevisionOrder, currentRevisionOrder int,
	buildVariant, displayName, project, requester string) db.Q

ByIntermediateRevisions creates a query that returns the tasks existing between two revision order numbers, exclusive.

func ByOldTaskID

func ByOldTaskID(id string) db.Q

func ByRecentlyFinished

func ByRecentlyFinished(finishTime time.Time, project string, requester string) db.Q

func ByStatusAndActivation

func ByStatusAndActivation(status string, active bool) db.Q

ByStatusAndActivation creates a query that returns tasks of a certain status and activation state.

func ByStatuses

func ByStatuses(statuses []string, buildVariant, displayName, project, requester string) db.Q

func ByTimeRun

func ByTimeRun(startTime, endTime time.Time) db.Q

ByTimeRun returns all tasks that are running in between two given times.

func ByTimeStartedAndFailed

func ByTimeStartedAndFailed(startTime, endTime time.Time, commandTypes []string) db.Q

ByTimeStartedAndFailed returns all failed tasks that started between 2 given times

func ByVersion

func ByVersion(version string) db.Q

ByVersion creates a query to return tasks with a certain build id

func ByVersionsForNameAndVariant

func ByVersionsForNameAndVariant(versions, displayNames []string, buildVariant string) db.Q

func CostDataByDistroIdPipeline

func CostDataByDistroIdPipeline(distroId string, starttime time.Time, duration time.Duration) []bson.M

CostDataByDistroIdPipeline returns an aggregation pipeline for fetching cost data (sum of time taken) from a distro by its Id.

func CostDataByVersionIdPipeline

func CostDataByVersionIdPipeline(versionId string) []bson.M

CostDataByVersionIdPipeline returns an aggregation pipeline for fetching cost data (sum of time taken) from a version by its Id.

func Count

func Count(query db.Q) (int, error)

Count returns the number of hosts that satisfy the given query.

func ExpectedTaskDuration

func ExpectedTaskDuration(project, buildvariant string, window time.Duration) (map[string]time.Duration, error)

ExpectedTaskDuration takes a given project and buildvariant and computes the average duration - grouped by task display name - for tasks that have completed within a given threshold as determined by the window

func FindAllTaskIDsFromBuild

func FindAllTaskIDsFromBuild(buildId string) ([]string, error)

func FindAllTaskIDsFromVersion

func FindAllTaskIDsFromVersion(versionId string) ([]string, error)

func FindVariantsWithTask

func FindVariantsWithTask(taskName, project string, orderMin, orderMax int) ([]string, error)

FindVariantsWithTask returns a list of build variants between specified commmits that contain a specific task name

func GetResultCountList

func GetResultCountList(statuses []StatusItem) map[string][]Stat

func GetTimeSpent

func GetTimeSpent(tasks []Task) (time.Duration, time.Duration)

GetTimeSpent returns the total time_taken and makespan of tasks tasks should not include display tasks so they aren't double counted

func IncSpawnedHostCost

func IncSpawnedHostCost(taskID string, cost float64) error

func IsAbortable

func IsAbortable(t Task) bool

Abortable returns true if the task can be aborted.

func Remove

func Remove(id string) error

Remove deletes the task of the given id from the database

func RemoveAllWithBuild

func RemoveAllWithBuild(buildId string) error

Remove all deletes all tasks with a given buildId

func ResetTasks

func ResetTasks(taskIds []string) error

Reset sets the task state to be activated, with a new secret, undispatched status and zero time on Start, Scheduled, Dispatch and FinishTime

func SetTasksScheduledTime

func SetTasksScheduledTime(tasks []Task, scheduledTime time.Time) error

SetTasksScheduledTime takes a list of tasks and a time, and then sets the scheduled time in the database for the tasks if it is currently unset

func TasksByBuildIdPipeline

func TasksByBuildIdPipeline(buildId, taskId, taskStatus string,
	limit, sortDir int) []bson.M

TasksByBuildIdPipeline fetches the pipeline to get the retrieve all tasks associated with a given build.

func TasksByProjectAndCommitPipeline

func TasksByProjectAndCommitPipeline(projectId, commitHash, taskId, taskStatus string, limit int) []bson.M

TasksByProjectAndCommitPipeline fetches the pipeline to get the retrieve all tasks associated with a given project and commit hash.

func UnscheduleStaleUnderwaterTasks

func UnscheduleStaleUnderwaterTasks(distroID string) (int, error)

Removes tasks older than the unscheduable threshold (e.g. two weeks) from the scheduler queue.

If you pass an empty string as an argument to this function, this operation will select tasks from all distros.

func UpdateAll

func UpdateAll(query interface{}, update interface{}) (*adb.ChangeInfo, error)

func UpdateExpectedDuration

func UpdateExpectedDuration(t *Task, timeTaken time.Duration) error

update the expected duration that we expect the given task to take when run on the given host

func UpdateOne

func UpdateOne(query interface{}, update interface{}) error

UpdateOne updates one task.

func WithinTimePeriod

func WithinTimePeriod(startedAfter, finishedBefore time.Time, project string, statuses []string) db.Q

Returns query which targets list of tasks And allow filter by project_id, status, start_time (gte), finish_time (lte)

Types

type ByPriority

type ByPriority []Task

func (ByPriority) Len

func (p ByPriority) Len() int

func (ByPriority) Less

func (p ByPriority) Less(i, j int) bool

func (ByPriority) Swap

func (p ByPriority) Swap(i, j int)

type Dependency

type Dependency struct {
	TaskId string `bson:"_id" json:"id"`
	Status string `bson:"status" json:"status"`
}

Dependency represents a task that must be completed before the owning task can be scheduled.

func (*Dependency) SetBSON

func (d *Dependency) SetBSON(raw mgobson.Raw) error

SetBSON allows us to use dependency representation of both just task Ids and of true Dependency structs.

TODO eventually drop all of this switching

func (*Dependency) UnmarshalBSON

func (d *Dependency) UnmarshalBSON(in []byte) error

type DistroCost

type DistroCost struct {
	DistroId         string                 `bson:"distro_id"`
	SumTimeTaken     time.Duration          `bson:"sum_time_taken"`
	SumEstimatedCost float64                `bson:"sum_estimated_cost"`
	Provider         string                 `json:"provider"`
	ProviderSettings map[string]interface{} `json:"provider_settings"`
	NumTasks         int                    `bson:"num_tasks"`
}

DistroCost is service level model for representing cost data related to a distro. SumTimeTaken is the aggregation of time taken by all tasks associated with a distro.

type LocalTestResults

type LocalTestResults struct {
	Results []TestResult `json:"results"`
}

LocalTestResults is only used when transferring data from agent to api.

type ResultCounts

type ResultCounts struct {
	Total              int `json:"total"`
	Inactive           int `json:"inactive"`
	Unstarted          int `json:"unstarted"`
	Started            int `json:"started"`
	Succeeded          int `json:"succeeded"`
	Failed             int `json:"failed"`
	SetupFailed        int `json:"setup-failed"`
	SystemFailed       int `json:"system-failed"`
	SystemUnresponsive int `json:"system-unresponsive"`
	SystemTimedOut     int `json:"system-timed-out"`
	TestTimedOut       int `json:"test-timed-out"`

	message.Base `json:"metadata,omitempty"`
	// contains filtered or unexported fields
}

ResultCounts stores a collection of counters related to.

This type implements the grip/message.Composer interface and may be passed directly to grip loggers.

func GetResultCounts

func GetResultCounts(tasks []Task) *ResultCounts

GetResultCounts takes a list of tasks and collects their outcomes using the same status as the.

func (*ResultCounts) Loggable

func (c *ResultCounts) Loggable() bool

func (*ResultCounts) Raw

func (c *ResultCounts) Raw() interface{}

func (*ResultCounts) String

func (c *ResultCounts) String() string

type Stat

type Stat struct {
	Name  string `bson:"name"`
	Count int    `bson:"count"`
}

type StatusItem

type StatusItem struct {
	Status string `bson:"status"`
	Stats  []Stat `bson:"stats"`
}

func GetRecentTaskStats

func GetRecentTaskStats(period time.Duration, nameKey string) ([]StatusItem, error)

type Task

type Task struct {
	Id     string `bson:"_id" json:"id"`
	Secret string `bson:"secret" json:"secret"`

	// time information for task
	// create - the creation time for the task, derived from the commit time or the patch creation time.
	// dispatch - the time the task runner starts up the agent on the host
	// scheduled - the time the commit is scheduled
	// start - the time the agent starts the task on the host after spinning it up
	// finish - the time the task was completed on the remote host
	CreateTime    time.Time `bson:"create_time" json:"create_time"`
	IngestTime    time.Time `bson:"injest_time" json:"ingest_time"`
	DispatchTime  time.Time `bson:"dispatch_time" json:"dispatch_time"`
	ScheduledTime time.Time `bson:"scheduled_time" json:"scheduled_time"`
	StartTime     time.Time `bson:"start_time" json:"start_time"`
	FinishTime    time.Time `bson:"finish_time" json:"finish_time"`
	ActivatedTime time.Time `bson:"activated_time" json:"activated_time"`

	Version           string              `bson:"version" json:"version,omitempty"`
	Project           string              `bson:"branch" json:"branch,omitempty"`
	Revision          string              `bson:"gitspec" json:"gitspec"`
	Priority          int64               `bson:"priority" json:"priority"`
	TaskGroup         string              `bson:"task_group" json:"task_group"`
	TaskGroupMaxHosts int                 `bson:"task_group_max_hosts,omitempty" json:"task_group_max_hosts,omitempty"`
	Logs              *apimodels.TaskLogs `bson:"logs,omitempty" json:"logs,omitempty"`

	// only relevant if the task is runnin.  the time of the last heartbeat
	// sent back by the agent
	LastHeartbeat time.Time `bson:"last_heartbeat"`

	// used to indicate whether task should be scheduled to run
	Activated            bool         `bson:"activated" json:"activated"`
	ActivatedBy          string       `bson:"activated_by" json:"activated_by"`
	BuildId              string       `bson:"build_id" json:"build_id"`
	DistroId             string       `bson:"distro" json:"distro"`
	BuildVariant         string       `bson:"build_variant" json:"build_variant"`
	DependsOn            []Dependency `bson:"depends_on" json:"depends_on"`
	NumDependents        int          `bson:"num_dependents,omitempty" json:"num_dependents,omitempty"`
	OverrideDependencies bool         `bson:"override_dependencies,omitempty" json:"override_dependencies,omitempty"`

	// Human-readable name
	DisplayName string `bson:"display_name" json:"display_name"`

	// Tags that describe the task
	Tags []string `bson:"tags,omitempty" json:"tags,omitempty"`

	// The host the task was run on. This value is empty for display
	// tasks
	HostId string `bson:"host_id" json:"host_id"`

	// the number of times this task has been restarted
	Restarts            int    `bson:"restarts" json:"restarts,omitempty"`
	Execution           int    `bson:"execution" json:"execution"`
	OldTaskId           string `bson:"old_task_id,omitempty" json:"old_task_id,omitempty"`
	Archived            bool   `bson:"archived,omitempty" json:"archived,omitempty"`
	RevisionOrderNumber int    `bson:"order,omitempty" json:"order,omitempty"`

	// task requester - this is used to help tell the
	// reason this task was created. e.g. it could be
	// because the repotracker requested it (via tracking the
	// repository) or it was triggered by a developer
	// patch request
	Requester string `bson:"r" json:"r"`

	// Status represents the various stages the task could be in
	Status  string                  `bson:"status" json:"status"`
	Details apimodels.TaskEndDetail `bson:"details" json:"task_end_details"`
	Aborted bool                    `bson:"abort,omitempty" json:"abort"`

	// TimeTaken is how long the task took to execute.  meaningless if the task is not finished
	TimeTaken time.Duration `bson:"time_taken" json:"time_taken"`

	// how long we expect the task to take from start to
	// finish. expected duration is the legacy value, but the UI
	// probably depends on it, so we maintain both values.
	ExpectedDuration   time.Duration            `bson:"expected_duration,omitempty" json:"expected_duration,omitempty"`
	DurationPrediction util.CachedDurationValue `bson:"duration_prediction,omitempty" json:"-"`

	// an estimate of what the task cost to run, hidden from JSON views for now
	Cost float64 `bson:"cost,omitempty" json:"-"`
	// total estimated cost of hosts this task spawned
	SpawnedHostCost float64 `bson:"spawned_host_cost,omitempty" json:"spawned_host_cost,omitempty"`

	// test results embedded from the testresults collection
	LocalTestResults []TestResult `bson:"-" json:"test_results"`

	// display task fields
	DisplayOnly       bool     `bson:"display_only,omitempty" json:"display_only,omitempty"`
	ExecutionTasks    []string `bson:"execution_tasks,omitempty" json:"execution_tasks,omitempty"`
	ResetWhenFinished bool     `bson:"reset_when_finished,omitempty" json:"reset_when_finished,omitempty"`
	DisplayTask       *Task    `bson:"-" json:"-"` // this is a local pointer from an exec to display task

	// GenerateTask indicates that the task generates other tasks, which the
	// scheduler will use to prioritize this task.
	GenerateTask bool `bson:"generate_task,omitempty" json:"generate_task,omitempty"`
	// GeneratedTasks indicates that the task has already generated other tasks. This fields
	// allows us to noop future requests, since a task should only generate others once.
	GeneratedTasks bool `bson:"generated_tasks,omitempty" json:"generated_tasks,omitempty"`
	// GeneratedBy, if present, is the ID of the task that generated this task.
	GeneratedBy string `bson:"generated_by,omitempty" json:"generated_by,omitempty"`

	// Fields set if triggered by an upstream build
	TriggerID    string `bson:"trigger_id,omitempty" json:"trigger_id,omitempty"`
	TriggerType  string `bson:"trigger_type,omitempty" json:"trigger_type,omitempty"`
	TriggerEvent string `bson:"trigger_event,omitempty" json:"trigger_event,omitempty"`

	CommitQueueMerge bool `bson:"commit_queue_merge,omitempty" json:"commit_queue_merge,omitempty"`
}

func FilterTasksOnStatus

func FilterTasksOnStatus(tasks []Task, statuses ...string) []Task

FilterTasksOnStatus tasks in a slice of tasks and removes tasks whose result status do not match the passed-in statuses

func Find

func Find(query db.Q) ([]Task, error)

Find returns all tasks that satisfy the query.

func FindAll

func FindAll(query db.Q) ([]Task, error)

Find returns really all tasks that satisfy the query.

func FindAllTasksFromVersionWithDependencies

func FindAllTasksFromVersionWithDependencies(versionId string) ([]Task, error)

FindAllTasksFromVersionWithDependencies finds all tasks in a version and includes only their dependencies.

func FindCostTaskByProject

func FindCostTaskByProject(project, taskId string, starttime,
	endtime time.Time, limit, sortDir int) ([]Task, error)

FindCostTaskByProject fetches all tasks of a project matching the given time range, starting at task's IdKey in sortDir direction.

func FindOld

func FindOld(query db.Q) ([]Task, error)

FindOld returns all task from the old tasks collection that satisfies the query.

func FindOldWithDisplayTasks

func FindOldWithDisplayTasks(query db.Q) ([]Task, error)

FindOldWithDisplayTasks finds display and execution tasks in the old collection

func FindOne

func FindOne(query db.Q) (*Task, error)

FindOne returns one task that satisfies the query.

func FindOneId

func FindOneId(id string) (*Task, error)

func FindOneIdAndExecution

func FindOneIdAndExecution(id string, execution int) (*Task, error)

func FindOneIdOldOrNew

func FindOneIdOldOrNew(id string, execution int) (*Task, error)

FindOneIdOldOrNew attempts to find a given task ID by first looking in the old collection, then the tasks collection

func FindOneIdWithFields

func FindOneIdWithFields(id string, projected ...string) (*Task, error)

func FindOneNoMerge

func FindOneNoMerge(query db.Q) (*Task, error)

FindOneNoMerge is a FindOne without merging test results.

func FindOneOld

func FindOneOld(query db.Q) (*Task, error)

FindOneOld returns one task from the old tasks collection that satisfies the query.

func FindOneOldNoMerge

func FindOneOldNoMerge(query db.Q) (*Task, error)

FindOneOldNoMerge is a FindOneOld without merging test results.

func FindOneOldNoMergeByIdAndExecution

func FindOneOldNoMergeByIdAndExecution(id string, execution int) (*Task, error)

FindOneOldNoMergeByIdAndExecution finds a task from the old tasks collection without test results.

func FindRunnable

func FindRunnable(distroID string, removeDeps bool) ([]Task, error)

func FindSchedulable

func FindSchedulable(distroID string) ([]Task, error)

func FindTasksFromBuildWithDependencies

func FindTasksFromBuildWithDependencies(buildId string) ([]Task, error)

FindTasksFromBuildWithDependencies finds tasks from a build that have dependencies.

func FindWithDisplayTasks

func FindWithDisplayTasks(query db.Q) ([]Task, error)

func GetRecentTasks

func GetRecentTasks(period time.Duration) ([]Task, error)

GetRecentTasks returns the task results used by the recent_tasks endpoints.

func MergeTestResultsBulk

func MergeTestResultsBulk(tasks []Task, query *db.Q) ([]Task, error)

MergeTestResultsBulk takes a slice of task structs and returns the slice with test results populated. Note that the order may change. The second parameter can be used to use a specific test result filtering query, otherwise all test results for the passed in tasks will be merged. Display tasks will have the execution task results merged

func (*Task) ActivateTask

func (t *Task) ActivateTask(caller string) error

ActivateTask will set the ActivatedBy field to the caller and set the active state to be true

func (*Task) AddDependency

func (t *Task) AddDependency(d Dependency) error

func (*Task) AllDependenciesSatisfied

func (t *Task) AllDependenciesSatisfied(cache map[string]Task) (bool, error)

AllDependenciesSatisfied inspects the tasks first-order dependencies with regards to the cached tasks, and reports if all of the dependencies have been satisfied.

If the cached tasks do not include a dependency specified by one of the tasks, the function returns an error.

func (*Task) Archive

func (t *Task) Archive() error

Inserts the task into the old_tasks collection

func (*Task) BlockedState

func (t *Task) BlockedState(tasksWithDeps []Task) (string, error)

BlockedState returns "blocked," "pending" (unsatisfied dependencies, but unblocked), or "" (runnable) to represent the state of the task with respect to its dependencies

func (*Task) CircularDependencies

func (t *Task) CircularDependencies() error

func (*Task) CountSimilarFailingTasks

func (t *Task) CountSimilarFailingTasks() (int, error)

CountSimilarFailingTasks returns a count of all tasks with the same project, same display name, and in other buildvariants, that have failed in the same revision

func (*Task) DeactivateTask

func (t *Task) DeactivateTask(caller string) error

DeactivateTask will set the ActivatedBy field to the caller and set the active state to be false and deschedule the task

func (*Task) DependenciesMet

func (t *Task) DependenciesMet(depCaches map[string]Task) (bool, error)

Checks whether the dependencies for the task have all completed successfully. If any of the dependencies exist in the map that is passed in, they are used to check rather than fetching from the database. All queries are cached back into the map for later use.

func (*Task) FetchExpectedDuration

func (t *Task) FetchExpectedDuration() time.Duration

func (*Task) FindIntermediateTasks

func (current *Task) FindIntermediateTasks(previous *Task) ([]Task, error)

FindIntermediateTasks returns the tasks from most recent to least recent between two tasks.

func (*Task) FindTaskOnBaseCommit

func (t *Task) FindTaskOnBaseCommit() (*Task, error)

FindTaskOnBaseCommit returns the task that is on the base commit.

func (*Task) GetDisplayTask

func (t *Task) GetDisplayTask() (*Task, error)

func (*Task) GetHistoricRuntime

func (t *Task) GetHistoricRuntime() (time.Duration, error)

func (*Task) GetJQL

func (t *Task) GetJQL(searchProjects []string) string

Generates a jira JQL string from the task When we search in jira for a task we search in the specified JIRA project If there are any test results, then we only search by test file name of all of the failed tests. Otherwise we search by the task name.

func (*Task) GetTaskGroupString

func (t *Task) GetTaskGroupString() string

func (*Task) GetTestResultsForDisplayTask

func (t *Task) GetTestResultsForDisplayTask() ([]TestResult, error)

GetTestResultsForDisplayTask returns the test results for the execution tasks for a display task.

func (*Task) HasFailedTests

func (t *Task) HasFailedTests() bool

HasFailedTests iterates through a tasks' tests and returns true if that task had any failed tests.

func (*Task) Insert

func (t *Task) Insert() error

Insert writes the b to the db.

func (*Task) IsBlockedDisplayTask

func (t *Task) IsBlockedDisplayTask() bool

func (*Task) IsDispatchable

func (t *Task) IsDispatchable() bool

IsDispatchable return true if the task should be dispatched

func (*Task) IsFinished

func (t *Task) IsFinished() bool

IsFinished returns true if the task is no longer running

func (*Task) IsPartOfDisplay

func (t *Task) IsPartOfDisplay() bool

func (*Task) IsPatchRequest

func (t *Task) IsPatchRequest() bool

func (*Task) MarkAsDispatched

func (t *Task) MarkAsDispatched(hostId string, distroId string, dispatchTime time.Time) error

Mark that the task has been dispatched onto a particular host. Sets the running task field on the host and the host id field on the task. Returns an error if any of the database updates fail.

func (*Task) MarkAsUndispatched

func (t *Task) MarkAsUndispatched() error

MarkAsUndispatched marks that the task has been undispatched from a particular host. Unsets the running task field on the host and the host id field on the task Returns an error if any of the database updates fail.

func (*Task) MarkEnd

func (t *Task) MarkEnd(finishTime time.Time, detail *apimodels.TaskEndDetail) error

MarkEnd handles the Task updates associated with ending a task. If the task's start time is zero at this time, it will set it to the finish time minus the timeout time.

func (*Task) MarkFailed

func (t *Task) MarkFailed() error

MarkFailed changes the state of the task to failed.

func (*Task) MarkGeneratedTasks

func (t *Task) MarkGeneratedTasks() error

MarkGeneratedTasks marks that the task has generated tasks.

func (*Task) MarkStart

func (t *Task) MarkStart(startTime time.Time) error

MarkStart updates the task's start time and sets the status to started

func (*Task) MarkSystemFailed

func (t *Task) MarkSystemFailed() error

func (*Task) MarkUnscheduled

func (t *Task) MarkUnscheduled() error

MarkUnscheduled marks the task as undispatched and updates it in the database

func (*Task) MarshalBSON

func (t *Task) MarshalBSON() ([]byte, error)

func (*Task) MergeNewTestResults

func (t *Task) MergeNewTestResults() error

MergeNewTestResults returns the task with both old (embedded in the tasks collection) and new (from the testresults collection) test results merged in the Task's LocalTestResults field.

func (*Task) PreviousCompletedTask

func (t *Task) PreviousCompletedTask(project string, statuses []string) (*Task, error)

Find the previously completed task for the same project + build variant + display name combination as the specified task

func (*Task) Reset

func (t *Task) Reset() error

Reset sets the task state to be activated, with a new secret, undispatched status and zero time on Start, Scheduled, Dispatch and FinishTime

func (*Task) ResultStatus

func (t *Task) ResultStatus() string

ResultStatus returns the status for this task that should be displayed in the UI. Itb uses a combination of the TaskEndDetails and the Task's status to determine the state of the task.

func (*Task) SetAborted

func (t *Task) SetAborted() error

SetAborted sets the abort field of task to aborted

func (*Task) SetCost

func (t *Task) SetCost(cost float64) error

SetCost updates the task's Cost field

func (*Task) SetExpectedDuration

func (t *Task) SetExpectedDuration(duration time.Duration) error

SetExpectedDuration updates the expected duration field for the task

func (*Task) SetOverrideDependencies

func (t *Task) SetOverrideDependencies(userID string) error

func (*Task) SetPriority

func (t *Task) SetPriority(priority int64, user string) error

SetPriority sets the priority of the tasks and the tasks that they depend on

func (*Task) SetResetWhenFinished

func (t *Task) SetResetWhenFinished() error

SetResetWhenFinished requests that a display task reset itself when finished. Will mark itself as system failed

func (*Task) SetResults

func (t *Task) SetResults(results []TestResult) error

SetResults sets the results of the task in LocalTestResults

func (*Task) String

func (t *Task) String() (taskStruct string)

String represents the stringified version of a task

func (*Task) UnmarshalBSON

func (t *Task) UnmarshalBSON(in []byte) error

func (*Task) UpdateDependencies

func (t *Task) UpdateDependencies(dependsOn []Dependency) error

UpdateDependencies replaces the dependencies of a task with the dependencies provided

func (*Task) UpdateHeartbeat

func (t *Task) UpdateHeartbeat() error

UpdateHeartbeat updates the heartbeat to be the current time

type TaskBookkeeping

type TaskBookkeeping struct {
	// standard object id
	Id primitive.ObjectID `bson:"_id"`

	// info that tasks with the same guessed duration will share
	Name         string `bson:"name"`
	BuildVariant string `bson:"build_variant"`
	HostType     string `bson:"host_type"` // may change to an enum once Host.HostType changes
	Project      string `bson:"branch"`

	// the duration we expect the task to take
	ExpectedDuration time.Duration `bson:"expected_duration"`

	// the number of times this task - as defined by the
	// buildvariant and task name - has been started
	NumStarted int64 `bson:"num_started"`
}

type TaskStatusCount

type TaskStatusCount struct {
	Succeeded    int `json:"succeeded"`
	Failed       int `json:"failed"`
	Started      int `json:"started"`
	Undispatched int `json:"undispatched"`
	Inactive     int `json:"inactive"`
	Dispatched   int `json:"dispatched"`
	TimedOut     int `json:"timed_out"`
}

TaskStatusCount holds counts for task statuses

func (*TaskStatusCount) IncrementStatus

func (tsc *TaskStatusCount) IncrementStatus(status string, statusDetails apimodels.TaskEndDetail)

type Tasks

type Tasks []*Task

func (Tasks) Insert

func (t Tasks) Insert() error

func (Tasks) InsertUnordered

func (t Tasks) InsertUnordered(ctx context.Context) error

func (Tasks) Len

func (t Tasks) Len() int

func (Tasks) Less

func (t Tasks) Less(i, j int) bool

func (Tasks) Swap

func (t Tasks) Swap(i, j int)

type TestResult

type TestResult struct {
	Status    string  `json:"status" bson:"status"`
	TestFile  string  `json:"test_file" bson:"test_file"`
	URL       string  `json:"url" bson:"url,omitempty"`
	URLRaw    string  `json:"url_raw" bson:"url_raw,omitempty"`
	LogId     string  `json:"log_id,omitempty" bson:"log_id,omitempty"`
	LineNum   int     `json:"line_num,omitempty" bson:"line_num,omitempty"`
	ExitCode  int     `json:"exit_code" bson:"exit_code"`
	StartTime float64 `json:"start" bson:"start"`
	EndTime   float64 `json:"end" bson:"end"`

	// LogRaw is not saved in the task
	LogRaw string `json:"log_raw" bson:"log_raw,omitempty"`
}

func ConvertToOld

func ConvertToOld(in *testresult.TestResult) TestResult

type VersionCost

type VersionCost struct {
	VersionId        string        `bson:"version_id"`
	SumTimeTaken     time.Duration `bson:"sum_time_taken"`
	SumEstimatedCost float64       `bson:"sum_estimated_cost"`
}

VersionCost is service level model for representing cost data related to a version. SumTimeTaken is the aggregation of time taken by all tasks associated with a version.

Jump to

Keyboard shortcuts

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