From 98fe626d8e2cb83858c76a2fa8f68936c7bdf1b5 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 02:21:01 +0000 Subject: [PATCH] feat(process): add process get core task --- actions.go | 10 ++++++++++ service.go | 11 +++++++++++ service_test.go | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/actions.go b/actions.go index f4ab6d1..f6b43f1 100644 --- a/actions.go +++ b/actions.go @@ -39,6 +39,16 @@ type TaskProcessKill struct { PID int } +// TaskProcessGet requests a snapshot of a managed process through Core.PERFORM. +// +// Example: +// +// c.PERFORM(process.TaskProcessGet{ID: "proc-1"}) +type TaskProcessGet struct { + // ID identifies a managed process started by this service. + ID string +} + // TaskProcessList requests a snapshot of managed processes through Core.PERFORM. // If RunningOnly is true, only active processes are returned. // diff --git a/service.go b/service.go index 5458d1c..6602f3e 100644 --- a/service.go +++ b/service.go @@ -586,6 +586,17 @@ func (s *Service) handleTask(c *core.Core, task core.Task) core.Result { default: return core.Result{Value: coreerr.E("Service.handleTask", "task process kill requires an id or pid", nil), OK: false} } + case TaskProcessGet: + if m.ID == "" { + return core.Result{Value: coreerr.E("Service.handleTask", "task process get requires an id", nil), OK: false} + } + + proc, err := s.Get(m.ID) + if err != nil { + return core.Result{Value: err, OK: false} + } + + return core.Result{Value: proc.Info(), OK: true} case TaskProcessList: procs := s.List() if m.RunningOnly { diff --git a/service_test.go b/service_test.go index 518106b..08c7332 100644 --- a/service_test.go +++ b/service_test.go @@ -685,6 +685,29 @@ func TestService_OnStartup(t *testing.T) { cancel() <-proc.Done() }) + + t.Run("registers process.get task", func(t *testing.T) { + svc, c := newTestService(t) + + err := svc.OnStartup(context.Background()) + require.NoError(t, err) + + proc, err := svc.Start(context.Background(), "echo", "snapshot") + require.NoError(t, err) + <-proc.Done() + + result := c.PERFORM(TaskProcessGet{ID: proc.ID}) + require.True(t, result.OK) + + info, ok := result.Value.(Info) + require.True(t, ok) + assert.Equal(t, proc.ID, info.ID) + assert.Equal(t, proc.Command, info.Command) + assert.Equal(t, proc.Args, info.Args) + assert.Equal(t, proc.Status, info.Status) + assert.Equal(t, proc.ExitCode, info.ExitCode) + assert.Equal(t, proc.Info().PID, info.PID) + }) } func TestService_RunWithOptions(t *testing.T) {