Documentation ¶
Index ¶
- Constants
- Variables
- func AbortBuild(buildId string) error
- func Aggregate(pipeline []bson.M, results interface{}) error
- func AverageTaskTimeDifference(field1 string, field2 string, groupByField string, cutoff time.Time) (map[string]time.Duration, error)
- func ByAborted(aborted bool) db.Q
- func ByActivatedBeforeRevisionWithStatuses(revisionOrder int, statuses []string, ...) db.Q
- func ByActivation(active bool) db.Q
- func ByBeforeRevision(revisionOrder int, buildVariant, displayName, project, requester string) db.Q
- func ByBeforeRevisionWithStatuses(revisionOrder int, statuses []string, ...) db.Q
- func ByBeforeRevisionWithStatusesAndRequester(revisionOrder int, statuses []string, ...) db.Q
- func ByBuildId(buildId string) db.Q
- func ByBuildIdAfterTaskId(buildId, taskId string) db.Q
- func ByCommit(revision, buildVariant, displayName, project, requester string) db.Q
- func ByDifferentFailedBuildVariants(revision, buildVariant, displayName, project, requester string) db.Q
- func ByDispatchedWithIdsVersionAndStatus(taskIds []string, versionId string, statuses []string) db.Q
- func ById(id string) db.Q
- func ByIds(ids []string) db.Q
- func ByIdsBuildAndStatus(taskIds []string, buildId string, statuses []string) db.Q
- func ByIntermediateRevisions(previousRevisionOrder, currentRevisionOrder int, ...) db.Q
- func ByOrderNumbersForNameAndVariant(revisionOrder []int, displayName, buildVariant string) db.Q
- func ByRecentlyFinished(finishTime time.Time, project string, requester string) db.Q
- func ByRunningLastHeartbeat(threshold time.Time) db.Q
- func ByStatusAndActivation(status string, active bool) db.Q
- func ByStatuses(statuses []string, buildVariant, displayName, project, requester string) db.Q
- func ByTimeRun(startTime, endTime time.Time) db.Q
- func ByVersion(version string) db.Q
- func Count(query db.Q) (int, error)
- func ExpectedTaskDuration(project, buildvariant string, window time.Duration) (map[string]time.Duration, error)
- func IsAbortable(t Task) bool
- func IsFinished(t Task) bool
- func Remove(id string) error
- func RemoveAllWithBuild(buildId string) error
- func ResetTasks(taskIds []string) error
- func SetTasksScheduledTime(tasks []Task, scheduledTime time.Time) error
- func TasksByBuildIdPipeline(buildId, taskId, taskStatus string, limit, sortDir int) []bson.M
- func TasksByProjectAndCommitPipeline(projectId, commitHash, taskId, taskStatus string, limit, sortDir int) []bson.M
- func TestResultsByTaskIdPipeline(taskId, testFilename, testStatus string, limit, sortDir int) []bson.M
- func UpdateAll(query interface{}, update interface{}) (*mgo.ChangeInfo, error)
- func UpdateOne(query interface{}, update interface{}) error
- type Dependency
- type Task
- func (t *Task) ActivateTask(caller string) error
- func (t *Task) Archive() error
- func (t *Task) ClearResults() error
- func (t *Task) CountSimilarFailingTasks() (int, error)
- func (t *Task) DeactivateTask(caller string) error
- func (t *Task) DependenciesMet(depCaches map[string]Task) (bool, error)
- func (current *Task) FindIntermediateTasks(previous *Task) ([]Task, error)
- func (t *Task) FindTaskOnBaseCommit() (*Task, error)
- func (t *Task) Insert() error
- func (t *Task) IsDispatchable() bool
- func (t *Task) MarkAsDispatched(hostId string, distroId string, dispatchTime time.Time) error
- func (t *Task) MarkAsUndispatched() error
- func (t *Task) MarkEnd(finishTime time.Time, detail *apimodels.TaskEndDetail) error
- func (t *Task) MarkFailed() error
- func (t *Task) MarkStart(startTime time.Time) error
- func (t *Task) MarkUnscheduled() error
- func (t *Task) PreviousCompletedTask(project string, statuses []string) (*Task, error)
- func (t *Task) Reset() error
- func (t *Task) SetAborted() error
- func (t *Task) SetCost(cost float64) error
- func (t *Task) SetExpectedDuration(duration time.Duration) error
- func (t *Task) SetPriority(priority int64) error
- func (t *Task) SetResults(results []TestResult) error
- func (t *Task) String() (taskStruct string)
- func (t *Task) UIStatus() string
- func (t *Task) UpdateHeartbeat() error
- type TestResult
- type TestResults
Constants ¶
const ( Collection = "tasks" OldCollection = "old_tasks" TestLogPath = "/test_log/" )
Variables ¶
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") 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") )
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") )
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} )
var ( IsUndispatched = ByStatusAndActivation(evergreen.TaskUndispatched, true) IsDispatchedOrStarted = db.Query(bson.M{ StatusKey: bson.M{"$in": []string{evergreen.TaskStarted, evergreen.TaskDispatched}}, }) )
var (
AgentHeartbeat = "heartbeat"
)
var All = db.Query(nil)
All returns all tasks.
var (
AllStatuses = "*"
)
Functions ¶
func AbortBuild ¶
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 ByActivation ¶
ByAborted creates a query to return tasks with an aborted state
func ByBeforeRevision ¶
func ByBuildIdAfterTaskId ¶
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 ¶
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 ByIdsBuildAndStatus ¶
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 ByRecentlyFinished ¶
func ByRunningLastHeartbeat ¶
ByRunningLastHeartbeat creates a query that finds any running tasks whose last heartbeat was at least the specified threshold ago
func ByStatusAndActivation ¶
ByStatusAndActivation creates a query that returns tasks of a certain status and activation state.
func ByStatuses ¶
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 IsFinished ¶
IsFinished returns true if the project is no longer running
func RemoveAllWithBuild ¶
Remove all deletes all tasks with a given buildId
func ResetTasks ¶
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 ¶
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 ¶
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, sortDir int) []bson.M
TasksByProjectAndCommitPipeline fetches the pipeline to get the retrieve all tasks associated with a given project and commit hash.
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.
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 FindOneOld ¶
FindOneOld returns one task from the old tasks collection that satisfies the query.
func (*Task) ActivateTask ¶
ActivateTask will set the ActivatedBy field to the caller and set the active state to be true
func (*Task) ClearResults ¶
ClearResults sets the TestResults to an empty list
func (*Task) CountSimilarFailingTasks ¶
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 ¶
DeactivateTask will set the ActivatedBy field to the caller and set the active state to be false and deschedule the task
func (*Task) DependenciesMet ¶
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 ¶
FindIntermediateTasks returns the tasks from most recent to least recent between two tasks.
func (*Task) FindTaskOnBaseCommit ¶
FindTaskOnBaseCommit returns the task that is on the base commit.
func (*Task) IsDispatchable ¶
IsDispatchable return true if the task should be dispatched
func (*Task) MarkAsDispatched ¶
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 ¶
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 ¶
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 ¶
MarkFailed changes the state of the task to failed.
func (*Task) MarkUnscheduled ¶
MarkUnscheduled marks the task as undispatched and updates it in the database
func (*Task) PreviousCompletedTask ¶
Find the previously completed task for the same requester + project + build variant + display name combination as the specified task
func (*Task) Reset ¶
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 ¶
SetAborted sets the abort field of task to aborted
func (*Task) SetExpectedDuration ¶
SetExpectedDuration updates the expected duration field for the task
func (*Task) SetPriority ¶
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) UIStatus ¶
UIStatus returns the status for this task that should be displayed in the UI. It uses a combination of the TaskEndDetails and the Task's status to determine the state of the task.
func (*Task) UpdateHeartbeat ¶
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.