当前位置:网站首页>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 .
边栏推荐
- Implement typescript runtime type checking
- March 27, 2021: give you a head node of the linked list, and rotate the linked list
- Go collaboration and pipeline to realize asynchronous batch consumption scheduling task
- [log service CLS] Tencent cloud game battle engine mgobe accesses CLS
- FPGA systematic learning notes serialization_ Day10 [sequential logic, competitive adventure, synchronous reset, asynchronous reset]
- Try catch finally implementation mechanism
- Collect tke logs through daemonset CRD
- 03. Tencent cloud IOT device side learning -- overview of mqtt control package
- Explanation of MySQL indexing principle
- Analysis of signal preemptive scheduling based on go language from source code
猜你喜欢
随机推荐
About with admin option and with grant option
Meituan financial report: making money while burning money
Easycvr, an urban intelligent video monitoring image analysis platform, plays national standard equipment videos and captures unstable packets for troubleshooting
With the solution, the nickname of the applet suddenly becomes "wechat user", and the avatar cannot be displayed?
Development of block hash game guessing system (mature code)
Install Clickhouse client code 210 connection referred (localhost:9000)
Customizing security groups using BPF
Users of the Tiktok open platform are authorized to obtain the user's fan statistics and short video data
Zblog system realizes the tutorial of the number of articles published on the same day when the foreground calls
## Kubernetes集群中流量暴露的几种方案 Kubernetes集群中流量暴露的几种方案
Analysis of software supply chain attack package preemption low cost phishing
[play with Tencent cloud] TSF User Guide
zblog判断某个插件是否安装启用的内置函数代码
How to get the response body content in gin?
Learn typescript with VAM (phase 1)
Using consistent hash algorithm in Presto to enhance the data cache locality of dynamic clusters
让UPS“印象派用户”重新认识可靠性
Introduction to koa (II) building the koa program
Industrial security experts talk about DDoS countermeasures from the perspective of attack and defense
Best practices for H5 page adaptation and wechat default font size