mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
124 lines
3.2 KiB
Go
124 lines
3.2 KiB
Go
package workflow
|
|
|
|
import (
|
|
"sync/atomic"
|
|
|
|
"github.com/pborman/uuid"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
querypb "go.temporal.io/api/query/v1"
|
|
"go.temporal.io/api/serviceerror"
|
|
historyi "go.temporal.io/server/service/history/interfaces"
|
|
)
|
|
|
|
const (
|
|
QueryCompletionTypeSucceeded historyi.QueryCompletionType = iota
|
|
QueryCompletionTypeUnblocked
|
|
QueryCompletionTypeFailed
|
|
)
|
|
|
|
var (
|
|
errCompletionStateInvalid = serviceerror.NewInternal("query completion state invalid")
|
|
errAlreadyInCompletionState = serviceerror.NewInternal("query is already in completion state")
|
|
errQueryNotInCompletionState = serviceerror.NewInternal("query is not in completion state")
|
|
)
|
|
|
|
type (
|
|
query interface {
|
|
getID() string
|
|
getCompletionCh() <-chan struct{}
|
|
getQueryInput() *querypb.WorkflowQuery
|
|
GetCompletionState() (*historyi.QueryCompletionState, error)
|
|
setCompletionState(*historyi.QueryCompletionState) error
|
|
}
|
|
|
|
queryImpl struct {
|
|
id string
|
|
queryInput *querypb.WorkflowQuery
|
|
completionCh chan struct{}
|
|
|
|
completionState atomic.Value
|
|
}
|
|
)
|
|
|
|
func newQuery(queryInput *querypb.WorkflowQuery) query {
|
|
return &queryImpl{
|
|
id: uuid.New(),
|
|
queryInput: queryInput,
|
|
completionCh: make(chan struct{}),
|
|
}
|
|
}
|
|
|
|
func (q *queryImpl) getID() string {
|
|
return q.id
|
|
}
|
|
|
|
func (q *queryImpl) getCompletionCh() <-chan struct{} {
|
|
return q.completionCh
|
|
}
|
|
|
|
func (q *queryImpl) getQueryInput() *querypb.WorkflowQuery {
|
|
return q.queryInput
|
|
}
|
|
|
|
func (q *queryImpl) GetCompletionState() (*historyi.QueryCompletionState, error) {
|
|
ts := q.completionState.Load()
|
|
if ts == nil {
|
|
return nil, errQueryNotInCompletionState
|
|
}
|
|
queryState, ok := ts.(*historyi.QueryCompletionState)
|
|
if !ok {
|
|
return nil, errCompletionStateInvalid
|
|
}
|
|
return queryState, nil
|
|
}
|
|
|
|
func (q *queryImpl) setCompletionState(completionState *historyi.QueryCompletionState) error {
|
|
if err := q.validateCompletionState(completionState); err != nil {
|
|
return err
|
|
}
|
|
currCompletionState, _ := q.GetCompletionState()
|
|
if currCompletionState != nil {
|
|
return errAlreadyInCompletionState
|
|
}
|
|
q.completionState.Store(completionState)
|
|
close(q.completionCh)
|
|
return nil
|
|
}
|
|
|
|
func (q *queryImpl) validateCompletionState(
|
|
completionState *historyi.QueryCompletionState,
|
|
) error {
|
|
if completionState == nil {
|
|
return errCompletionStateInvalid
|
|
}
|
|
switch completionState.Type {
|
|
case QueryCompletionTypeSucceeded:
|
|
if completionState.Result == nil || completionState.Err != nil {
|
|
return errCompletionStateInvalid
|
|
}
|
|
queryResult := completionState.Result
|
|
validAnswered := queryResult.GetResultType() == enumspb.QUERY_RESULT_TYPE_ANSWERED &&
|
|
queryResult.Answer != nil &&
|
|
queryResult.GetErrorMessage() == ""
|
|
validFailed := queryResult.GetResultType() == enumspb.QUERY_RESULT_TYPE_FAILED &&
|
|
queryResult.Answer == nil &&
|
|
queryResult.GetErrorMessage() != ""
|
|
if !validAnswered && !validFailed {
|
|
return errCompletionStateInvalid
|
|
}
|
|
return nil
|
|
case QueryCompletionTypeUnblocked:
|
|
if completionState.Result != nil || completionState.Err != nil {
|
|
return errCompletionStateInvalid
|
|
}
|
|
return nil
|
|
case QueryCompletionTypeFailed:
|
|
if completionState.Result != nil || completionState.Err == nil {
|
|
return errCompletionStateInvalid
|
|
}
|
|
return nil
|
|
default:
|
|
return errCompletionStateInvalid
|
|
}
|
|
}
|