コード例 #1
0
ファイル: task.go プロジェクト: pritten/evergreen
func (t *Task) markEnd(caller string, finishTime time.Time, detail *apimodels.TaskEndDetail) error {
	// record that the task has finished, in memory and in the db
	t.Status = detail.Status
	t.FinishTime = finishTime
	t.TimeTaken = finishTime.Sub(t.StartTime)
	t.Details = *detail
	err := UpdateOneTask(
		bson.M{
			TaskIdKey: t.Id,
		},
		bson.M{
			"$set": bson.M{
				TaskFinishTimeKey: finishTime,
				TaskStatusKey:     detail.Status,
				TaskTimeTakenKey:  t.TimeTaken,
				TaskDetailsKey:    t.Details,
			},
			"$unset": bson.M{
				TaskAbortedKey: "",
			},
		})

	if err != nil {
		return fmt.Errorf("error updating task: %v", err.Error())
	}
	event.LogTaskFinished(t.Id, detail.Status)
	return nil
}
コード例 #2
0
ファイル: task_lifecycle.go プロジェクト: tychoish/evergreen
// MarkEnd updates the task as being finished, performs a stepback if necessary, and updates the build status
func MarkEnd(taskId, caller string, finishTime time.Time, detail *apimodels.TaskEndDetail, p *Project, deactivatePrevious bool) error {

	t, err := task.FindOne(task.ById(taskId))
	if err != nil {
		return err
	}
	if t == nil {
		return fmt.Errorf("Task not found for taskId: %v", taskId)
	}

	if t.Status == detail.Status {
		evergreen.Logger.Logf(slogger.WARN, "Tried to mark task %v as finished twice", t.Id)
		return nil
	}

	t.Details = *detail

	err = t.MarkEnd(caller, finishTime, detail)
	if err != nil {
		return err
	}
	event.LogTaskFinished(t.Id, t.HostId, detail.Status)

	// update the cached version of the task, in its build document
	err = build.SetCachedTaskFinished(t.BuildId, t.Id, detail, t.TimeTaken)
	if err != nil {
		return fmt.Errorf("error updating build: %v", err.Error())
	}

	// no need to activate/deactivate other task if this is a patch request's task
	if t.Requester == evergreen.PatchVersionRequester {
		err = UpdateBuildAndVersionStatusForTask(t.Id)
		if err != nil {
			return fmt.Errorf("Error updating build status (1): %v", err.Error())
		}
		return nil
	}
	if detail.Status == evergreen.TaskFailed {
		shouldStepBack, err := getStepback(t.Id, p)
		if err != nil {
			return err
		}
		if shouldStepBack {
			err = doStepback(t, caller, detail, deactivatePrevious)
			if err != nil {
				return fmt.Errorf("Error during step back: %v", err.Error())
			}
		} else {
			evergreen.Logger.Logf(slogger.DEBUG, "Not stepping backwards on task failure: %v", t.Id)
		}

	} else if deactivatePrevious {
		// if the task was successful, ignore running previous
		// activated tasks for this buildvariant
		err = DeactivatePreviousTasks(t.Id, caller)
		if err != nil {
			return fmt.Errorf("Error deactivating previous task: %v", err.Error())
		}
	}

	// update the build
	if err := UpdateBuildAndVersionStatusForTask(t.Id); err != nil {
		return fmt.Errorf("Error updating build status (2): %v", err.Error())
	}

	return nil
}