代码拉取完成,页面将自动刷新
package tcc
import (
"database/sql"
"encoding/json"
"fmt"
"time"
)
type tccAction struct {
Name string `json:",omitempty"`
Raw json.RawMessage
Status string `json:",omitempty"`
}
func marshalAction(action Action) ([]byte, error) {
actionJson, err := json.Marshal(action)
if err != nil {
return nil, err
}
return json.Marshal(tccAction{
Name: action.Name(),
Raw: json.RawMessage(actionJson),
})
}
func (ta tccAction) confirm(tcc *TCC, tx *sql.Tx, actionIndex int) (time.Duration, bool, error) {
action, err := tcc.engine.unmarshalAction(ta.Name, ta.Raw)
if err != nil {
return time.Hour, true, err
}
if err := action.Confirm(); err != nil {
return 0, true, err
}
return setActionStatus(tcc, tx, actionIndex, statusConfirmed, "confirm action")
}
func (ta tccAction) cancel(tcc *TCC, tx *sql.Tx, actionIndex int) (time.Duration, bool, error) {
action, err := tcc.engine.unmarshalAction(ta.Name, ta.Raw)
if err != nil {
return time.Hour, true, err
}
if err := action.Cancel(); err != nil {
return 0, true, err
}
return setActionStatus(tcc, tx, actionIndex, statusCanceled, "cancel action")
}
func setActionStatus(
tcc *TCC, tx *sql.Tx, actionIndex int, status, method string,
) (time.Duration, bool, error) {
setSql := fmt.Sprintf(
`data = jsonb_set(data, '{Actions,%d,Status}'::text[], to_jsonb('%s'::text))`,
actionIndex, status,
)
canCommit, err := tcc.update(setSql, status, method, tx)
return 0, canCommit, err
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。