当前位置:网站首页>Three simple steps to quickly complete order data processing through workflow (ASW)
Three simple steps to quickly complete order data processing through workflow (ASW)
2022-06-24 17:25:00 【Tencent cloud workflow】
How does this article describe workflow ASW Edit and arrange cloud function , Quickly complete the order data processing .
working principle
- Workflow calls function to get order data in a certain period of time , Preprocess the data .
- Give the preprocessed data to Map Iterative task processing : After data processing of each order , Write to different database tables , Or draw a chart to show .
Operation steps
Creating a workflow requires first creating a state machine , By choreographing the different components of the state machine , Change the state machine structure , So as to achieve user-defined function set .
It's a simple three-step process : Create cloud functions → Create workflow → Running state machine
Step 1: Create cloud functions
establish GetOrder function
- Sign in Cloud function console , Click... On the left navigation bar 【 Function service 】.
- Select Guangzhou in the function service area above the main interface , And click 【 newly build 】, Enter the function creation process .
- On the new function page , Fill in the following information in the basic information :
- The name of the function :GetOrder.
- Running environment :Nodejs10.15.
- How it was created : Select the blank function , single click 【 next step 】 Go to function configuration .
- In the function configuration page Cloud Studio In the pane , Delete the original code , Copy the code shown below :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is get order function");
# You can api Request for real order data , The data in the example is convenient to simulate workflow execution
var orderlist = [
{
"orderId":"202012200001",
"goodsId":"1004",
"goodsName":" a mandarin orange #1004",
"unit":" Pieces of ",
"specific":"5 One kilo a box ",
"linePrice":100,
"salePrice":90,
"costPrice":80,
"number":30,
"isVoucher":1,
"voucherPrice":2,
"voucherId":"3dr55678hj",
"isDiscount":1,
"discountPrice":3,
"carriage": 8,
"receiver":"susu",
"phone":"18633567898",
"address":" Tencent building, Nanshan District, Shenzhen 20 floor ",
"createTime":"2020-12-20 10:00:00",
"payTime":"2020-12-20 11:00:00",
"payMethod":1,
"payOrder":"202012201100003940",
"orderStatus":3,
"deliveryTime":"2020-12-21 11:00:00",
"finishTime":"2020-12-25 11:00:00",
"deliveryOrder":"ZT12345789d786",
"isReturn":1,
"returnId":"2020122600012",
"returnNumber":2,
},
{
"orderId":"202012200001",
"goodsId":"2001",
"goodsName":" pears #2001",
"unit":" Pieces of ",
"specific":"6 One kilo a box ",
"linePrice":150,
"salePrice":120,
"costPrice":90,
"number":20,
"isVoucher":1,
"voucherPrice":3,
"voucherId":"3dr55678hj",
"isDiscount":1,
"discountPrice":5,
"carriage": 0,
"receiver":"susu",
"phone":"18633567898",
"address":" Tencent building, Nanshan District, Shenzhen 20 floor ",
"createTime":"2020-12-20 10:00:00",
"payTime":"2020-12-20 11:00:00",
"payMethod":1,
"payOrder":"202012201100003940",
"orderStatus":3,
"deliveryTime":"2020-12-21 11:00:00",
"finishTime":"2020-12-25 11:00:00",
"deliveryOrder":"ZT12345789d786",
"isReturn":0,
"returnId":"",
"returnNumber":0,
},
{
"orderId":"202012200001",
"goodsId":"3005",
"goodsName":" Banana #3005",
"unit":" Pieces of ",
"specific":"10 One kilo a box ",
"linePrice":180,
"salePrice":150,
"costPrice":98,
"number":6,
"isVoucher":1,
"voucherPrice":8,
"voucherId":"3dr55678hj",
"isDiscount":1,
"discountPrice":20,
"carriage": 0,
"receiver":"susu",
"phone":"18633567898",
"address":" Tencent building, Nanshan District, Shenzhen 20 floor ",
"createTime":"2020-12-20 10:00:00",
"payTime":"2020-12-20 11:00:00",
"payMethod":1,
"payOrder":"202012201100003940",
"orderStatus":3,
"deliveryTime":"2020-12-21 11:00:00",
"finishTime":"2020-12-25 11:00:00",
"deliveryOrder":"ZT12345789d786",
"isReturn":1,
"returnId":"2020122600013",
"returnNumber":3,
}
];
return {"orderList":orderlist};
};- single click 【 preservation 】, The cloud function is created successfully
establish ProcessOrder function
Reference resources 【 establish GetOrder function 】 The way , establish ProcessOrder function , The code is as follows :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is processOrder function");
var order = event;
# Data processing
var income = order["salePrice"]-order["costPrice"];
var goodsInfo = {"goodsId":order["goodId"],"goodsName":order["goodsName"],"number":order["number"]};
var incomeInfo = {"goodsId":order["goodId"],"goodsName":order["goodsName"],"number":order["number"],"income":income};
return {
"goodsInfo":goodsInfo,
"incomeInfo":incomeInfo,
"salesInfo":salesInfo
};
}establish GoodsSold function
Reference resources 【 establish GetOrder function 】 The way , establish GoodsSold function , The code is as follows :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is goodsSold function");
// Some write to database or graph display operations
console.log(event);
return "GoodsSold success";
};establish Income function
Reference resources 【 establish GetOrder function 】 The way , establish Income function , The code is as follows :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is income function");
// Some write to database or graph display operations
console.log(event);
return "Income success";
};establish SalesReturn function
Reference resources 【 establish GetOrder function 】 The way , establish SalesReturn function , The code is as follows :
'use strict';
exports.main_handler = async (event, context) => {
console.log("this is salesReturn function");
// Some write to database or graph display operations
console.log(event);
return "SalesReturn success";
};Step 2: Create workflow
- Sign in Application and choreography service flow console .
- On the state machine page , single click 【 newly build 】, Go to the create workflow page , Choose to use 【 Code creation 】:
- Paste the following directly in the code edit box TCSL Code :
{
"Comment": " The order processing ",
"StartAt": "GetOrder",
"States": {
"GetOrder": {
"Type": "Task",
"Comment": " Pull data ",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/GetOrder",
"Next": "MapProcess"
},
"MapProcess": {
"Type": "Map",
"ItemsPath": "$.orderList",
"MaxConcurrency": 6,
"Iterator": {
"StartAt": "ProcessOrder",
"States": {
"ProcessOrder": {
"Type": "Task",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/ProcessOrder",
"Next": "ParallelDataProcess"
},
"ParallelDataProcess": {
"Type": "Parallel",
"End": true,
"Branches": [
{
"StartAt": "GoodsSold",
"States": {
"GoodsSold": {
"InputPath": "$.goodsInfo",
"Type": "Task",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/GoodsSold",
"End": true
}
}
},
{
"StartAt": "Income",
"States": {
"Income": {
"InputPath": "$.incomeInfo",
"Type": "Task",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/Income",
"End": true
}
}
},
{
"StartAt": "SalesReturn",
"States": {
"SalesReturn": {
"InputPath": "$.salesInfo",
"Type": "Task",
"Resource": "qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/SalesReturn",
"End": true
}
}
}
]
}
}
},
"End": true
}
}
}- Click in the upper right corner 【 next step 】, Enter the save interface , Enter the name of the state machine , Run role selection 【 New character 】, Type selection 【 Standard state machine 】, Click in the upper right corner 【 complete 】, You can see the created state machine on the state machine list page .
To use an existing role, you need to create a role first , And empower the role with relevant policies , Please refer to Running roles .
Step 3: Running state machine
After the state machine is created , You can view the created state machine on the main page after login .
- Click... Of the state machine you want to run 【 name 】, Enter the state machine .
- You can see the basic information of the state machine in the interface . single click 【 Workflow execution 】 Under the 【 Start execution 】 .
- In the pop-up “ Input ” Window , With JSON Format the input required by the state machine . for example :
{"comment": "invoke workflow"}- single click 【 determine 】, After completing the state execution , You can view the execution results on the details page :
- Slide to the bottom of the page , stay 【 Execution history 】 Under entry , You can view the operation of the child node .
The above steps introduce the basic workflow of an order data processing scenario .
In a real business scenario, every Task Nodes will be involved in configuring some relevant parameter information , For example, do parameter transfer 、 Exception retrial and error capture processing, etc , For more details, please refer to State machine language .
Apply for probation ASW
ASW At present, it is in the public beta stage , The public beta stage is free of charge . Welcome to suggest product improvements , After the feedback is adopted, you can get Tencent Mengxin short goose doll !
immediately Apply for the public test , We're going to be 3 Complete the approval within working days , And inform you through SMS and on-site letters , Thank you for your support .
边栏推荐
- [play with Tencent cloud] play with cloud database mysql
- Introduction to visual studio shortcut keys and advanced gameplay
- Meituan financial report: making money while burning money
- Tencent released "warehouse express" and issued "ID card" for each commodity!
- zblog系统如何根据用户ID获取用户相关信息的教程
- Can you remember the code of a programming boss? Can you hit it out without Baidu?
- Cloud native monitoring practice (2) monitoring and collection of components outside the TKE cluster
- What is the reason for the worse website SEO ranking?
- Example description and case of ansible playbook automated cluster server management
- [play Tencent cloud] experience and development of game multimedia engine (II)
猜你喜欢
随机推荐
How to build RTSP test URL in Intranet Environment
Sigai intelligent container damage identification products are deployed in Rizhao Port and Yingkou Port
IBM: supporting AI and enterprise digital reshaping in the cloud era with modern architecture
Cloud native monitoring configuration self built alertmanager to realize alarm
[DB Bao 45] MySQL highly available mgr+consult architecture deployment
Tencent cloud layer 7 load balancing log analysis and monitoring
ClassNotFoundException v/s NoClassDefFoundError
Kubernetes 1.20.5 helm installation Jenkins
2. Leveldb design principle -- LSM
Elastic searchable snapshot function (frozen Tier 3)
March 27, 2021: give you a head node of the linked list, and rotate the linked list
zblog系统实现前台调用当天发布文章数量的教程
QQ domain name detection API interface sharing (with internal access automatic jump PHP code)
GB gb28181 video cascading intelligent analysis platform easygbs broadcast video console error 401
Pagoda activities, team members can enjoy a lightweight server 1 core 2g5m 28 yuan for two years
[play with Tencent cloud] TSF User Guide
TVP experts talk about geese factory middleware: innovating forward and meeting the future
Meituan financial report: making money while burning money
Example description and case of ansible playbook automated cluster server management
Quick view of product trends in February 2021

