task

package
v0.0.0-...-a204096 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Collection    = "tasks"
	OldCollection = "old_tasks"
	TestLogPath   = "/test_log/"
)

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")
	PushTimeKey            = bsonutil.MustHaveTag(Task{}, "PushTime")
	ScheduledTimeKey       = bsonutil.MustHaveTag(Task{}, "ScheduledTime")
	StartTimeKey           = bsonutil.MustHaveTag(Task{}, "StartTime")
	FinishTimeKey          = bsonutil.MustHaveTag(Task{}, "FinishTime")
	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")
	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")
	TestResultsKey         = bsonutil.MustHaveTag(Task{}, "TestResults")
	PriorityKey            = bsonutil.MustHaveTag(Task{}, "Priority")
	ActivatedByKey         = bsonutil.MustHaveTag(Task{}, "ActivatedBy")
	CostKey                = bsonutil.MustHaveTag(Task{}, "Cost")

	// BSON fields for the test result struct
	TestResultStatusKey    = bsonutil.MustHaveTag(TestResult{}, "Status")
	TestResultTestFileKey  = bsonutil.MustHaveTag(TestResult{}, "TestFile")
	TestResultURLKey       = bsonutil.MustHaveTag(TestResult{}, "URL")
	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 = "*"
)

Functions

func AbortBuild

func AbortBuild(buildId string) error

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

func AverageTaskTimeDifference

func AverageTaskTimeDifference(field1 string, field2 string,
	groupByField string, cutoff time.Time) (map[string]time.Duration, error)

AverageTaskTimeDifference takes two field names (such that field2 happened after field1), a field to group on, and a cutoff time. It returns the average duration between fields 1 and 2, grouped by the groupBy field, including only task documents where both time fields happened after the given cutoff time. This information is returned as a map from groupBy_field -> avg_time_difference

NOTE: THIS FUNCTION DOES NOT SANITIZE INPUT! BAD THINGS CAN HAPPEN IF NON-TIME FIELDNAMES ARE PASSED IN OR IF A FIELD OF NON-STRING TYPE IS SUPPLIED FOR groupBy!

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, displayName, 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 ByBeforeRevisionWithStatuses

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

func ByBeforeRevisionWithStatusesAndRequester

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

func ByBuildId

func ByBuildId(buildId string) db.Q

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

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 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 ByOrderNumbersForNameAndVariant

func ByOrderNumbersForNameAndVariant(revisionOrder []int, displayName, buildVariant string) db.Q

func ByRecentlyFinished

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

func ByRunningLastHeartbeat

func ByRunningLastHeartbeat(threshold time.Time) db.Q

ByRunningLastHeartbeat creates a query that finds any running tasks whose last heartbeat was at least the specified threshold ago

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 ByVersion

func ByVersion(version string) db.Q

ByVersion creates a query to return tasks with a certain build 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 GetTestUrl

func GetTestUrl(tr *TestResult) string

GetTestUrl returns the correct relative URL to a test log, given a TestResult structure

func IsAbortable

func IsAbortable(t Task) bool

Abortable returns true if the task can be aborted.

func IsFinished

func IsFinished(t Task) bool

IsFinished returns true if the project is no longer running

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 UpdateAll

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

func UpdateOne

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

UpdateOne updates one task.

Types

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 bson.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

type Task

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

	// time information for task
	// create - the time we created this task in our database
	// dispatch - the time the task runner starts up the agent on the host
	// push - the time the commit generating this build was pushed to the remote
	// 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"`
	DispatchTime  time.Time `bson:"dispatch_time" json:"dispatch_time"`
	PushTime      time.Time `bson:"push_time" json:"push_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"`

	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"`

	// only relevant if the task is running.  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"`

	// 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
	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
	ExpectedDuration time.Duration `bson:"expected_duration,omitempty" json:"expected_duration,omitempty"`

	// an estimate of what the task cost to run, hidden from JSON views for now
	Cost float64 `bson:"cost,omitempty" json:"-"`

	// test results captured and sent back by agent
	TestResults []TestResult `bson:"test_results" json:"test_results"`
}

func Find

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

Find returns all tasks that satisfy the query.

func FindOld

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

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

func FindOne

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

FindOne returns one task that satisfies the query.

func FindOneOld

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

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

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) Archive

func (t *Task) Archive() error

Inserts the task into the old_tasks collection

func (*Task) ClearResults

func (t *Task) ClearResults() error

ClearResults sets the TestResults to an empty list

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) 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) Insert

func (t *Task) Insert() error

Insert writes the b to the db.

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(caller string, finishTime time.Time, detail *apimodels.TaskEndDetail) error

MarkEnd handles the Task updates associated with ending a task.

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) MarkUnscheduled

func (t *Task) MarkUnscheduled() error

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

func (*Task) PreviousCompletedTask

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

Find the previously completed task for the same requester + 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) 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) SetPriority

func (t *Task) SetPriority(priority int64) error

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

func (*Task) SetResults

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

SetResults sets the results of the task in TestResults

func (*Task) String

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

String represents the stringified version of a task

func (*Task) UpdateHeartbeat

func (t *Task) UpdateHeartbeat() error

UpdateHeartbeat updates the heartbeat to be the current time

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"`
}

type TestResults

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

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

Jump to

Keyboard shortcuts

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