mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
Adds native Temporal SDK integration to the tasks plugin: - durable.go: DurableStore client (submit/cancel/signal/status workflows) - workflows.go: AgentTaskWorkflow, PipelineWorkflow, FanOutWorkflow - activities.go: ExecuteTaskActivity with heartbeat + pluggable executor - worker.go: Embedded Temporal worker (polls task queue in-process) SQLite remains authoritative state. Temporal provides crash-safe execution that survives restarts. When durable is enabled: - Task create → SQLite + Temporal workflow submission - Task cancel → SQLite + Temporal workflow cancellation - Task signal → forwarded to Temporal workflow Multi-tenant via namespace-per-org (TASKS_NAMESPACE=org-acme). Env config: TASKS_ENABLED, TASKS_ADDRESS, TASKS_NAMESPACE, TASKS_QUEUE. Default cloud: tasks.hanzo.ai:7233. Falls back to SQLite-only if unreachable.
40 lines
966 B
Go
40 lines
966 B
Go
package tasks
|
|
|
|
import (
|
|
"go.temporal.io/sdk/client"
|
|
sdkworker "go.temporal.io/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()
|
|
}
|