Skip to content

Commit 85f58fd

Browse files
authored
feat: finish_after_command (#53)
* feat: finish_after_command
1 parent c73bc69 commit 85f58fd

16 files changed

Lines changed: 145 additions & 74 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ test_clean:
4141
go test -v ./test
4242

4343
test-integration:
44-
go test -v ./test/integration
44+
go test -timeout 1200s -v ./test/integration
4545

4646
test-integration-docker:
4747
docker build . -f Dockerfile.testing -t druid-cli-test
48-
docker run -v ./:/app --entrypoint=/bin/bash --rm druid-cli-test -c "go test -v ./test/integration"
49-
docker run -v ./:/app --entrypoint=/bin/bash --rm druid-cli-test -c "go test -v ./test/integration/commands"
48+
docker run -v ./:/app --entrypoint=/bin/bash --rm druid-cli-test -c "go test -timeout 1200s -v ./test/integration"
49+
docker run -v ./:/app --entrypoint=/bin/bash --rm druid-cli-test -c "go test -timeout 1200s -v ./test/integration/commands"
5050

5151
test-integration-docker-debug:
5252
docker build . -f Dockerfile.testing -t druid-cli-test

cmd/coldstarter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ var ColdstarterCmd = &cobra.Command{
2929

3030
logger.Log().Info("Scroll loaded", zap.String("Name", currentScroll.Name), zap.Any("Version", currentScroll.Version), zap.String("AppVersion", currentScroll.AppVersion), zap.Any("Ports", currentScroll.Ports))
3131

32-
portsService := services.NewPortServiceWithScrollFile(&currentScroll.File)
32+
portService := services.NewPortServiceWithScrollFile(&currentScroll.File)
3333

34-
coldStarter := services.NewColdStarter(scrollService.GetDir(), portsService)
34+
coldStarter := services.NewColdStarter(portService, nil, scrollService.GetDir())
3535

3636
finish := coldStarter.Start(context.TODO())
3737
<-finish

cmd/serve.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ to interact and monitor the Scroll Application`,
112112

113113
portService := services.NewPortServiceWithScrollFile(scrollService.GetFile())
114114

115-
coldStarter := services.NewColdStarter(scrollService.GetDir(), portService)
115+
coldStarter := services.NewColdStarter(portService, queueManager, scrollService.GetDir())
116116

117117
scrollHandler := handler.NewScrollHandler(scrollService, pluginManager, processLauncher, queueManager)
118118
processHandler := handler.NewProcessHandler(processManager)
@@ -165,18 +165,13 @@ to interact and monitor the Scroll Application`,
165165
finish := coldStarter.Start(ctx)
166166
executedPort := <-finish
167167

168-
if executedPort != nil && executedPort.StartDelay > 0 {
169-
go func() {
170-
time.Sleep(time.Duration(executedPort.StartDelay) * time.Second)
171-
coldStarter.Stop()
172-
}()
173-
} else {
174-
coldStarter.Stop()
168+
if executedPort.FinishAfterCommand == "" {
169+
coldStarter.Stop(executedPort.StartDelay)
175170
}
176171

177172
logger.Log().Info("Coldstarter done, starting scroll")
178173

179-
startup(scrollService, processLauncher, queueManager, cwd, doneChan)
174+
startup(scrollService, processLauncher, queueManager, portService, coldStarter, cwd, doneChan)
180175

181176
portService.ResetOpenPorts()
182177

@@ -216,10 +211,10 @@ to interact and monitor the Scroll Application`,
216211
}
217212
} else {
218213
logger.Log().Warn("No ports to start, skipping coldstarter")
219-
startup(scrollService, processLauncher, queueManager, cwd, doneChan)
214+
startup(scrollService, processLauncher, queueManager, portService, coldStarter, cwd, doneChan)
220215
}
221216
} else {
222-
startup(scrollService, processLauncher, queueManager, cwd, doneChan)
217+
startup(scrollService, processLauncher, queueManager, portService, coldStarter, cwd, doneChan)
223218
}
224219

225220
}()
@@ -269,7 +264,7 @@ func init() {
269264
ServeCommand.Flags().UintVarP(&maxStartupHealthCheckTimeout, "max-health-check-startup-timeount", "", 0, "Sets the max amount of time the health check is allowed to take on startup. If the value is 0, there will be no timeout. This is useful to prevent the health check from blocking the startup of the daemon fully.")
270265
}
271266

272-
func startup(scrollService *services.ScrollService, processLauncher *services.ProcedureLauncher, queueManager *services.QueueManager, cwd string, doneChan chan error) {
267+
func startup(scrollService *services.ScrollService, processLauncher *services.ProcedureLauncher, queueManager *services.QueueManager, portSerivce *services.PortMonitor, coldStarter *services.ColdStarter, cwd string, doneChan chan error) {
273268

274269
currentScroll := scrollService.GetCurrent()
275270

@@ -330,7 +325,17 @@ func startup(scrollService *services.ScrollService, processLauncher *services.Pr
330325
logger.Log().Info("Bootstrapping done")
331326
}
332327

333-
err = queueManager.QueueLockFile()
328+
callbacks := map[string]func(){}
329+
330+
for _, port := range portSerivce.GetPorts() {
331+
if port.FinishAfterCommand != "" {
332+
callbacks[port.FinishAfterCommand] = func() {
333+
coldStarter.Stop(port.StartDelay)
334+
}
335+
}
336+
}
337+
338+
err = queueManager.QueueLockFile(callbacks)
334339
if err != nil {
335340
doneChan <- err
336341
return

examples/minecraft/.scroll/packet_handler/minecraft.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ function handle(ctx, data)
107107

108108
while hex ~= "" do
109109

110+
queue = get_queue()
111+
110112
hex = string.tohex(restBytes)
111113

112114
debug_print("Remaining Bytes: " .. hex)
@@ -224,7 +226,10 @@ function pingResponse()
224226
favicon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAAXNSR0IArs4c6QAAAMlQTFRFR3BM6ndq5Wxb3WBQ6HFi0EUvvVxI8IBzzTwm0EUv11RC3GBQ7X1w00w50EUv42pa1lRB3mNT4WZV0Ugz2VlH0ks22lpJ0ks332RU1VI/6XZo8oV4421e63Zn32JR0046ytvZ2FZEieHa5nBgb+fZFerZ1NrZDOrZDurZ1tjYQunZztrZO+jZruDZFOrZDOrZDOrZ6HVoDOrZ09rZ0cvJn+LZbebZi+PZkOPZC+rZ942B7Xpr9op98oR29Id67n1uz9vZH+rZjeTZHadAYQAAADl0Uk5TAOr9sP4WBv4CDXqV8kcf3m277CmGPaAzx1Pg8tD90lw3YxDx/mzTQ+aq/nYk/bT50NSS71SwxIbiWYkesQAABERJREFUeNqll2tfozgUxkshIeF+vxWoiNfRUaszuztDC7rf/0PtISAlpR1dfPLzTZLzz3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qk6EDpl3XACLp7vu5llpoUPPKgOIDIIbSHLyOLy50ULJ5PMNTmoQ6zmzlICLR3bCunitAi1gJDH+MAZaj+7PU8pdJd+9I2ttIQ1nmRHEUIUk8WHQpYjSXlBF3NFaGFKkqkgMhtB41ySnMDFswlYt5fSMorpbBPEDRww4bl4LgKakbcm1gh/IY3WhKjPRhDDa004wXwE1kWzQxhzEciynRYhFuHcx8JQGGKZe7FLZ3a0RbB7qIRzERbUorURWWhuQ9Zq5CyXS0dBs++HbwU5EKwv3FJDh2rk/uILoqFlT38O/QdGyOZnTVzZRwAAAABJRU5ErkJggg=="
225227
}
226228

227-
if get_finish_sec() ~= nil then
229+
if queue ~= nil and queue["install"] == "running" then
230+
obj.version.name = "§2▶ Installing..."
231+
obj.description = "Installing Minecraft Server, this might take a moment"
232+
elseif get_finish_sec() ~= nil then
228233
obj.version.name = "§2▶ Starting..."
229234
obj.description = "Starting " .. math.ceil(get_finish_sec()) .. "s"
230235
end

examples/minecraft/.scroll/packet_handler/query.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,19 @@ function handle(ctx, data)
7676

7777
if packetId == "54" then
7878

79+
queue = get_queue()
7980
name = get_var("ServerListName") or "Coldstarter is cool (server is idle, join to start)"
8081

81-
if get_finish_sec() ~= nil then
82+
map = get_var("MapName") or "server idle"
83+
84+
if queue ~= nil and queue["install"] == "running" then
85+
name = get_var("ServerListNameInstalling") or "INSTALLING, this might take a moment"
86+
map = get_var("MapNameInstalling") or "installing server"
87+
elseif get_finish_sec() ~= nil then
8288
nameTemplate = get_var("ServerListNameStarting") or "Druid Gameserver (starting) - %ds"
8389
name = string.format(nameTemplate, math.ceil(get_finish_sec()))
8490
end
8591

86-
map = get_var("MapName") or "TheIsland"
87-
8892
folder = get_var("GameSteamFolder") or "ark_survival_evolved"
8993

9094
gameName = get_var("GameName") or "ARK: Survival Evolved"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"statuses":{"install":{"status":"done","exit_code":null,"last_status_change":1730062651},"start":{"status":"waiting","exit_code":null,"last_status_change":1730235343}},"scroll_version":"0.0.1","scroll_name":"registry-1.docker.io/highcard/scroll-minecraft-spigot"}
1+
{"statuses":{"install":{"status":"done","exit_code":null,"last_status_change":1731537003},"start":{"status":"running","exit_code":null,"last_status_change":1731539114}},"scroll_version":"0.0.1","scroll_name":"registry-1.docker.io/highcard/scroll-minecraft-spigot"}

examples/minecraft/.scroll/scroll.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ ports:
88
protocol: tcp
99
port: 25565
1010
sleep_handler: packet_handler/minecraft.lua
11-
start_delay: 10
1211
mandatory: true
1312
- name: query
1413
protocol: udp
@@ -27,7 +26,6 @@ ports:
2726
- name: ServerListNameStarting
2827
value: "▶️ Druid Gameserver (starting) - %ds"
2928
- name: main
30-
start_delay: 10
3129
protocol: udp
3230

3331
init: "start"

internal/core/domain/broadcast_channel.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func (h *BroadcastChannel) Run() {
4848
select {
4949
case client <- &message: // Try to send the message.
5050
default:
51-
logger.Log().Warn("Failed to Broadcast message to channel.. closing channel")
51+
// logger.Log().Warn("Channel seems to be closed, removing")
52+
logger.Log().Warn("Channel seems to be closed")
53+
// delete(h.Clients, client)
5254
// h.Unsubscribe(client)
5355
}
5456
}

internal/core/domain/scroll.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ type ColdStarterVars struct {
3232
}
3333

3434
type Port struct {
35-
Port int `yaml:"port" json:"port"`
36-
Protocol string `yaml:"protocol" json:"protocol"`
37-
Name string `yaml:"name" json:"name"`
38-
SleepHandler *string `yaml:"sleep_handler" json:"sleep_handler"`
39-
Mandatory bool `yaml:"mandatory" json:"mandatory"`
40-
Vars []ColdStarterVars `yaml:"vars" json:"vars"`
41-
StartDelay uint `yaml:"start_delay" json:"start_delay"`
35+
Port int `yaml:"port" json:"port"`
36+
Protocol string `yaml:"protocol" json:"protocol"`
37+
Name string `yaml:"name" json:"name"`
38+
SleepHandler *string `yaml:"sleep_handler" json:"sleep_handler"`
39+
Mandatory bool `yaml:"mandatory" json:"mandatory"`
40+
Vars []ColdStarterVars `yaml:"vars" json:"vars"`
41+
StartDelay uint `yaml:"start_delay" json:"start_delay"`
42+
FinishAfterCommand string `yaml:"finish_after_command" json:"finish_after_command"`
4243
}
4344

4445
type AugmentedPort struct {
@@ -66,10 +67,11 @@ type Scroll struct {
6667
} // @name Scroll
6768

6869
type Procedure struct {
69-
Mode string `yaml:"mode"`
70-
Id *string `yaml:"id"`
71-
Wait interface{} `yaml:"wait"`
72-
Data interface{} `yaml:"data"`
70+
Mode string `yaml:"mode"`
71+
Id *string `yaml:"id"`
72+
Wait interface{} `yaml:"wait"`
73+
Data interface{} `yaml:"data"`
74+
IgnoreFailure bool `yaml:"ignore_failure"`
7375
} // @name Procedure
7476

7577
type CommandInstructionSet struct {

internal/core/ports/services_ports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ type ColdStarterServerInterface interface {
117117
}
118118

119119
type ColdStarterInterface interface {
120-
Stop()
120+
Stop(uint)
121121
Finish(*domain.AugmentedPort)
122122
}

0 commit comments

Comments
 (0)