mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? - Use plain go struct inside migration workflow activity input output - Customize the json encoding/decoding for migration execution info and make it backward & forward compatible. - This will temporary break cloud and the fix is in https://github.com/temporalio/temporal/pull/9097 - This PR needs to be part of oss v1.30 release. ## Why? - Backward compatibility and less confusion over how the encoding will be done. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [x] added new unit test(s) - [ ] added new functional test(s)
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package migration
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
type ExecutionInfo struct {
|
|
executionInfoNewJSON
|
|
}
|
|
|
|
type executionInfoNewJSON struct {
|
|
BusinessID string `json:"business_id,omitempty"`
|
|
RunID string `json:"run_id,omitempty"`
|
|
ArchetypeID uint32 `json:"archetype_id,omitempty"`
|
|
}
|
|
|
|
type executionInfoLegacyJSON struct {
|
|
BusinessID string `json:"business_id,omitempty"`
|
|
WorkflowID string `json:"workflow_id,omitempty"`
|
|
RunID string `json:"run_id,omitempty"`
|
|
ArchetypeID uint32 `json:"archetype_id,omitempty"`
|
|
}
|
|
|
|
func (e *ExecutionInfo) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(executionInfoLegacyJSON{
|
|
WorkflowID: e.BusinessID,
|
|
RunID: e.RunID,
|
|
ArchetypeID: e.ArchetypeID,
|
|
})
|
|
}
|
|
|
|
func (e *ExecutionInfo) UnmarshalJSON(data []byte) error {
|
|
// For forward compatibility, support both workflow_id and business_id here.
|
|
// Then in v1.31, we can always encode using "business_id" and also support downgrade.
|
|
var legacy executionInfoLegacyJSON
|
|
if err := json.Unmarshal(data, &legacy); err != nil {
|
|
return err
|
|
}
|
|
|
|
businessID := legacy.WorkflowID
|
|
if legacy.BusinessID != "" {
|
|
businessID = legacy.BusinessID
|
|
}
|
|
|
|
e.executionInfoNewJSON = executionInfoNewJSON{
|
|
BusinessID: businessID,
|
|
RunID: legacy.RunID,
|
|
ArchetypeID: legacy.ArchetypeID,
|
|
}
|
|
return nil
|
|
}
|