Development Specifications on Custom Functions
When developing a custom function, the input and output parameters of the function must comply with the specifications in this section.
For details about how to compile a custom function, see Developing Functions.
Function Input Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Records | Yes | Array | Message records of an event source triggered by a workflow |
| inputs | No | Map[String]String | List of modifiable parameters |
| dynamic_source | No | Map | Parameter required for function execution, which can be used to pass to the service to be invoked. |
| execution_name | Yes | String | Workflow instance name |
| graph_name | Yes | String | Workflow name |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| region | No | String | Name of the current region |
Function Output Parameters
The following table defines the JSON structure of a custom function's output parameters:
| Parameter | Mandatory | Type | Description | Constraint |
|---|---|---|---|---|
| Records | Yes | Array | Message records of an event source triggered by a workflow | If there is no change, the output records are the same as the input records. |
| inputs | No | Map[String]String | List of modifiable parameters | If there are no new parameters, this will be the same as the input value. |
| dynamic_source | No | Map | Output parameter of a function. It can be passed to the next function to be executed. | - |
| execution_name | Yes | String | Workflow instance name | Inherits the execution_name value of the input parameter. |
| graph_name | Yes | String | Workflow name | Inherits the graph_name value of the input parameter. |
| operation_name | No | String | Operation name of a function | Operation names of built-in workflow functions are as follows:
|
Implementing a Function that Interconnects with the Built-in Frame Capturing Function (for GO Language)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | package main
import (
"encoding/json"
"errors"
"go-runtime/go-api/context"
)
func DemoHandler(jsonData []byte, ctx context.RuntimeContext) (interface{}, error) {
var eventMsg Payload
err := json.Unmarshal(jsonData, &eventMsg)
if err != nil {
return nil, errors.New("not correct format")
}
// Store the input bucket and object values.
record := eventMsg.Records[0]
// Output definitions.
resp := struct {
OBSMessages
Inputs map[string]interface{} `json:"inputs"`
ExecutionName string `json:"execution_name"`
GraphName string `json:"graph_name"`
DynamicSource struct {
*CreateThumbnailDynamicSourceBody
} `json:"dynamic_source"`
}{}
// Configure frame capturing parameters to provide parameter settings for downstream capturing tasks.
resp.DynamicSource.CreateThumbnailDynamicSourceBody = &CreateThumbnailDynamicSourceBody{
Thumbnails: []*ThumbnailCreateTaskBody{
&ThumbnailCreateTaskBody{
// Storage location of an input file
Input: &FileAddr{
Location: "cn-north-1",
BucketName: record.Obs.Bucket.Name,
Object: record.Obs.Object.Key,
},
// Storage location of an output file
Output: &FileAddr{
Location: "cn-north-1",
BucketName: record.Obs.Bucket.Name,
Object: "thumb_out",
},
// Whether to compress captured snapshots to a TAR package
Tar: 0,
// Whether to enable synchronous processing. Synchronous processing refers to quickly locating the snapshot position to take a snapshot.
Mode: 0,
// Frame capturing parameters
ThumbnailParam: &ThumbnailParam{
Type: "DOTS",
MaxLength: 0,
Dots: []int64{2, 10, 14}, // Frame capturing position (s)
OutputFileName: "default_cover.jpg",
},
},
},
}
// The following parameters need to be inherited and passed so that the downstream functions of the workflow can obtain the corresponding parameter values.
resp.Inputs = eventMsg.Inputs
resp.Records = eventMsg.Records
resp.GraphName = eventMsg.GraphName
resp.ExecutionName = eventMsg.ExecutionName
return resp, nil
}
|
Implementing a Function that Interconnects with the Built-in Transcoding Function (for GO Language)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | package main
import (
"encoding/json"
"errors"
"go-runtime/go-api/context"
)
func DemoTranscodeHandler(jsonData []byte, ctx context.RuntimeContext) (interface{}, error) {
var eventMsg Payload
err := json.Unmarshal(jsonData, &eventMsg)
if err != nil {
return nil, errors.New("not correct format")
}
// Store the input bucket and object values.
record := eventMsg.Records[0]
// Output definitions.
resp := struct {
OBSMessages
Inputs map[string]interface{} `json:"inputs"`
ExecutionName string `json:"execution_name"`
GraphName string `json:"graph_name"`
DynamicSource struct {
*CreateTranscodeDynamicSourceBody
} `json:"dynamic_source"`
}{}
// Configure frame capturing parameters to provide parameter settings for downstream capturing tasks.
resp.DynamicSource.CreateTranscodeDynamicSourceBody = &CreateTranscodeDynamicSourceBody{
Transcodes: []*CreateTranscodeTaskBody{
&CreateTranscodeTaskBody{
// Storage location of an input file
Input: &FileAddr{
Location: "cn-north-4",
BucketName: record.Obs.Bucket.Name,
Object: record.Obs.Object.Key,
},
// Storage location of an output file
Output: &FileAddr{
Location: "cn-north-4",
BucketName: record.Obs.Bucket.Name,
Object: "transcode_out",
},
TransTemplateID: []int{7000523, 7000524, 7000526, 7000528, 7000530, 7000538},
OutputFilenames: []string{"out_file1", "out_file2", "out_file3", "out_file4", "out_file5", "out_file6"},
},
},
}
// The following parameters need to be inherited and passed so that the downstream functions of the workflow can obtain the corresponding parameter values.
resp.Inputs = eventMsg.Inputs
resp.Records = eventMsg.Records
resp.GraphName = eventMsg.GraphName
resp.ExecutionName = eventMsg.ExecutionName
return resp, nil
}
|
Structure Example in Go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | package main
type CreateTranscodeDynamicSourceBody struct {
Transcodes []*CreateTranscodeTaskBody `json:"transcodes"`
}
type CreateTranscodeTaskBody struct {
// Storage location of an input file
Input *FileAddr `json:"input,omitempty"`
// Storage location of an output file
Output *FileAddr `json:"output"`
//Transcoding template ID, which is an array.
TransTemplateID []int `json:"trans_template_id,omitempty"`
// A maximum of 20 watermarks (images and texts) are supported.
Watermarks []*Watermark `json:"watermarks,omitempty"`
// Task priority.
Priority string `json:"priority,omitempty"`
// Output file name. Each output file has a name. If there are multiple output files, their names must be in sequence of the template ID array.
OutputFilenames []string `json:"output_filenames,omitempty"`
}
type Watermark struct {
Input *FileAddr `json:"input,omitempty"`
TemplateID int `json:"template_id,omitempty"`
TextContext string `json:"text_context,omitempty"`
ImageWatermark *ImageWatermark `json:"image_watermark,omitempty"`
TextWatermark *TextWatermark `json:"text_watermark,omitempty"`
}
type TextWatermark struct {
Dx string `json:"dx,omitempty"`
Dy string `json:"dy,omitempty"`
ReferPos string `json:"referpos,omitempty"`
TimelineStart string `json:"timeline_start,omitempty"`
TimelineDuration string `json:"timeline_duration,omitempty"`
FontName string `json:"font_name,omitempty"`
FontSize string `json:"font_size,omitempty"`
FontColor string `json:"font_color,omitempty"`
Base string `json:"base,omitempty"`
}
type ImageWatermark struct {
Dx string `json:"dx,omitempty"`
Dy string `json:"dy,omitempty"`
ReferPos string `json:"referpos,omitempty"`
TimelineStart string `json:"timeline_start,omitempty"`
TimelineDuration string `json:"timeline_duration,omitempty"`
ImageProcess string `json:"image_process,omitempty"`
Width string `json:"width,omitempty"`
Height string `json:"height,omitempty"`
Base string `json:"base,omitempty"`
}
type CreateThumbnailDynamicSourceBody struct {
Thumbnails []*ThumbnailCreateTaskBody `json:"thumbnails"`
}
//FileAddr file path structure
type FileAddr struct {
Location string `json:"location"`
BucketName string `json:"bucket"`
Object string `json:"object"`
}
type ThumbnailCreateTaskBody struct {
// Storage location of an input file
Input *FileAddr `json:"input"`
// Storage location of an output file
Output *FileAddr `json:"output"`
// Whether to compress captured snapshots to a TAR package
Tar int `json:"tar,omitempty"`
// Whether to enable synchronous processing. Synchronous processing refers to quickly locating the snapshot position to take a snapshot.
Mode int `json:"sync,omitempty"`
// Frame capturing parameters
ThumbnailParam *ThumbnailParam `json:"thumbnail_para"`
}
type ThumbnailParam struct {
Type string `json:"type"`
Time int64 `json:"time,omitempty"`
StartTime int64 `json:"start_time,omitempty"`
Duration int64 `json:"duration,omitempty"`
Dots []int64 `json:"dots,omitempty"`
Format int64 `json:"format,omitempty"`
AspectRatio int64 `json:"aspect_ratio,omitempty"`
Width int64 `json:"width,omitempty"`
Height int64 `json:"height,omitempty"`
MaxLength int64 `json:"max_length,omitempty"`
OutputFileName string `json:"output_filename,omitempty"`
}
type OBSMessages struct {
Records []OBSRecord `json:"Records"`
}
// OBSRecord OBS message format
type OBSRecord struct {
EventVersion string `json:"eventVersion"`
EventSource string `json:"eventSource"`
EventRegion string `json:"eventRegion"`
EventTime string `json:"eventTime"`
EventName string `json:"eventName"`
UserIdentity UserIdentity `json:"userIdentity"`
RequestParameters RequestParameters `json:"requestParameters"`
ResponseElements ResponseElements `json:"responseElements"`
Obs *OBSInfo `json:"obs"`
}
// UserIdentity User ID
type UserIdentity struct {
ID string `json:"ID,omitempty"`
}
//RequestParameters original request parameters
type RequestParameters struct {
SourceIPAddress string `json:"sourceIPAddress,omitempty"`
}
//ResponseElements Response parameters
type ResponseElements struct {
OBSRequestID string `json:"x-obs-request-id"`
OBSID2 string `json:"x-obs-id-2"`
}
// OBSInfo OBS information
type OBSInfo struct {
Version string `json:"Version"`
ConfigurationID string `json:"configurationId"`
Bucket BucketInfo `json:"bucket"`
Object ObjectInfo `json:"object"`
}
//BucketInfo Bucket information
type BucketInfo struct {
Name string `json:"name"`
OwnerIdentity UserIdentity `json:"ownerIdentity"`
Bucket string `json:"bucket"`
}
//ObjectInfo Object information
type ObjectInfo struct {
Key string `json:"key"`
Tag string `json:"eTag"`
Size uint64 `json:"size"`
VersionID string `json:"versionId"`
Sequencer string `json:"sequencer"`
}
type Payload struct {
ExecutionName string `json:"execution_name"`
GraphName string `json:"graph_name"`
OBSMessages
DynamicSource interface{} `json:"dynamic_source"`
Inputs map[string]interface{} `json:"inputs"`
}
|
Last Article: Configuring Data+
Next Article: Built-in Template Parameters
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.