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).
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination client_mock.go
|
|
|
|
package parentclosepolicy
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"math/rand"
|
|
"time"
|
|
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
sdkclient "go.temporal.io/sdk/client"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/metrics"
|
|
"github.com/hanzoai/tasks/common/sdk"
|
|
)
|
|
|
|
type (
|
|
|
|
// Client is used to send request to processor workflow
|
|
Client interface {
|
|
SendParentClosePolicyRequest(context.Context, Request) error
|
|
}
|
|
|
|
clientImpl struct {
|
|
metricsHandler metrics.Handler
|
|
logger log.Logger
|
|
sdkClientFactory sdk.ClientFactory
|
|
numWorkflows int
|
|
}
|
|
)
|
|
|
|
var _ Client = (*clientImpl)(nil)
|
|
|
|
const (
|
|
signalTimeout = 400 * time.Millisecond
|
|
workflowIDPrefix = "parent-close-policy-workflow"
|
|
workflowTaskTimeout = time.Minute
|
|
workflowIDReusePolicy = enumspb.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
|
|
)
|
|
|
|
// NewClient creates a new Client
|
|
func NewClient(
|
|
metricsHandler metrics.Handler,
|
|
logger log.Logger,
|
|
sdkClientFactory sdk.ClientFactory,
|
|
numWorkflows int,
|
|
) Client {
|
|
return &clientImpl{
|
|
metricsHandler: metricsHandler,
|
|
logger: logger,
|
|
sdkClientFactory: sdkClientFactory,
|
|
numWorkflows: numWorkflows,
|
|
}
|
|
}
|
|
|
|
func (c *clientImpl) SendParentClosePolicyRequest(ctx context.Context, request Request) error {
|
|
workflowID := getWorkflowID(c.numWorkflows)
|
|
workflowOptions := sdkclient.StartWorkflowOptions{
|
|
ID: workflowID,
|
|
TaskQueue: processorTaskQueueName,
|
|
WorkflowTaskTimeout: workflowTaskTimeout,
|
|
WorkflowIDReusePolicy: workflowIDReusePolicy,
|
|
}
|
|
signalCtx, cancel := context.WithTimeout(ctx, signalTimeout)
|
|
defer cancel()
|
|
|
|
sdkClient := c.sdkClientFactory.GetSystemClient()
|
|
_, err := sdkClient.SignalWithStartWorkflow(signalCtx, workflowID, processorChannelName, request, workflowOptions, processorWFTypeName, nil)
|
|
return err
|
|
}
|
|
|
|
func getWorkflowID(numWorkflows int) string {
|
|
return fmt.Sprintf("%v-%v", workflowIDPrefix, rand.Intn(numWorkflows))
|
|
}
|