mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +00:00
<!-- Describe what has changed in this PR -->
**What changed?**
I added pluggable logic to decode DLQ tasks in tdbg. The default
behavior uses the predefined set of categories in the server,
deserializes them into protos, and then uses jsonpb to marshal them.
However, for deployments with custom task categories, there is an option
of extending this behavior.
Registering a custom task category will look something like this:
```go
package main
import (
"os"
"github.com/gogo/protobuf/proto"
commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/server/service/history/tasks"
"go.temporal.io/server/tools/tdbg"
)
type (
myTaskDeserializer struct {
baseDeserializer tdbg.PredefinedTaskBlobDeserializer // the zero value is valid
}
myTaskCategoryRegistry struct {
baseRegistry tasks.TaskCategoryRegistry
}
)
var (
myTaskCategory = tasks.Category{
// ...
}
)
func (m myTaskDeserializer) Deserialize(taskCategoryID int, blob commonpb.DataBlob) (proto.Message, error) {
if taskCategoryID == myTaskCategory.ID() {
panic("TODO")
}
return m.baseDeserializer.Deserialize(taskCategoryID, blob)
}
func (m myTaskCategoryRegistry) GetCategoryByID(id int) (tasks.Category, bool) {
if id == myTaskCategory.ID() {
return myTaskCategory, true
}
return m.baseRegistry.GetCategoryByID(id)
}
func (m myTaskCategoryRegistry) GetCategories() map[int]tasks.Category {
categories := m.baseRegistry.GetCategories()
categories[myTaskCategory.ID()] = myTaskCategory
return categories
}
func main() {
_ = tdbg.NewCliApp(func(params *tdbg.Params) {
params.TaskBlobEncoder = tdbg.NewProtoTaskBlobEncoder(myTaskDeserializer{})
params.TaskCategoryRegistry = myTaskCategoryRegistry{
baseRegistry: tasks.NewDefaultTaskCategoryRegistry(),
}
}).Run(os.Args)
}
```
<!-- Tell your future self why have you made these changes -->
**Why?**
Before this change, tasks looked like this:
```json
{
"metadata": {
"messageId": "0"
},
"payload": {
"shardId": 1,
"blob": {
"encodingType": "Proto3",
"data": "CiRhZjllOTY4Ni0yNThiLTRiOGYtYWU2ZC0xMWNhMjIzZWQ1ZGYSO2RscS10ZXN0LXRlcm1pbmFsLXdmdHMtNGJlN2RlMTctZWQ4Yy00NjliLWExOGMtYmExMjJmZmI5YzE2GiQ0YTI4YzA1ZC1kZGIyLTQxYzYtOWQ0Ni0xYjhkYTU2OWFlNTQgAyokYWY5ZTk2ODYtMjU4Yi00YjhmLWFlNmQtMTFjYTIyM2VkNWRmQhNkbHEtdGVzdC10YXNrLXF1ZXVlUAJghIBAagwIm6ftqQYQkLiC4AE="
}
}
}
```
Now they're much more informative:
```json
{
"message_id": 0,
"shard_id": 3,
"payload": {
"namespace_id": "0d911dda-4c83-4890-9a00-aa4b709bfea6",
"workflow_id": "dlq-test-terminal-wfts-b6871484-2840-40b4-9460-c8289ee8e178",
"run_id": "1d8dfa7c-09e5-4845-a16f-69eed57fec9d",
"task_type": "TransferWorkflowTask",
"target_namespace_id": "0d911dda-4c83-4890-9a00-aa4b709bfea6",
"target_workflow_id": "",
"target_run_id": "",
"task_queue": "dlq-test-task-queue",
"target_child_workflow_only": false,
"scheduled_event_id": "2",
"version": "0",
"task_id": "1048580",
"visibility_time": "2023-10-27T06:08:08.993945Z",
"delete_after_close": false
}
}
```
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
There's quite a few tests which verify that the output contains task
details now without further parsing of any "data" field. In addition, I
did some manual testing to inspect the output.
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**
<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
38 lines
1.5 KiB
Go
38 lines
1.5 KiB
Go
// The MIT License
|
|
//
|
|
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
|
|
//
|
|
// Copyright (c) 2020 Uber Technologies, Inc.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
package tdbgtest
|
|
|
|
import (
|
|
"github.com/urfave/cli/v2"
|
|
"go.temporal.io/server/tools/tdbg"
|
|
)
|
|
|
|
// NewCliApp is a wrapper around [tdbg.NewCliApp] that sets the [cli.App.ExitErrHandler] to a no-op function.
|
|
func NewCliApp(opts ...tdbg.Option) *cli.App {
|
|
app := tdbg.NewCliApp(opts...)
|
|
app.ExitErrHandler = func(context *cli.Context, err error) {}
|
|
return app
|
|
}
|