예제 #1
0
func MarkTaskDispatched(t *task.Task, hostId, distroId string) error {
	// record that the task was dispatched on the host
	if err := t.MarkAsDispatched(hostId, distroId, time.Now()); err != nil {
		return fmt.Errorf("error marking task %v as dispatched "+
			"on host %v: %v", t.Id, hostId, err)
	}
	// the task was successfully dispatched, log the event
	event.LogTaskDispatched(t.Id, hostId)

	// update the cached version of the task in its related build document
	if err := build.SetCachedTaskDispatched(t.BuildId, t.Id); err != nil {
		return fmt.Errorf("error updating task cache in build %v: %v", t.BuildId, err)
	}
	return nil
}
예제 #2
0
파일: task.go 프로젝트: pritten/evergreen
// 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, as well
// as updating the cache for the task in its build document in the db.
// Returns an error if any of the database updates fail.
func (t *Task) MarkAsDispatched(host *host.Host, dispatchTime time.Time) error {
	// then, update the task document
	t.DispatchTime = dispatchTime
	t.Status = evergreen.TaskDispatched
	t.HostId = host.Id
	t.LastHeartbeat = dispatchTime
	t.DistroId = host.Distro.Id
	err := UpdateOneTask(
		bson.M{
			TaskIdKey: t.Id,
		},
		bson.M{
			"$set": bson.M{
				TaskDispatchTimeKey:  dispatchTime,
				TaskStatusKey:        evergreen.TaskDispatched,
				TaskHostIdKey:        host.Id,
				TaskLastHeartbeatKey: dispatchTime,
				TaskDistroIdKey:      host.Distro.Id,
			},
			"$unset": bson.M{
				TaskAbortedKey:     "",
				TaskTestResultsKey: "",
				TaskDetailsKey:     "",
				TaskMinQueuePosKey: "",
			},
		},
	)
	if err != nil {
		return fmt.Errorf("error updating task with id %v: %v", t.Id, err)
	}

	// the task was successfully dispatched, log the event
	event.LogTaskDispatched(t.Id, host.Id)

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