func startAsync()

in internal/goalstate/goalstate.go [85:128]


func startAsync(ctx *log.Context, setting settings.SettingsCommon, notifier *observer.Notifier, done chan bool, err chan error) {
	if notifier == nil {
		err <- errors.New("notifier is nil. Cannot report status to HGAP")
		return
	}

	cmd, ok := commands.Cmds[enableCommand]
	if !ok {
		err <- errors.New("missing enable command")
		return
	}

	// Overwrite function to report status to HGAP. This function prepares the status to be sent to the HGAP and then calls the notifier to send it.
	cmd.Functions.ReportStatus = func(ctx *log.Context, _ types.HandlerEnvironment, metadata types.RCMetadata, statusType types.StatusType, c types.Cmd, msg string) error {
		if !c.ShouldReportStatus {
			ctx.Log("status", "not reported for operation (by design)")
			return nil
		}

		statusItem, err := status.GetSingleStatusItem(ctx, statusType, c, msg)
		if err != nil {
			return errors.Wrap(err, "failed to get status item")
		}

		ctx.Log("message", fmt.Sprintf("reporting status by notifying the observer to then send to HGAP for extension name %v and seq number %v", metadata.ExtName, metadata.SeqNum))
		return notifier.Notify(types.StatusEventArgs{
			StatusKey: types.GoalStateKey{
				ExtensionName: metadata.ExtName,
				SeqNumber:     metadata.SeqNum,
			},
			TopLevelStatus: statusItem,
		})
	}

	// Overwrite function to cleanup the command. This function is called after the command has been executed.
	cmd.Functions.Cleanup = cleanup.ImmediateRunCommandCleanup

	var hs handlersettings.HandlerSettingsFile
	var runtimeSettings []handlersettings.RunTimeSettingsFile
	hs.RuntimeSettings = append(runtimeSettings, handlersettings.RunTimeSettingsFile{HandlerSettings: setting})
	ctx.Log("message", "executing immediate goal state")
	commandProcessor.ProcessImmediateHandlerCommand(cmd, hs, *setting.ExtensionName, *setting.SeqNo)
	done <- true
}