Пример #1
0
// Deactivate any previously activated but undispatched
// tasks for the same build variant + display name + project combination
// as the task.
func DeactivatePreviousTasks(taskId, caller string) error {
	t, err := task.FindOne(task.ById(taskId))
	if err != nil {
		return err
	}
	statuses := []string{evergreen.TaskUndispatched}
	allTasks, err := task.Find(task.ByActivatedBeforeRevisionWithStatuses(t.RevisionOrderNumber, statuses, t.BuildVariant,
		t.DisplayName, t.Project))
	if err != nil {
		return err
	}
	for _, t := range allTasks {
		err = SetActiveState(t.Id, caller, false)
		if err != nil {
			return err
		}
		event.LogTaskDeactivated(t.Id, caller)
		// update the cached version of the task, in its build document to be deactivated
		if err = build.SetCachedTaskActivated(t.BuildId, t.Id, false); err != nil {
			return err
		}
	}

	return nil
}
Пример #2
0
func SetActiveState(taskId string, caller string, active bool) error {
	t, err := task.FindOne(task.ById(taskId))
	if err != nil {
		return err
	}
	if active {
		// if the task is being activated, make sure to activate all of the task's
		// dependencies as well
		for _, dep := range t.DependsOn {
			if err = SetActiveState(dep.TaskId, caller, true); err != nil {
				return fmt.Errorf("error activating dependency for %v with id %v: %v",
					taskId, dep.TaskId, err)
			}
		}

		if t.DispatchTime != util.ZeroTime && t.Status == evergreen.TaskUndispatched {
			err = resetTask(t.Id)
			if err != nil {
				return fmt.Errorf("error resetting task: %v:", err.Error())
			}
		} else {
			err = t.ActivateTask(caller)
			if err != nil {
				return fmt.Errorf("error while activating task: %v", err.Error())
			}
		}
		// if the caller is not evergreen or the the task is activated by evergreen, deactivate it
	} else if !evergreen.IsSystemActivator(caller) || evergreen.IsSystemActivator(t.ActivatedBy) {

		err = t.DeactivateTask(caller)
		if err != nil {
			return fmt.Errorf("error deactivating task : %v:", err.Error())
		}
	} else {
		return nil
	}

	if active {
		event.LogTaskActivated(taskId, caller)
	} else {
		event.LogTaskDeactivated(taskId, caller)
	}
	return build.SetCachedTaskActivated(t.BuildId, taskId, active)
}
Пример #3
0
func SetTaskActivated(taskId string, caller string, active bool) error {
	task, err := FindTask(taskId)
	if err != nil {
		return err
	}

	if active {

		// if the task is being activated, make sure to activate all of the task's
		// dependencies as well
		for _, dep := range task.DependsOn {
			if err = SetTaskActivated(dep.TaskId, caller, true); err != nil {
				return fmt.Errorf("error activating dependency for %v with id %v: %v",
					taskId, dep.TaskId, err)
			}
		}

		if task.DispatchTime != ZeroTime && task.Status == evergreen.TaskUndispatched {
			err = task.reset()
		} else {
			err = UpdateOneTask(
				bson.M{
					TaskIdKey: taskId,
				},
				bson.M{
					"$set": bson.M{
						TaskActivatedKey:   active,
						TaskActivatedByKey: caller,
					},
					"$unset": bson.M{
						TaskMinQueuePosKey: "",
					},
				},
			)
		}
		// if the caller is not evergreen or the the task is activated by evergreen, deactivate it
	} else if !build.IsSystemActivator(caller) || build.IsSystemActivator(task.ActivatedBy) {
		err = UpdateOneTask(
			bson.M{
				TaskIdKey: taskId,
			},
			bson.M{
				"$set": bson.M{
					TaskActivatedKey:     active,
					TaskScheduledTimeKey: ZeroTime,
				},
				"$unset": bson.M{
					TaskMinQueuePosKey: "",
				},
			},
		)
	} else {
		return nil
	}

	if err != nil {
		return err
	}

	if active {
		event.LogTaskActivated(taskId, caller)
	} else {
		event.LogTaskDeactivated(taskId, caller)
	}

	// update the cached version of the task, in its build document
	return build.SetCachedTaskActivated(task.BuildId, taskId, active)
}