Files
tasks/service/history/api/token.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

119 lines
4.0 KiB
Go

package api
import (
historyspb "github.com/hanzoai/tasks/api/history/v1"
"github.com/hanzoai/tasks/api/historyservice/v1"
tokenspb "github.com/hanzoai/tasks/api/token/v1"
"github.com/hanzoai/tasks/service/history/consts"
)
// NOTE: DO NOT MODIFY UNLESS ALSO APPLIED TO ./service/frontend/token_deprecated.go
func GeneratePaginationTokenV2Request(
request *historyservice.GetWorkflowExecutionRawHistoryV2Request,
versionHistories *historyspb.VersionHistories,
) *tokenspb.RawHistoryContinuation {
req := request.Request
execution := req.Execution
return &tokenspb.RawHistoryContinuation{
NamespaceId: req.GetNamespaceId(),
WorkflowId: execution.GetWorkflowId(),
RunId: execution.GetRunId(),
StartEventId: req.GetStartEventId(),
StartEventVersion: req.GetStartEventVersion(),
EndEventId: req.GetEndEventId(),
EndEventVersion: req.GetEndEventVersion(),
VersionHistories: versionHistories,
PersistenceToken: nil, // this is the initialized value
}
}
// NOTE: DO NOT MODIFY UNLESS ALSO APPLIED TO ./service/frontend/token_deprecated.go
func ValidatePaginationTokenV2Request(
request *historyservice.GetWorkflowExecutionRawHistoryV2Request,
token *tokenspb.RawHistoryContinuation,
) error {
req := request.Request
execution := req.Execution
if req.GetNamespaceId() != token.GetNamespaceId() ||
execution.GetWorkflowId() != token.GetWorkflowId() ||
execution.GetRunId() != token.GetRunId() ||
req.GetStartEventId() != token.GetStartEventId() ||
req.GetStartEventVersion() != token.GetStartEventVersion() ||
req.GetEndEventId() != token.GetEndEventId() ||
req.GetEndEventVersion() != token.GetEndEventVersion() {
return consts.ErrInvalidPaginationToken
}
return nil
}
// NOTE: DO NOT MODIFY UNLESS ALSO APPLIED TO ./service/frontend/token_deprecated.go
func SerializeRawHistoryToken(token *tokenspb.RawHistoryContinuation) ([]byte, error) {
if token == nil {
return nil, nil
}
return token.Marshal()
}
// NOTE: DO NOT MODIFY UNLESS ALSO APPLIED TO ./service/frontend/token_deprecated.go
func DeserializeRawHistoryToken(bytes []byte) (*tokenspb.RawHistoryContinuation, error) {
token := &tokenspb.RawHistoryContinuation{}
err := token.Unmarshal(bytes)
return token, err
}
// NOTE: DO NOT MODIFY UNLESS ALSO APPLIED TO ./service/frontend/token_deprecated.go
func SerializeHistoryToken(token *tokenspb.HistoryContinuation) ([]byte, error) {
if token == nil {
return nil, nil
}
return token.Marshal()
}
// NOTE: DO NOT MODIFY UNLESS ALSO APPLIED TO ./service/frontend/token_deprecated.go
func DeserializeHistoryToken(bytes []byte) (*tokenspb.HistoryContinuation, error) {
token := &tokenspb.HistoryContinuation{}
err := token.Unmarshal(bytes)
return token, err
}
func GeneratePaginationToken(
request *historyservice.GetWorkflowExecutionRawHistoryRequest,
versionHistories *historyspb.VersionHistories,
) *tokenspb.RawHistoryContinuation {
req := request.Request
execution := req.Execution
return &tokenspb.RawHistoryContinuation{
NamespaceId: req.GetNamespaceId(),
WorkflowId: execution.GetWorkflowId(),
RunId: execution.GetRunId(),
StartEventId: req.GetStartEventId(),
StartEventVersion: req.GetStartEventVersion(),
EndEventId: req.GetEndEventId(),
EndEventVersion: req.GetEndEventVersion(),
VersionHistories: versionHistories,
PersistenceToken: nil, // this is the initialized value
}
}
func ValidatePaginationToken(
request *historyservice.GetWorkflowExecutionRawHistoryRequest,
token *tokenspb.RawHistoryContinuation,
) error {
req := request.Request
execution := req.Execution
if req.GetNamespaceId() != token.GetNamespaceId() ||
execution.GetWorkflowId() != token.GetWorkflowId() ||
execution.GetRunId() != token.GetRunId() ||
req.GetStartEventId() != token.GetStartEventId() ||
req.GetStartEventVersion() != token.GetStartEventVersion() ||
req.GetEndEventId() != token.GetEndEventId() ||
req.GetEndEventVersion() != token.GetEndEventVersion() {
return consts.ErrInvalidPaginationToken
}
return nil
}