Exemple #1
0
func (t *Task) Abort(caller string, aborted bool) error {
	if !t.Abortable() {
		return fmt.Errorf("Task '%v' is currently '%v' - cannot abort task"+
			" in this status", t.Id, t.Status)
	}

	evergreen.Logger.Logf(slogger.DEBUG, "Setting abort=%v for task %v", aborted, t.Id)

	err := SetTaskActivated(t.Id, caller, false)
	if err != nil {
		return err
	}

	err = UpdateOneTask(
		bson.M{
			TaskIdKey: t.Id,
		},
		bson.M{
			"$set": bson.M{
				TaskAbortedKey: aborted,
			},
		},
	)
	if err != nil {
		return err
	}

	event.LogTaskAbortRequest(t.Id, caller)

	t.Aborted = aborted
	return nil
}
Exemple #2
0
func AbortTask(taskId, caller string) error {
	t, err := task.FindOne(task.ById(taskId))
	if err != nil {
		return err
	}

	if !task.IsAbortable(*t) {
		return fmt.Errorf("Task '%v' is currently '%v' - cannot abort task"+
			" in this status", t.Id, t.Status)
	}

	evergreen.Logger.Logf(slogger.DEBUG, "Aborting task %v", t.Id)
	// set the active state and then set the abort
	if err = SetActiveState(t.Id, caller, false); err != nil {
		return err
	}
	event.LogTaskAbortRequest(t.Id, caller)
	return t.SetAborted()
}