Skip to content

Commit

Permalink
Handle and log service metadata publication errors rather than exitin…
Browse files Browse the repository at this point in the history
…g (refs #22)
  • Loading branch information
jhkolb committed Oct 17, 2017
1 parent 83ae6af commit 921df44
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion spawnd/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"github.com/SoftwareDefinedBuildings/spawnpoint/objects"
bw2 "gopkg.in/immesys/bw2bind.v5"
bw2 "github.com/immesys/bw2bind"
)

type BWLogger struct {
Expand Down
35 changes: 28 additions & 7 deletions spawnd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/pkg/errors"

docker "github.com/fsouza/go-dockerclient"
bw2 "gopkg.in/immesys/bw2bind.v5"
bw2 "github.com/immesys/bw2bind"
yaml "gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -207,8 +207,7 @@ func actionDecommission(c *cli.Context) error {
service := bwClients[i].RegisterService(cfg.Path, "s.spawnpoint")
iface := service.RegisterInterface("server", "i.spawnpoint")
// Publishing a message without any POs is effectively a "de-persist"
err = iface.PublishSignal("heartbeat")
if err != nil {
if err = iface.PublishSignal("heartbeat"); err != nil {
logs[i].Fatalf("Failed to decommission spawnpoint %s: %v", cfg.Alias, err)
}
}
Expand Down Expand Up @@ -252,12 +251,34 @@ func actionRun(c *cli.Context) error {
spInterfaces = make([]*bw2.Interface, len(cfgs))
for i, cfg := range cfgs {
spServices[i] = bwClients[i].RegisterService(cfg.Path, "s.spawnpoint")
spServices[i].SetErrorHandler(func(err error) {
logs[i].Errorf("Failed to register service metadata: %s", err)
})
spInterfaces[i] = spServices[i].RegisterInterface("server", "i.spawnpoint")

spInterfaces[i].SubscribeSlot("config", curryHandleConfig(i))
spInterfaces[i].SubscribeSlot("restart", curryHandleRestart(i))
spInterfaces[i].SubscribeSlot("stop", curryHandleStop(i))
spInterfaces[i].SubscribeSlot("logs", curryHandleLogs(i))
if err = spInterfaces[i].SubscribeSlot("config", curryHandleConfig(i)); err != nil {
logs[i].Fatalf("Failed to subscribe to slot %s: %s", spInterfaces[i].SlotURI("config"), err)
} else {
logs[i].Debugf("Subscribed to slot %s", spInterfaces[i].SlotURI("config"))
}

if err = spInterfaces[i].SubscribeSlot("restart", curryHandleRestart(i)); err != nil {
logs[i].Fatalf("Failed to subscribe to slot %s: %s", spInterfaces[i].SlotURI("restart"), err)
} else {
logs[i].Debugf("Subscribed to slot %s", spInterfaces[i].SlotURI("restart"))
}

if err = spInterfaces[i].SubscribeSlot("stop", curryHandleStop(i)); err != nil {
logs[i].Fatalf("Failed to subscribe to slot: %s: %s", spInterfaces[i].SlotURI("stop"), err)
} else {
logs[i].Debugf("Subscribed to slot %s", spInterfaces[i].SlotURI("stop"))
}

if err = spInterfaces[i].SubscribeSlot("logs", curryHandleLogs(i)); err != nil {
logs[i].Fatalf("Failed to subscribe to slot: %s: %s", spInterfaces[i].SlotURI("logs"), err)
} else {
logs[i].Debugf("Subscribed to slot %s", spInterfaces[i].SlotURI("logs"))
}
}

// Set Spawnpoint metadata
Expand Down

0 comments on commit 921df44

Please sign in to comment.