Example #1
0
// UpdateRunningTask takes two id strings - an old task and a new one - finds
// the host running the task with Id, 'prevTaskId' and updates its running task
// to 'newTaskId'; also setting the completion time of 'prevTaskId'
func (host *Host) UpdateRunningTask(prevTaskId, newTaskId string,
	finishTime time.Time) (err error) {
	selector := bson.M{
		IdKey: host.Id,
	}
	update := bson.M{
		"$set": bson.M{
			LTCKey:         prevTaskId,
			RunningTaskKey: newTaskId,
			LTCTimeKey:     finishTime,
			PidKey:         "",
		},
	}

	if err = UpdateOne(selector, update); err == nil {
		event.LogHostRunningTaskSet(host.Id, newTaskId)
	}
	return err
}
Example #2
0
// Marks that the specified task was started on the host at the specified time.
func (self *Host) SetRunningTask(taskId, agentRevision string,
	taskDispatchTime time.Time) error {

	// log the event
	event.LogHostRunningTaskSet(self.Id, taskId)

	// update the in-memory host, then the database
	self.RunningTask = taskId
	self.AgentRevision = agentRevision
	self.TaskDispatchTime = taskDispatchTime
	return UpdateOne(
		bson.M{
			IdKey: self.Id,
		},
		bson.M{
			"$set": bson.M{
				RunningTaskKey:      taskId,
				AgentRevisionKey:    agentRevision,
				TaskDispatchTimeKey: taskDispatchTime,
			},
		},
	)
}