better startup flow
This commit is contained in:
1 parent
d7f5dba677
commit
650bcff83a
8 files changed
+345
-68
No files matched your search
@@ -218,8 +218,11 @@ func (b *Bot) onMessage(ctx context.Context, m incoming) {
|
||||
ownerID, kind := m.owner()
|
||||
var off *node.NodeOfflineError
|
||||
var full *node.NodeFullError
|
||||
u, err := b.mgr.Ensure(ctx, ownerID, kind)
|
||||
sl := &startLog{b: b, m: m, root: root, ownerID: ownerID}
|
||||
started := func(ev manager.StartEvent) { sl.event(ctx, ev) }
|
||||
u, err := b.mgr.EnsureProgress(ctx, ownerID, kind, started)
|
||||
if errors.As(err, &full) {
|
||||
sl.failed(ctx, fmt.Sprintf("`%s` is full, so the container is being moved to a node with room first.", full.Node))
|
||||
edit(fmt.Sprintf(":truck: %s is full, so this container is being moved to a node with room…", full.Node))
|
||||
trigger := fmt.Sprintf("auto process (%s was full), for <@%s>'s message", full.Node, m.user)
|
||||
_, merr := b.runMove(ctx, m.channel, ownerID, manager.MoveOptions{StartAfter: true}, trigger, func(link string) {
|
||||
@@ -230,13 +233,15 @@ func (b *Bot) onMessage(ctx context.Context, m incoming) {
|
||||
return
|
||||
}
|
||||
edit(":hourglass_flowing_sand: Moved. Getting the container ready…")
|
||||
u, err = b.mgr.Ensure(ctx, ownerID, kind)
|
||||
u, err = b.mgr.EnsureProgress(ctx, ownerID, kind, started)
|
||||
}
|
||||
if errors.As(err, &off) {
|
||||
sl.failed(ctx, fmt.Sprintf("Node `%s` is offline.", off.Node))
|
||||
b.deadSlave(ctx, m.channel, ph, ownerID, off.Node)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
sl.failed(ctx, b.explain(err))
|
||||
edit(b.explain(err))
|
||||
return
|
||||
}
|
||||
@@ -246,13 +251,16 @@ func (b *Bot) onMessage(ctx context.Context, m incoming) {
|
||||
|
||||
acp, err := b.client(ctx, u)
|
||||
if errors.As(err, &off) {
|
||||
sl.failed(ctx, fmt.Sprintf("Node `%s` went offline.", off.Node))
|
||||
b.deadSlave(ctx, m.channel, ph, ownerID, off.Node)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
sl.failed(ctx, "The agent never became ready: "+err.Error())
|
||||
edit(":warning: Couldn't reach the agent: " + err.Error())
|
||||
return
|
||||
}
|
||||
sl.up(ctx)
|
||||
|
||||
var id string
|
||||
text := m.text
|
||||
@@ -510,7 +518,11 @@ func (b *Bot) stopFor(ctx context.Context, ownerID string) string {
|
||||
return ":warning: Couldn't stop it: " + err.Error()
|
||||
}
|
||||
b.dropClient(u)
|
||||
return "Shutting down the container. Its files are kept. Message me anytime to start it again."
|
||||
reply := "Shutting down the container. Its files are kept. Message me anytime to start it again."
|
||||
if link := b.announceStop(ctx, u, "Stopped on request."); link != "" {
|
||||
reply += fmt.Sprintf(" <%s|Follow the shutdown here>.", link)
|
||||
}
|
||||
return reply
|
||||
}
|
||||
|
||||
func (b *Bot) scaleFor(ctx context.Context, ownerID string, kind model.OwnerKind, args string) (reply string, ok bool) {
|
||||
@@ -1074,6 +1086,9 @@ func (b *Bot) reapOnce(ctx context.Context) {
|
||||
b.dropClient(&u)
|
||||
msg := fmt.Sprintf("I stopped the container after %s without use. Its files are kept. "+
|
||||
"Message me anytime to start it again, or use `keep` to change how long it waits.", commands.Human(limit))
|
||||
if link := b.announceStop(ctx, &u, fmt.Sprintf("Unused for %s.", commands.Human(limit))); link != "" {
|
||||
msg += fmt.Sprintf(" <%s|Shutdown details>.", link)
|
||||
}
|
||||
b.say(ctx, u.ID, "", msg) // a user ID posts to their DM, a channel ID to the channel
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user