Skip to content

Commit 71cb7ef

Browse files
authored
fix: run hydrated queue after daemon restart (#82)
1 parent 1113d87 commit 71cb7ef

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

apps/druid/core/services/runtime_session_commands.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ func (s *RuntimeSession) Hydrate() error {
8484
s.runtimeScroll.Status = deriveRuntimeScrollStatus(s.runtimeScroll.Procedures, s.scrollService.GetFile().Commands)
8585
err := s.store.UpdateScroll(s.runtimeScroll)
8686
s.mu.Unlock()
87-
return err
87+
if err != nil {
88+
return err
89+
}
90+
s.triggerRunQueue()
91+
return nil
8892
}
8993

9094
func (s *RuntimeSession) AutoStartServe() error {

apps/druid/core/services/runtime_supervisor_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,56 @@ func TestRuntimeSupervisorStartHydratesRunningScroll(t *testing.T) {
402402
}
403403
}
404404

405+
func TestRuntimeSupervisorStartRunsHydratedRestartCommand(t *testing.T) {
406+
store := newTestStateStore(t)
407+
scrollYAML := multiProcedureScrollYAML()
408+
runtimeScroll := &domain.RuntimeScroll{
409+
ID: "running-restart-scroll",
410+
Artifact: "local",
411+
Root: "runtime://running-restart-scroll",
412+
ScrollName: "cached",
413+
ScrollYAML: scrollYAML,
414+
Status: domain.RuntimeScrollStatusRunning,
415+
Procedures: domain.ProcedureStatusMap{
416+
"start": {
417+
"coldstart": {Status: domain.ScrollLockStatusRunning},
418+
"start": {Status: domain.ScrollLockStatusWaiting},
419+
},
420+
},
421+
}
422+
if err := store.CreateScroll(runtimeScroll); err != nil {
423+
t.Fatal(err)
424+
}
425+
called := make(chan ports.RuntimeCommand, 1)
426+
release := make(chan struct{})
427+
supervisor := NewRuntimeSupervisor(store, coreservices.NewRuntimeScrollManager(store), &fakeWorkerBackend{
428+
runCommand: func(command ports.RuntimeCommand) (*int, error) {
429+
called <- command
430+
<-release
431+
return nil, nil
432+
},
433+
})
434+
435+
if err := supervisor.Start(); err != nil {
436+
t.Fatal(err)
437+
}
438+
defer func() {
439+
close(release)
440+
if session := supervisor.sessions["running-restart-scroll"]; session != nil {
441+
session.stopDeploymentQueue()
442+
}
443+
}()
444+
445+
select {
446+
case command := <-called:
447+
if command.Name != "start" {
448+
t.Fatalf("hydrated command = %s, want start", command.Name)
449+
}
450+
case <-time.After(2 * time.Second):
451+
t.Fatal("timed out waiting for hydrated restart command to run")
452+
}
453+
}
454+
405455
func TestRuntimeSupervisorEnsureCanCreate(t *testing.T) {
406456
artifact := t.TempDir()
407457
if err := os.WriteFile(filepath.Join(artifact, "scroll.yaml"), []byte(cachedScrollYAML("start")), 0644); err != nil {

0 commit comments

Comments
 (0)