consumer

package
v0.0.0-...-34c5bf1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HandleSetSceneEvent scenedef.SetSceneEventHandler = func(body *scenedef.SetSceneEvent) firehose.Result {
	metadata := map[string]string{
		"scene_id": strconv.Itoa(int(body.SceneId)),
	}

	scene := &domain.Scene{}
	if err := database.Find(&scene, body.SceneId); err != nil {
		return firehose.Discard(oops.WithMetadata(err, metadata))
	}

	if scene == nil {
		err := oops.NotFound("scene not found", metadata)
		return firehose.Discard(err)
	}

	lock, err := distsync.Lock(nil, "scene", body.SceneId)
	if err != nil {
		return firehose.Fail(oops.WithMetadata(err, metadata))
	}
	defer lock.Unlock()

	slog.Infof("Setting scene %d...", body.SceneId)

	stages := constructStages(scene)

	for _, stage := range stages {
		var g errgroup.Group
		for _, action := range stage {
			g.Go(func() error {
				return action.Perform(context.TODO())
			})
		}
		if err := g.Wait(); err != nil {
			return firehose.Fail(err)
		}
	}

	return firehose.Success()
}

HandleSetSceneEvent sets the scene

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL