MCPcopy Create free account
hub / github.com/temporalio/temporal / decodeTask

Function decodeTask

tools/tdbg/chasm_decoder.go:53–110  ·  view source on GitHub ↗
(
	task *persistencespb.ChasmComponentAttributes_Task,
	registry *chasm.Registry,
)

Source from the content-addressed store, hash-verified

51}
52
53func decodeTask(
54 task *persistencespb.ChasmComponentAttributes_Task,
55 registry *chasm.Registry,
56) (*decodedTask, error) {
57 typeID := task.GetTypeId()
58 fqn, _ := registry.TaskFqnByID(typeID)
59
60 var scheduledTime string
61 if ts := task.GetScheduledTime(); ts != nil {
62 scheduledTime = ts.AsTime().UTC().Format(defaultDateTimeFormat)
63 }
64
65 decoded := &decodedTask{
66 TypeID: typeID,
67 TaskFQN: fqn,
68 Destination: task.GetDestination(),
69 ScheduledTime: scheduledTime,
70 VersionedTransition: task.GetVersionedTransition(),
71 PhysicalTaskStatus: task.GetPhysicalTaskStatus(),
72 }
73
74 rt, ok := registry.TaskByID(typeID)
75 if !ok {
76 decoded.RawData = task.GetData()
77 return decoded, nil
78 }
79
80 goType := rt.GoType()
81 if goType == nil {
82 decoded.RawData = task.GetData()
83 return decoded, nil
84 }
85
86 messageValue := reflect.New(goType.Elem())
87 message, ok := messageValue.Interface().(proto.Message)
88 if !ok {
89 decoded.RawData = task.GetData()
90 return decoded, nil
91 }
92
93 dataBlob := task.GetData()
94 if dataBlob != nil && len(dataBlob.GetData()) > 0 {
95 message = message.ProtoReflect().New().Interface()
96 if err := serialization.Decode(dataBlob, message); err != nil {
97 decoded.RawData = dataBlob
98 return decoded, nil
99 }
100 }
101
102 jsonBytes, err := codec.NewJSONPBEncoder().Encode(message)
103 if err != nil {
104 decoded.RawData = dataBlob
105 return decoded, nil
106 }
107
108 decoded.DecodedData = json.RawMessage(jsonBytes)
109 return decoded, nil
110}

Callers 1

decodeTasksFunction · 0.85

Calls 15

DecodeFunction · 0.92
NewJSONPBEncoderFunction · 0.92
TaskFqnByIDMethod · 0.80
GetPhysicalTaskStatusMethod · 0.80
TaskByIDMethod · 0.80
GetScheduledTimeMethod · 0.65
GetDestinationMethod · 0.65
GetDataMethod · 0.65
NewMethod · 0.65
EncodeMethod · 0.65
GetTypeIdMethod · 0.45
FormatMethod · 0.45

Tested by

no test coverage detected