func (w *Watcher) addLocked(d *structs.Deployment) (*deploymentWatcher, error) {
	// Not enabled so no-op
	if !w.enabled {
		return nil, nil
	}

	if !d.Active() {
		return nil, fmt.Errorf("deployment %q is terminal", d.ID)
	}

	// Already watched so no-op
	if _, ok := w.watchers[d.ID]; ok {
		return nil, nil
	}

	// Get the job the deployment is referencing
	args := &structs.JobSpecificRequest{
		JobID: d.JobID,
	}
	var resp structs.SingleJobResponse
	if err := w.stateWatchers.GetJob(args, &resp); err != nil {
		return nil, err
	}
	if resp.Job == nil {
		return nil, fmt.Errorf("deployment %q references unknown job %q", d.ID, d.JobID)
	}

	watcher := newDeploymentWatcher(w.ctx, w.queryLimiter, w.logger, w.stateWatchers, d, resp.Job, w)
	w.watchers[d.ID] = watcher
	return watcher, nil
}
// addLocked adds a deployment to the watch list and should only be called when
// locked.
addLocked adds a deployment to the watch list and should only be called when
locked.
// addLocked adds a deployment to the watch list and should only be called when // locked .
func (w *Watcher) addLocked(d *structs.Deployment) (*deploymentWatcher, error) {
	if !w.enabled {
		return nil, nil
	}
	if !d.Active() {
		return nil, fmt.Errorf("deployment %q is terminal", d.ID)
	}
	if _, ok := w.watchers[d.ID]; ok {
		return nil, nil
	}
	args := &structs.JobSpecificRequest{
		JobID: d.JobID,
	}
	var resp structs.SingleJobResponse
	if err := w.stateWatchers.GetJob(args, &resp); err != nil {
		return nil, err
	}
	if resp.Job == nil {
		return nil, fmt.Errorf("deployment %q references unknown job %q", d.ID, d.JobID)
	}
	watcher := newDeploymentWatcher(w.ctx, w.queryLimiter, w.logger, w.stateWatchers, d, resp.Job, w)
	w.watchers[d.ID] = watcher
	return watcher, nil
}
func ( w * Watcher ) addLocked ( d * structs . Deployment ) ( * deploymentWatcher , error ) { if ! w . enabled { return nil , nil } if ! d . Active ( ) { return nil , fmt . Errorf ( " " , d . ID ) } if _ , ok := w . watchers [ d . ID ] ; ok { return nil , nil } args := & structs . JobSpecificRequest { JobID : d . JobID , } var resp structs . SingleJobResponse if err := w . stateWatchers . GetJob ( args , & resp ) ; err != nil { return nil , err } if resp . Job == nil { return nil , fmt . Errorf ( " " , d . ID , d . JobID ) } watcher := newDeploymentWatcher ( w . ctx , w . queryLimiter , w . logger , w . stateWatchers , d , resp . Job , w ) w . watchers [ d . ID ] = watcher return watcher , nil }
addLocked adds a deployment to the watch list and should only be called when
locked.
addLocked adds a deployment to the watch list and should only be called when locked .
// Not enabled so no-op // Already watched so no-op // Get the job the deployment is referencing