mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
Every go.temporal.io/sdk/{client,worker,workflow,activity,temporal}
import swapped to github.com/hanzoai/tasks/pkg/sdk/<same>. The three
protobuf-accessor sites in durable.go rewrote to the native flat
shape: DescribeWorkflow returns *WorkflowExecutionInfo directly;
ListWorkflows takes (query, pageSize, nextPageToken). No shim
package, no compatibility layer.
go.mod: replace directive -> ../tasks pending v1.36.0 tag (removed
in the follow-up cleanup commit in hanzoai/tasks PR-F).
Import-purity: grep go.temporal.io/ plugins/tasks/ -> 0 hits.
go test ./plugins/tasks/... -> green.
40 lines
994 B
Go
40 lines
994 B
Go
package tasks
|
|
|
|
import (
|
|
"github.com/hanzoai/tasks/pkg/sdk/client"
|
|
sdkworker "github.com/hanzoai/tasks/pkg/sdk/worker"
|
|
)
|
|
|
|
// Worker runs an embedded Temporal worker that polls a task queue
|
|
// and executes workflows and activities in-process.
|
|
type Worker struct {
|
|
worker sdkworker.Worker
|
|
queue string
|
|
}
|
|
|
|
// NewWorker creates a worker for a specific task queue.
|
|
// For multi-tenant deployments, each org/space can have its own queue.
|
|
func NewWorker(c client.Client, queue string) *Worker {
|
|
w := sdkworker.New(c, queue, sdkworker.Options{})
|
|
|
|
// Register all workflow types.
|
|
w.RegisterWorkflow(AgentTaskWorkflow)
|
|
w.RegisterWorkflow(PipelineWorkflow)
|
|
w.RegisterWorkflow(FanOutWorkflow)
|
|
|
|
// Register activities.
|
|
w.RegisterActivity(ExecuteTaskActivity)
|
|
|
|
return &Worker{worker: w, queue: queue}
|
|
}
|
|
|
|
// Start begins polling the task queue.
|
|
func (tw *Worker) Start() error {
|
|
return tw.worker.Start()
|
|
}
|
|
|
|
// Stop gracefully shuts down the worker.
|
|
func (tw *Worker) Stop() {
|
|
tw.worker.Stop()
|
|
}
|