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.
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package tasks
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/tasks/pkg/sdk/activity"
|
|
)
|
|
|
|
// ExecuteTaskActivity is the Temporal activity that executes a task.
|
|
// Delegates to the Config.OnExecute callback registered during plugin setup.
|
|
//
|
|
// If no executor is configured, the task completes with an acknowledgment message.
|
|
var taskExecutor func(ctx context.Context, task *Task) (*Task, error)
|
|
|
|
// SetTaskExecutor registers the function called by Temporal activities.
|
|
// This is typically set during plugin registration via Config.OnDurableExecute.
|
|
func SetTaskExecutor(fn func(ctx context.Context, task *Task) (*Task, error)) {
|
|
taskExecutor = fn
|
|
}
|
|
|
|
// ExecuteTaskActivity is the activity implementation called by Temporal workflows.
|
|
func ExecuteTaskActivity(ctx context.Context, task *Task) (*Task, error) {
|
|
logger := activity.GetLogger(ctx)
|
|
logger.Info("Executing task",
|
|
"task_id", task.ID,
|
|
"space_id", task.SpaceID,
|
|
"title", task.Title,
|
|
"assigned_to", task.AssignedTo,
|
|
)
|
|
|
|
if taskExecutor == nil {
|
|
task.State = TaskCompleted
|
|
task.Output = map[string]any{"message": "No executor registered. Task acknowledged."}
|
|
return task, nil
|
|
}
|
|
|
|
// Heartbeat so Temporal knows we're alive.
|
|
activity.RecordHeartbeat(ctx, "executing")
|
|
|
|
result, err := taskExecutor(ctx, task)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("task execution failed: %w", err)
|
|
}
|
|
|
|
return result, nil
|
|
}
|