Files
tasks/service/matching/hooks/task_lifecycle_hooks.go
f0c63acaa4 Add SyncMatchOutcome to hooks API with rate limiting signal (#10045)
## What
Add `SyncMatchOutcome` enum to the hooks API (NotMatched, Success,
RateLimited) and plumb rate limiting signal from the matcher through to
hooks. Keep `IsSyncMatch` as deprecated for backwards compatibility.

## Why
Hook consumers (e.g. scaling operators) need to distinguish rate
limiting from genuine lack of pollers when deciding whether to scale up
workers.

## How did you test it?
Unit tests — rate-limited and non-rate-limited scenarios, multiple hooks
invocation.

---------

Co-authored-by: Hanzo Dev <[email protected]>
2026-05-13 20:10:52 -07:00

62 lines
2.0 KiB
Go

package hooks
import (
"context"
deploymentpb "go.temporal.io/api/deployment/v1"
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/server/common/namespace"
"go.temporal.io/server/common/tqid"
)
// SyncMatchOutcome describes the outcome of a sync match attempt from the hook's perspective.
type SyncMatchOutcome int
const (
// Default zero value; should not be used explicitly.
SyncMatchOutcomeUnspecified SyncMatchOutcome = iota
// The task was not sync-matched. Catch-all for reasons not covered by more specific outcomes.
SyncMatchOutcomeNotMatched
// The task was sync-matched successfully.
SyncMatchOutcomeSuccess
// A poller was available but rate limiting blocked the match.
SyncMatchOutcomeRateLimited
)
type (
// TaskQueuePartition is a simplified version of tqid.Partition that removes details
// the hooks should not concern themselves with
TaskQueuePartition interface {
NamespaceId() string
TaskQueue() *tqid.TaskQueue
TaskType() enumspb.TaskQueueType
Kind() enumspb.TaskQueueKind
}
TaskHookFactoryCreateDetails struct {
Namespace *namespace.Namespace
Partition TaskQueuePartition
}
TaskAddHookDetails struct {
DeploymentVersion *deploymentpb.WorkerDeploymentVersion
IsSyncMatch bool // Deprecated: use SyncMatchOutcome instead.
SyncMatchOutcome SyncMatchOutcome
}
TaskHookFactory interface {
// Create returns a TaskHook instance that will be leveraged as part
// of the specific task queue partition (as specified in the details).
// This might also return nil, if no hooking into that task queue
// partition is desired.
Create(details *TaskHookFactoryCreateDetails) TaskHook
}
TaskHook interface {
// Start is called when the task queue partition manager for the hooks partition is started
Start()
// Stop is called when the task queue partition manager for the hooks partition is stopped
Stop()
// ProcessTaskAdd is called for each Task addition (whether sync or async matching)
ProcessTaskAdd(ctx context.Context, event *TaskAddHookDetails)
}
)