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`.
96 lines
2.9 KiB
Go
96 lines
2.9 KiB
Go
package listtasks
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"go.temporal.io/api/serviceerror"
|
|
"go.temporal.io/server/api/adminservice/v1"
|
|
"go.temporal.io/server/api/historyservice/v1"
|
|
"go.temporal.io/server/common"
|
|
"go.temporal.io/server/common/persistence"
|
|
"go.temporal.io/server/common/primitives/timestamp"
|
|
"go.temporal.io/server/service/history/tasks"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
func Invoke(
|
|
ctx context.Context,
|
|
taskCategoryRegistry tasks.TaskCategoryRegistry,
|
|
executionManager persistence.ExecutionManager,
|
|
request *historyservice.ListTasksRequest,
|
|
) (*historyservice.ListTasksResponse, error) {
|
|
adminRequest := request.Request
|
|
taskCategory, ok := taskCategoryRegistry.GetCategoryByID(int(adminRequest.Category))
|
|
if !ok {
|
|
return nil, &serviceerror.InvalidArgument{
|
|
Message: fmt.Sprintf("unknown task category: %v", adminRequest.Category),
|
|
}
|
|
}
|
|
|
|
taskRange := adminRequest.GetTaskRange()
|
|
var minTaskKey, maxTaskKey tasks.Key
|
|
if taskRange.InclusiveMinTaskKey != nil {
|
|
minTaskKey = tasks.NewKey(
|
|
timestamp.TimeValue(taskRange.InclusiveMinTaskKey.FireTime),
|
|
taskRange.InclusiveMinTaskKey.TaskId,
|
|
)
|
|
if err := tasks.ValidateKey(minTaskKey); err != nil {
|
|
return nil, &serviceerror.InvalidArgument{
|
|
Message: fmt.Sprintf("invalid minTaskKey: %v", err.Error()),
|
|
}
|
|
}
|
|
}
|
|
if taskRange.ExclusiveMaxTaskKey != nil {
|
|
maxTaskKey = tasks.NewKey(
|
|
timestamp.TimeValue(taskRange.ExclusiveMaxTaskKey.FireTime),
|
|
taskRange.ExclusiveMaxTaskKey.TaskId,
|
|
)
|
|
if err := tasks.ValidateKey(maxTaskKey); err != nil {
|
|
return nil, &serviceerror.InvalidArgument{
|
|
Message: fmt.Sprintf("invalid maxTaskKey: %v", err.Error()),
|
|
}
|
|
}
|
|
}
|
|
|
|
resp, err := executionManager.GetHistoryTasks(ctx, &persistence.GetHistoryTasksRequest{
|
|
ShardID: adminRequest.ShardId,
|
|
TaskCategory: taskCategory,
|
|
InclusiveMinTaskKey: minTaskKey,
|
|
ExclusiveMaxTaskKey: maxTaskKey,
|
|
BatchSize: int(adminRequest.BatchSize),
|
|
NextPageToken: adminRequest.NextPageToken,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &historyservice.ListTasksResponse{
|
|
Response: &adminservice.ListHistoryTasksResponse{
|
|
Tasks: toAdminTask(resp.Tasks),
|
|
NextPageToken: resp.NextPageToken,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func toAdminTask(historyTasks []tasks.Task) []*adminservice.Task {
|
|
var adminTasks []*adminservice.Task
|
|
for _, historyTask := range historyTasks {
|
|
historyTaskVersion := common.EmptyVersion
|
|
if taskWithVersion, ok := historyTask.(tasks.HasVersion); ok {
|
|
historyTaskVersion = taskWithVersion.GetVersion()
|
|
}
|
|
|
|
adminTasks = append(adminTasks, &adminservice.Task{
|
|
NamespaceId: historyTask.GetNamespaceID(),
|
|
WorkflowId: historyTask.GetWorkflowID(),
|
|
RunId: historyTask.GetRunID(),
|
|
TaskId: historyTask.GetTaskID(),
|
|
TaskType: historyTask.GetType(),
|
|
FireTime: timestamppb.New(historyTask.GetKey().FireTime),
|
|
Version: historyTaskVersion,
|
|
})
|
|
}
|
|
return adminTasks
|
|
}
|