Skip to content

Commit 091e4df

Browse files
author
wanjiewu
committed
完善工作流实例查询接口
1 parent 89bf394 commit 091e4df

File tree

4 files changed

+231
-2
lines changed

4 files changed

+231
-2
lines changed

ci_media.go

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"fmt"
88
"net/http"
99
"strings"
10+
11+
"github.com/clbanning/mxj"
12+
"github.com/mitchellh/mapstructure"
1013
)
1114

1215
type JobInput struct {
@@ -756,3 +759,221 @@ func (s *CIService) GetPrivateM3U8(ctx context.Context, name string, opt *GetPri
756759
resp, err := s.client.send(ctx, &sendOpt)
757760
return resp, err
758761
}
762+
763+
type TriggerWorkflowOptions struct {
764+
WorkflowId string `url:"workflowId"`
765+
Object string `url:"object"`
766+
}
767+
768+
type TriggerWorkflowResult struct {
769+
XMLName xml.Name `xml:"Response"`
770+
InstanceId string `xml:"InstanceId"`
771+
RequestId string `xml:"RequestId"`
772+
}
773+
774+
//单文件触发工作流 https://cloud.tencent.com/document/product/460/54640
775+
func (s *CIService) TriggerWorkflow(ctx context.Context, opt *TriggerWorkflowOptions) (*TriggerWorkflowResult, *Response, error) {
776+
var res TriggerWorkflowResult
777+
sendOpt := sendOptions{
778+
baseURL: s.client.BaseURL.CIURL,
779+
uri: "/triggerworkflow",
780+
optQuery: opt,
781+
method: http.MethodPost,
782+
result: &res,
783+
}
784+
resp, err := s.client.send(ctx, &sendOpt)
785+
return &res, resp, err
786+
}
787+
788+
type DescribeWorkflowExecutionsOptions struct {
789+
WorkflowId string `url:"workflowId,omitempty"`
790+
Name string `url:"Name,omitempty"`
791+
OrderByTime string `url:"orderByTime,omitempty"`
792+
NextToken string `url:"nextToken,omitempty"`
793+
Size int `url:"size,omitempty"`
794+
States string `url:"states,omitempty"`
795+
StartCreationTime string `url:"startCreationTime,omitempty"`
796+
EndCreationTime string `url:"endCreationTime,omitempty"`
797+
}
798+
799+
type WorkflowExecutionList struct {
800+
RunId string `xml:"RunId,omitempty"`
801+
WorkflowId string `xml:"WorkflowId,omitempty"`
802+
State string `xml:"State,omitempty"`
803+
CreationTime string `xml:"CreationTime,omitempty"`
804+
Object string `xml:"Object,omitempty"`
805+
}
806+
807+
type DescribeWorkflowExecutionsResult struct {
808+
XMLName xml.Name `xml:"Response"`
809+
WorkflowExecutionList []WorkflowExecutionList `xml:"WorkflowExecutionList,omitempty"`
810+
NextToken string `xml:"NextToken,omitempty"`
811+
}
812+
813+
//获取工作流实例列表 https://cloud.tencent.com/document/product/460/45950
814+
func (s *CIService) DescribeWorkflowExecutions(ctx context.Context, opt *DescribeWorkflowExecutionsOptions) (*DescribeWorkflowExecutionsResult, *Response, error) {
815+
var res DescribeWorkflowExecutionsResult
816+
sendOpt := sendOptions{
817+
baseURL: s.client.BaseURL.CIURL,
818+
uri: "/workflowexecution",
819+
optQuery: opt,
820+
method: http.MethodGet,
821+
result: &res,
822+
}
823+
resp, err := s.client.send(ctx, &sendOpt)
824+
return &res, resp, err
825+
}
826+
827+
type NotifyConfig struct {
828+
URL string `xml:"Url,omitempty"`
829+
Event string `xml:"Event,omitempty"`
830+
Type string `xml:"Type,omitempty"`
831+
}
832+
833+
type ExtFilter struct {
834+
State string `xml:"State,omitempty"`
835+
Audio string `xml:"Audio,omitempty"`
836+
Custom string `xml:"Custom,omitempty"`
837+
CustomExts string `xml:"CustomExts,omitempty"`
838+
AllFile string `xml:"AllFile,omitempty"`
839+
}
840+
841+
type NodeInput struct {
842+
QueueId string `xml:"QueueId,omitempty"`
843+
ObjectPrefix string `xml:"ObjectPrefix,omitempty"`
844+
NotifyConfig *NotifyConfig `xml:"NotifyConfig,omitempty" json:"NotifyConfig,omitempty"`
845+
ExtFilter *ExtFilter `xml:"ExtFilter,omitempty" json:"ExtFilter,omitempty"`
846+
}
847+
848+
type NodeSegment struct {
849+
Format string `xml:"Format,omitempty"`
850+
Duration string `xml:"Duration,omitempty"`
851+
}
852+
853+
type NodeOutput struct {
854+
Region string `xml:"Region,omitempty"`
855+
Bucket string `xml:"Bucket,omitempty"`
856+
Object string `xml:"Object,omitempty"`
857+
AuObject string `xml:"AuObject,omitempty"`
858+
SpriteObject string `xml:"SpriteObject,omitempty"`
859+
}
860+
861+
type NodeSCF struct {
862+
Region string `xml:"Region,omitempty"`
863+
FunctionName string `xml:"FunctionName,omitempty"`
864+
Namespace string `xml:"Namespace,omitempty"`
865+
}
866+
867+
type NodeSDRtoHDR struct {
868+
HdrMode string `xml:"HdrMode,omitempty"`
869+
}
870+
871+
type NodeSmartCover struct {
872+
Format string `xml:"Format,omitempty"`
873+
Width string `xml:"Width,omitempty"`
874+
Height string `xml:"Height,omitempty"`
875+
Count string `xml:"Count,omitempty"`
876+
DeleteDuplicates string `xml:"DeleteDuplicates,omitempty"`
877+
}
878+
879+
type NodeOperation struct {
880+
TemplateId string `xml:"TemplateId,omitempty" json:"TemplateId,omitempty"`
881+
Segment *NodeSegment `xml:"Segment,omitempty" json:"Segment,omitempty" `
882+
Output *NodeOutput `xml:"Output,omitempty" json:"Output,omitempty"`
883+
SCF *NodeSCF `xml:"SCF,omitempty" json:"SCF,omitempty"`
884+
SDRtoHDR *NodeSDRtoHDR `xml:"SDRtoHDR,omitempty" json:"SDRtoHDR,omitempty"`
885+
SmartCover *NodeSmartCover `xml:"SmartCover,omitempty" json:"SmartCover,omitempty"`
886+
WatermarkTemplateId string `xml:"WatermarkTemplateId,omitempty" json:"WatermarkTemplateId,omitempty`
887+
TranscodeTemplateId string `xml:"TranscodeTemplateId,omitempty" json:"TranscodeTemplateId,omitempty"`
888+
}
889+
890+
type Node struct {
891+
Type string `xml:"Type"`
892+
Input *NodeInput `xml:"Input,omitempty" json:"Input,omitempty"`
893+
Operation *NodeOperation `xml:"Operation,omitempty" json:"Operation,omitempty"`
894+
}
895+
896+
type Topology struct {
897+
Dependencies map[string]string `json:"Dependencies,omitempty"`
898+
Nodes map[string]Node `json:"Nodes,omitempty"`
899+
}
900+
901+
func (m *Topology) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
902+
var v struct {
903+
XMLName xml.Name //`xml:"Topology"`
904+
Dependencies struct {
905+
Inner []byte `xml:",innerxml"`
906+
} `xml:"Dependencies"`
907+
Nodes struct {
908+
Inner []byte `xml:",innerxml"`
909+
} `xml:"Nodes"`
910+
}
911+
err := d.DecodeElement(&v, &start)
912+
if err != nil {
913+
return err
914+
}
915+
916+
myMap := make(map[string]interface{})
917+
918+
// ... do the mxj magic here ... -
919+
920+
temp := v.Nodes.Inner
921+
922+
prefix := "<Nodes>"
923+
postfix := "</Nodes>"
924+
str := prefix + string(temp) + postfix
925+
//fmt.Println(str)
926+
myMxjMap, _ := mxj.NewMapXml([]byte(str))
927+
myMap, _ = myMxjMap["Nodes"].(map[string]interface{})
928+
nodesMap := make(map[string]Node)
929+
930+
for k, v := range myMap {
931+
var node Node
932+
mapstructure.Decode(v, &node)
933+
nodesMap[k] = node
934+
}
935+
936+
// fill myMap
937+
m.Nodes = nodesMap
938+
939+
deps := make(map[string]interface{})
940+
941+
tep := "<Dependencies>" + string(v.Dependencies.Inner) + "</Dependencies>"
942+
tepMxjMap, _ := mxj.NewMapXml([]byte(tep))
943+
deps, _ = tepMxjMap["Dependencies"].(map[string]interface{})
944+
depsString := make(map[string]string)
945+
for k, v := range deps {
946+
depsString[k] = v.(string)
947+
}
948+
m.Dependencies = depsString
949+
return nil
950+
}
951+
952+
type WorkflowExecution struct {
953+
RunId string `xml:"RunId,omitempty" json:"RunId,omitempty"`
954+
WorkflowId string `xml:"WorkflowId,omitempty" json:"WorkflowId,omitempty"`
955+
WorkflowName string `xml:"WorkflowName,omitempty" json:"WorkflowName,omitempty"`
956+
State string `xml:"State,omitempty" json:"State,omitempty"`
957+
CreateTime string `xml:"CreateTime,omitempty" json:"CreateTime,omitempty"`
958+
Object string `xml:"Object,omitempty" json:"Object,omitempty"`
959+
Topology Topology `xml:"Topology,omitempty" json:"Topology,omitempty"`
960+
}
961+
962+
type DescribeWorkflowExecutionResult struct {
963+
XMLName xml.Name `xml:"Response"`
964+
WorkflowExecution []WorkflowExecution `xml:"WorkflowExecution,omitempty" json:"WorkflowExecution,omitempty"`
965+
NextToken string `xml:"NextToken,omitempty" json:"NextToken,omitempty"`
966+
}
967+
968+
//获取工作流实例详情 https://cloud.tencent.com/document/product/460/45949
969+
func (s *CIService) DescribeWorkflowExecution(ctx context.Context, runId string) (*DescribeWorkflowExecutionResult, *Response, error) {
970+
var res DescribeWorkflowExecutionResult
971+
sendOpt := sendOptions{
972+
baseURL: s.client.BaseURL.CIURL,
973+
uri: "/workflowexecution/" + runId,
974+
method: http.MethodGet,
975+
result: &res,
976+
}
977+
resp, err := s.client.send(ctx, &sendOpt)
978+
return &res, resp, err
979+
}

example/CI/media_process/media_process.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ func TriggerWorkflow() {
891891
})
892892
triggerWorkflowOpt := &cos.TriggerWorkflowOptions{
893893
WorkflowId: "w18fd791485904afba3ab07ed57d9cf1e",
894-
Object: "100986-2999.mp4",
894+
Object: "100986-2999.mp4",
895895
}
896896
triggerWorkflowRes, _, err := c.CI.TriggerWorkflow(context.Background(), triggerWorkflowOpt)
897897
log_status(err)
@@ -940,7 +940,7 @@ func DescribeMultiWorkflowExecution() {
940940
},
941941
},
942942
})
943-
describeWorkflowExecutionsRes, _, err := c.CI.DescribeWorkflowExecution(context.Background(), "i00689df860ad11ec9c5952540019ee59")
943+
describeWorkflowExecutionsRes, _, err := c.CI.DescribeWorkflowExecution(context.Background(), "i00689df860ad11ec9c5952540019ee59")
944944
log_status(err)
945945
a, _ := json.Marshal(describeWorkflowExecutionsRes)
946946
fmt.Println(string(a))

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ go 1.12
44

55
require (
66
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409
7+
github.com/clbanning/mxj v1.8.4
78
github.com/google/go-querystring v1.0.0
89
github.com/google/uuid v1.1.1
10+
github.com/mitchellh/mapstructure v1.4.3
911
github.com/mozillazg/go-httpheader v0.2.1
1012
github.com/stretchr/testify v1.3.0
1113
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.194

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
2+
github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=
3+
github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
24
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
36
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
47
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
8+
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
9+
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
10+
github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ=
511
github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60=
612
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
713
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

0 commit comments

Comments
 (0)