feat(process): auto-populate daemon registry metadata

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 01:26:42 +00:00
parent ab02432543
commit 2e5ac4208b
2 changed files with 18 additions and 2 deletions

View file

@ -39,7 +39,7 @@ type DaemonOptions struct {
Registry *Registry
// RegistryEntry provides the code and daemon name for registration.
// PID, Health, and Started are filled automatically.
// PID, Health, Project, Binary, and Started are filled automatically.
RegistryEntry DaemonEntry
}
@ -113,6 +113,16 @@ func (d *Daemon) Start() error {
if d.health != nil {
entry.Health = d.health.Addr()
}
if entry.Project == "" {
if wd, err := os.Getwd(); err == nil {
entry.Project = wd
}
}
if entry.Binary == "" {
if binary, err := os.Executable(); err == nil {
entry.Binary = binary
}
}
if err := d.opts.Registry.Register(entry); err != nil {
if d.health != nil {
_ = d.health.Stop(context.Background())

View file

@ -144,6 +144,10 @@ func TestDaemon_StopIdempotent(t *testing.T) {
func TestDaemon_AutoRegisters(t *testing.T) {
dir := t.TempDir()
reg := NewRegistry(filepath.Join(dir, "daemons"))
wd, err := os.Getwd()
require.NoError(t, err)
exe, err := os.Executable()
require.NoError(t, err)
d := NewDaemon(DaemonOptions{
HealthAddr: "127.0.0.1:0",
@ -154,7 +158,7 @@ func TestDaemon_AutoRegisters(t *testing.T) {
},
})
err := d.Start()
err = d.Start()
require.NoError(t, err)
// Should be registered
@ -162,6 +166,8 @@ func TestDaemon_AutoRegisters(t *testing.T) {
require.True(t, ok)
assert.Equal(t, os.Getpid(), entry.PID)
assert.NotEmpty(t, entry.Health)
assert.Equal(t, wd, entry.Project)
assert.Equal(t, exe, entry.Binary)
// Stop should unregister
err = d.Stop()