refactor: swap pkg/framework imports to pkg/core
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
8095807ad6
commit
85b0e002d6
5 changed files with 37 additions and 37 deletions
|
|
@ -5,7 +5,7 @@ import (
|
|||
"sync"
|
||||
"testing"
|
||||
|
||||
"forge.lthn.ai/core/go/pkg/framework"
|
||||
"forge.lthn.ai/core/go/pkg/core"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -53,12 +53,12 @@ func TestGlobal_SetDefault(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
core, err := framework.New(
|
||||
framework.WithName("process", NewService(Options{})),
|
||||
core, err := core.New(
|
||||
core.WithName("process", NewService(Options{})),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
svc, err := framework.ServiceFor[*Service](core, "process")
|
||||
svc, err := core.ServiceFor[*Service](core, "process")
|
||||
require.NoError(t, err)
|
||||
|
||||
SetDefault(svc)
|
||||
|
|
@ -81,12 +81,12 @@ func TestGlobal_ConcurrentDefault(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
core, err := framework.New(
|
||||
framework.WithName("process", NewService(Options{})),
|
||||
core, err := core.New(
|
||||
core.WithName("process", NewService(Options{})),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
svc, err := framework.ServiceFor[*Service](core, "process")
|
||||
svc, err := core.ServiceFor[*Service](core, "process")
|
||||
require.NoError(t, err)
|
||||
|
||||
SetDefault(svc)
|
||||
|
|
@ -117,12 +117,12 @@ func TestGlobal_ConcurrentSetDefault(t *testing.T) {
|
|||
// Create multiple services
|
||||
var services []*Service
|
||||
for i := 0; i < 10; i++ {
|
||||
core, err := framework.New(
|
||||
framework.WithName("process", NewService(Options{})),
|
||||
core, err := core.New(
|
||||
core.WithName("process", NewService(Options{})),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
svc, err := framework.ServiceFor[*Service](core, "process")
|
||||
svc, err := core.ServiceFor[*Service](core, "process")
|
||||
require.NoError(t, err)
|
||||
services = append(services, svc)
|
||||
}
|
||||
|
|
@ -161,12 +161,12 @@ func TestGlobal_ConcurrentOperations(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
core, err := framework.New(
|
||||
framework.WithName("process", NewService(Options{})),
|
||||
core, err := core.New(
|
||||
core.WithName("process", NewService(Options{})),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
svc, err := framework.ServiceFor[*Service](core, "process")
|
||||
svc, err := core.ServiceFor[*Service](core, "process")
|
||||
require.NoError(t, err)
|
||||
|
||||
SetDefault(svc)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"forge.lthn.ai/core/go/pkg/framework"
|
||||
"forge.lthn.ai/core/go/pkg/core"
|
||||
)
|
||||
|
||||
// Global default service (follows i18n pattern).
|
||||
|
|
@ -32,7 +32,7 @@ func SetDefault(s *Service) {
|
|||
|
||||
// Init initializes the default global service with a Core instance.
|
||||
// This is typically called during application startup.
|
||||
func Init(c *framework.Core) error {
|
||||
func Init(c *core.Core) error {
|
||||
defaultOnce.Do(func() {
|
||||
factory := NewService(Options{})
|
||||
svc, err := factory(c)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"forge.lthn.ai/core/go/pkg/framework"
|
||||
"forge.lthn.ai/core/go/pkg/core"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -12,12 +12,12 @@ import (
|
|||
func newTestRunner(t *testing.T) *Runner {
|
||||
t.Helper()
|
||||
|
||||
core, err := framework.New(
|
||||
framework.WithName("process", NewService(Options{})),
|
||||
core, err := core.New(
|
||||
core.WithName("process", NewService(Options{})),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
svc, err := framework.ServiceFor[*Service](core, "process")
|
||||
svc, err := core.ServiceFor[*Service](core, "process")
|
||||
require.NoError(t, err)
|
||||
|
||||
return NewRunner(svc)
|
||||
|
|
|
|||
18
service.go
18
service.go
|
|
@ -11,7 +11,7 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"forge.lthn.ai/core/go/pkg/framework"
|
||||
"forge.lthn.ai/core/go/pkg/core"
|
||||
)
|
||||
|
||||
// Default buffer size for process output (1MB).
|
||||
|
|
@ -26,7 +26,7 @@ var (
|
|||
|
||||
// Service manages process execution with Core IPC integration.
|
||||
type Service struct {
|
||||
*framework.ServiceRuntime[Options]
|
||||
*core.ServiceRuntime[Options]
|
||||
|
||||
processes map[string]*Process
|
||||
mu sync.RWMutex
|
||||
|
|
@ -43,16 +43,16 @@ type Options struct {
|
|||
|
||||
// NewService creates a process service factory for Core registration.
|
||||
//
|
||||
// core, _ := framework.New(
|
||||
// framework.WithName("process", process.NewService(process.Options{})),
|
||||
// core, _ := core.New(
|
||||
// core.WithName("process", process.NewService(process.Options{})),
|
||||
// )
|
||||
func NewService(opts Options) func(*framework.Core) (any, error) {
|
||||
return func(c *framework.Core) (any, error) {
|
||||
func NewService(opts Options) func(*core.Core) (any, error) {
|
||||
return func(c *core.Core) (any, error) {
|
||||
if opts.BufferSize == 0 {
|
||||
opts.BufferSize = DefaultBufferSize
|
||||
}
|
||||
svc := &Service{
|
||||
ServiceRuntime: framework.NewServiceRuntime(c, opts),
|
||||
ServiceRuntime: core.NewServiceRuntime(c, opts),
|
||||
processes: make(map[string]*Process),
|
||||
bufSize: opts.BufferSize,
|
||||
}
|
||||
|
|
@ -60,12 +60,12 @@ func NewService(opts Options) func(*framework.Core) (any, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// OnStartup implements framework.Startable.
|
||||
// OnStartup implements core.Startable.
|
||||
func (s *Service) OnStartup(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// OnShutdown implements framework.Stoppable.
|
||||
// OnShutdown implements core.Stoppable.
|
||||
// Kills all running processes on shutdown.
|
||||
func (s *Service) OnShutdown(ctx context.Context) error {
|
||||
s.mu.RLock()
|
||||
|
|
|
|||
|
|
@ -7,20 +7,20 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.lthn.ai/core/go/pkg/framework"
|
||||
"forge.lthn.ai/core/go/pkg/core"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newTestService(t *testing.T) (*Service, *framework.Core) {
|
||||
func newTestService(t *testing.T) (*Service, *core.Core) {
|
||||
t.Helper()
|
||||
|
||||
core, err := framework.New(
|
||||
framework.WithName("process", NewService(Options{BufferSize: 1024})),
|
||||
core, err := core.New(
|
||||
core.WithName("process", NewService(Options{BufferSize: 1024})),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
svc, err := framework.ServiceFor[*Service](core, "process")
|
||||
svc, err := core.ServiceFor[*Service](core, "process")
|
||||
require.NoError(t, err)
|
||||
|
||||
return svc, core
|
||||
|
|
@ -120,8 +120,8 @@ func TestService_Run(t *testing.T) {
|
|||
|
||||
func TestService_Actions(t *testing.T) {
|
||||
t.Run("broadcasts events", func(t *testing.T) {
|
||||
core, err := framework.New(
|
||||
framework.WithName("process", NewService(Options{})),
|
||||
core, err := core.New(
|
||||
core.WithName("process", NewService(Options{})),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ func TestService_Actions(t *testing.T) {
|
|||
var exited []ActionProcessExited
|
||||
var mu sync.Mutex
|
||||
|
||||
core.RegisterAction(func(c *framework.Core, msg framework.Message) error {
|
||||
core.RegisterAction(func(c *core.Core, msg core.Message) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
switch m := msg.(type) {
|
||||
|
|
@ -144,7 +144,7 @@ func TestService_Actions(t *testing.T) {
|
|||
return nil
|
||||
})
|
||||
|
||||
svc, _ := framework.ServiceFor[*Service](core, "process")
|
||||
svc, _ := core.ServiceFor[*Service](core, "process")
|
||||
proc, err := svc.Start(context.Background(), "echo", "test")
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue