mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package nexustest
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nexus-rpc/sdk-go/nexus"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/hanzoai/tasks/common/nexus/nexusrpc"
|
|
"github.com/hanzoai/tasks/common/testing/freeport"
|
|
)
|
|
|
|
func AllocListenAddress() string {
|
|
return fmt.Sprintf("localhost:%d", freeport.MustGetFreePort())
|
|
}
|
|
|
|
func NewNexusServer(t *testing.T, listenAddr string, handler nexus.Handler) {
|
|
hh := nexusrpc.NewHTTPHandler(nexusrpc.HandlerOptions{
|
|
Handler: handler,
|
|
})
|
|
srv := &http.Server{Addr: listenAddr, Handler: hh}
|
|
listener, err := net.Listen("tcp", listenAddr)
|
|
require.NoError(t, err)
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
errCh <- srv.Serve(listener)
|
|
}()
|
|
|
|
t.Cleanup(func() {
|
|
// Graceful shutdown
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
err = srv.Shutdown(ctx)
|
|
if ctx.Err() != nil {
|
|
require.NoError(t, err)
|
|
require.ErrorIs(t, <-errCh, http.ErrServerClosed)
|
|
}
|
|
})
|
|
}
|
|
|
|
type Handler struct {
|
|
nexus.UnimplementedHandler
|
|
OnStartOperation func(ctx context.Context, service, operation string, input *nexus.LazyValue, options nexus.StartOperationOptions) (nexus.HandlerStartOperationResult[any], error)
|
|
OnCancelOperation func(ctx context.Context, service, operation, token string, options nexus.CancelOperationOptions) error
|
|
}
|
|
|
|
func (h Handler) StartOperation(ctx context.Context, service, operation string, input *nexus.LazyValue, options nexus.StartOperationOptions) (nexus.HandlerStartOperationResult[any], error) {
|
|
return h.OnStartOperation(ctx, service, operation, input, options)
|
|
}
|
|
|
|
func (h Handler) CancelOperation(ctx context.Context, service, operation, token string, options nexus.CancelOperationOptions) error {
|
|
return h.OnCancelOperation(ctx, service, operation, token, options)
|
|
}
|