{"componentChunkName":"component---src-templates-best-practice-detail-tsx","path":"/best-practice/2021-01-28-asw-order","result":{"data":{"currentBlog":{"id":"c21445e2-63c7-51ea-96b7-33274e34af3f","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/a0345eb9192c11afc25a1aceeb4e0e03.jpg","authors":["Susu"],"categories":["best-practice"],"date":"2021-01-28T00:00:00.000Z","title":"简单三步，通过工作流（ASW）快速完成订单数据处理","description":"本文介绍如何通过工作流 ASW 编排云函数，快速完成订单数据的处理","authorslink":null,"translators":null,"translatorslink":null,"tags":["Serverless","工作流 ASW"],"keywords":null,"outdated":null},"wordCount":{"words":198,"sentences":48,"paragraphs":48},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2021-01-28-asw-order.md","fields":{"slug":"/best-practice/2021-01-28-asw-order/","keywords":["go","serverless","云函数","状态机","创建","函数"]},"html":"<p>本文介绍如何通过<a href=\"https://cloud.tencent.com/product/asw?ADTAG=outer.zhihu\">工作流 ASW</a> 编排云函数，快速完成订单数据的处理。 </p>\n<h2 id=\"工作原理\"><a href=\"#%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86\" aria-label=\"工作原理 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>工作原理</h2>\n<ol>\n<li>工作流调用函数获取一定时间段内的订单数据，对数据进行预处理。</li>\n<li>将预处理的数据交给 Map 迭代任务处理：每个订单进行数据处理后，分别写到不同的数据库表中，或者绘制成图表展示。</li>\n</ol>\n<p><img src=\"https://main.qcloudimg.com/raw/12a4bf778b5a8e9361f1afa61973d8de.svg\"></p>\n<h2 id=\"操作步骤\"><a href=\"#%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4\" aria-label=\"操作步骤 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>操作步骤</h2>\n<p>创建工作流程需要首先创建一个状态机，通过编排状态机的不同元件，改变状态机结构，从而实现用户自定义的功能集合。</p>\n<p>简单三步即可完成：创建云函数 → 创建工作流 → 运行状态机</p>\n<h3 id=\"step-1：创建云函数\"><a href=\"#step-1%EF%BC%9A%E5%88%9B%E5%BB%BA%E4%BA%91%E5%87%BD%E6%95%B0\" aria-label=\"step 1：创建云函数 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Step 1：创建云函数</h3>\n<h4 id=\"创建-getorder-函数\"><a href=\"#%E5%88%9B%E5%BB%BA-getorder-%E5%87%BD%E6%95%B0\" aria-label=\"创建 getorder 函数 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>创建 GetOrder 函数</h4>\n<ol>\n<li>登录 <a href=\"https://console.cloud.tencent.com/scf/list?rid=1&#x26;ns=default\">云函数控制台</a>，单击左侧导航栏的【函数服务】。</li>\n<li>在主界面上方函数服务区域选择广州，并单击【新建】，进入函数创建流程。</li>\n<li>\n<p>在新建函数页面，基本信息中填写以下信息：</p>\n<ul>\n<li>函数名称：GetOrder。</li>\n<li>运行环境：Nodejs10.15。</li>\n<li>创建方式：选择空白函数，单击【下一步】进入函数配置。</li>\n</ul>\n</li>\n<li>在函数配置页面中的 <strong>Cloud Studio</strong> 窗格中，删除原有代码，复制如下所示的代码：</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">   &#39;use strict&#39;;\n   exports.main_handler = async (event, context) =&gt; {\n       console.log(&quot;this is get order function&quot;);\n       # 您可以通过api请求获取真实的订单数据，样例中数据方便模拟工作流执行\n          var orderlist = [\n           {\n               &quot;orderId&quot;:&quot;202012200001&quot;,\n               &quot;goodsId&quot;:&quot;1004&quot;,\n               &quot;goodsName&quot;:&quot;橘子#1004&quot;,\n               &quot;unit&quot;:&quot;件&quot;,\n               &quot;specific&quot;:&quot;5斤一箱&quot;,\n               &quot;linePrice&quot;:100,\n               &quot;salePrice&quot;:90,\n               &quot;costPrice&quot;:80,\n               &quot;number&quot;:30,\n   \t\t\t&quot;isVoucher&quot;:1,\n   \t\t\t&quot;voucherPrice&quot;:2,\n   \t\t\t&quot;voucherId&quot;:&quot;3dr55678hj&quot;,\n   \t\t\t&quot;isDiscount&quot;:1,\n   \t\t\t&quot;discountPrice&quot;:3,\n   \t\t\t&quot;carriage&quot;: 8,\n   \t\t\t&quot;receiver&quot;:&quot;susu&quot;,\n   \t\t\t&quot;phone&quot;:&quot;18633567898&quot;,\n   \t\t\t&quot;address&quot;:&quot;深圳市南山区腾讯大厦20楼&quot;,\n   \t\t\t&quot;createTime&quot;:&quot;2020-12-20 10:00:00&quot;,\n   \t\t\t&quot;payTime&quot;:&quot;2020-12-20 11:00:00&quot;,\n   \t\t\t&quot;payMethod&quot;:1, \n   \t\t\t&quot;payOrder&quot;:&quot;202012201100003940&quot;,\n   \t\t\t&quot;orderStatus&quot;:3,\n   \t\t\t&quot;deliveryTime&quot;:&quot;2020-12-21 11:00:00&quot;,\n   \t\t\t&quot;finishTime&quot;:&quot;2020-12-25 11:00:00&quot;,\n   \t\t\t&quot;deliveryOrder&quot;:&quot;ZT12345789d786&quot;,\n   \t\t\t&quot;isReturn&quot;:1,\n   \t\t\t&quot;returnId&quot;:&quot;2020122600012&quot;,\n               &quot;returnNumber&quot;:2,\t\n           },\n   \t\t {\n               &quot;orderId&quot;:&quot;202012200001&quot;,\n               &quot;goodsId&quot;:&quot;2001&quot;,\n               &quot;goodsName&quot;:&quot;梨子#2001&quot;,\n               &quot;unit&quot;:&quot;件&quot;,\n               &quot;specific&quot;:&quot;6斤一箱&quot;,\n               &quot;linePrice&quot;:150,\n               &quot;salePrice&quot;:120,\n               &quot;costPrice&quot;:90,\n               &quot;number&quot;:20,\n   \t\t\t&quot;isVoucher&quot;:1,\n   \t\t\t&quot;voucherPrice&quot;:3,\n   \t\t\t&quot;voucherId&quot;:&quot;3dr55678hj&quot;,\n   \t\t\t&quot;isDiscount&quot;:1,\n   \t\t\t&quot;discountPrice&quot;:5,\n   \t\t\t&quot;carriage&quot;: 0,\n   \t\t\t&quot;receiver&quot;:&quot;susu&quot;,\n   \t\t\t&quot;phone&quot;:&quot;18633567898&quot;,\n   \t\t\t&quot;address&quot;:&quot;深圳市南山区腾讯大厦20楼&quot;,\n   \t\t\t&quot;createTime&quot;:&quot;2020-12-20 10:00:00&quot;,\n   \t\t\t&quot;payTime&quot;:&quot;2020-12-20 11:00:00&quot;,\n   \t\t\t&quot;payMethod&quot;:1, \n   \t\t\t&quot;payOrder&quot;:&quot;202012201100003940&quot;,\n   \t\t\t&quot;orderStatus&quot;:3,\n   \t\t\t&quot;deliveryTime&quot;:&quot;2020-12-21 11:00:00&quot;,\n   \t\t\t&quot;finishTime&quot;:&quot;2020-12-25 11:00:00&quot;,\n   \t\t\t&quot;deliveryOrder&quot;:&quot;ZT12345789d786&quot;,\n   \t\t\t&quot;isReturn&quot;:0,\n   \t\t\t&quot;returnId&quot;:&quot;&quot;,\n               &quot;returnNumber&quot;:0,\t\t\n           },\n   \t\t{\n               &quot;orderId&quot;:&quot;202012200001&quot;,\n               &quot;goodsId&quot;:&quot;3005&quot;,\n               &quot;goodsName&quot;:&quot;香蕉#3005&quot;,\n               &quot;unit&quot;:&quot;件&quot;,\n               &quot;specific&quot;:&quot;10斤一箱&quot;,\n               &quot;linePrice&quot;:180,\n               &quot;salePrice&quot;:150,\n               &quot;costPrice&quot;:98,\n               &quot;number&quot;:6,\n   \t\t\t&quot;isVoucher&quot;:1,\n   \t\t\t&quot;voucherPrice&quot;:8,\n   \t\t\t&quot;voucherId&quot;:&quot;3dr55678hj&quot;,\n   \t\t\t&quot;isDiscount&quot;:1,\n   \t\t\t&quot;discountPrice&quot;:20,\n   \t\t\t&quot;carriage&quot;: 0,\n   \t\t\t&quot;receiver&quot;:&quot;susu&quot;,\n   \t\t\t&quot;phone&quot;:&quot;18633567898&quot;,\n   \t\t\t&quot;address&quot;:&quot;深圳市南山区腾讯大厦20楼&quot;,\n   \t\t\t&quot;createTime&quot;:&quot;2020-12-20 10:00:00&quot;,\n   \t\t\t&quot;payTime&quot;:&quot;2020-12-20 11:00:00&quot;,\n   \t\t\t&quot;payMethod&quot;:1, \n   \t\t\t&quot;payOrder&quot;:&quot;202012201100003940&quot;,\n   \t\t\t&quot;orderStatus&quot;:3,\n   \t\t\t&quot;deliveryTime&quot;:&quot;2020-12-21 11:00:00&quot;,\n   \t\t\t&quot;finishTime&quot;:&quot;2020-12-25 11:00:00&quot;,\n   \t\t\t&quot;deliveryOrder&quot;:&quot;ZT12345789d786&quot;,\n   \t\t\t&quot;isReturn&quot;:1,\n   \t\t\t&quot;returnId&quot;:&quot;2020122600013&quot;,\n               &quot;returnNumber&quot;:3,\t\t\n           }\n       ];\n       \n       return {&quot;orderList&quot;:orderlist};\n   };</code></pre></div>\n<ol start=\"5\">\n<li>单击【保存】，则成功创建了云函数</li>\n</ol>\n<h4 id=\"创建-processorder-函数\"><a href=\"#%E5%88%9B%E5%BB%BA-processorder-%E5%87%BD%E6%95%B0\" aria-label=\"创建 processorder 函数 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>创建 ProcessOrder 函数</h4>\n<p>参考【创建 GetOrder 函数】的方式，创建 ProcessOrder 函数，代码如下：</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&#39;use strict&#39;;\nexports.main_handler = async (event, context) =&gt; {\n    console.log(&quot;this is processOrder function&quot;);\n    var order = event;\n    #数据处理\n    var income = order[&quot;salePrice&quot;]-order[&quot;costPrice&quot;];\n    var goodsInfo = {&quot;goodsId&quot;:order[&quot;goodId&quot;],&quot;goodsName&quot;:order[&quot;goodsName&quot;],&quot;number&quot;:order[&quot;number&quot;]};\n    var incomeInfo = {&quot;goodsId&quot;:order[&quot;goodId&quot;],&quot;goodsName&quot;:order[&quot;goodsName&quot;],&quot;number&quot;:order[&quot;number&quot;],&quot;income&quot;:income};\n   return {\n        &quot;goodsInfo&quot;:goodsInfo,\n        &quot;incomeInfo&quot;:incomeInfo,\n        &quot;salesInfo&quot;:salesInfo\n    };\n}</code></pre></div>\n<h4 id=\"创建-goodssold-函数\"><a href=\"#%E5%88%9B%E5%BB%BA-goodssold-%E5%87%BD%E6%95%B0\" aria-label=\"创建 goodssold 函数 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>创建 GoodsSold 函数</h4>\n<p>参考【创建 GetOrder 函数】的方式，创建 GoodsSold 函数，代码如下：</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&#39;use strict&#39;;\nexports.main_handler = async (event, context) =&gt; {\n    console.log(&quot;this is goodsSold function&quot;);\n    //一些写入数据库或者图表展示操作\n    console.log(event);\n    return &quot;GoodsSold success&quot;;\n};</code></pre></div>\n<h4 id=\"创建-income-函数\"><a href=\"#%E5%88%9B%E5%BB%BA-income-%E5%87%BD%E6%95%B0\" aria-label=\"创建 income 函数 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>创建 Income 函数</h4>\n<p>参考【创建 GetOrder 函数】的方式，创建 Income 函数，代码如下：</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&#39;use strict&#39;;\nexports.main_handler = async (event, context) =&gt; {\n    console.log(&quot;this is income function&quot;);\n    //一些写入数据库或者图表展示操作\n    console.log(event);\n    return &quot;Income success&quot;;\n};</code></pre></div>\n<h4 id=\"创建-salesreturn-函数\"><a href=\"#%E5%88%9B%E5%BB%BA-salesreturn-%E5%87%BD%E6%95%B0\" aria-label=\"创建 salesreturn 函数 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>创建 SalesReturn 函数</h4>\n<p>参考【创建 GetOrder 函数】的方式，创建 SalesReturn 函数，代码如下：</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&#39;use strict&#39;;\nexports.main_handler = async (event, context) =&gt; {\n    console.log(&quot;this is salesReturn function&quot;);\n    //一些写入数据库或者图表展示操作\n    console.log(event);\n    return &quot;SalesReturn success&quot;;\n};</code></pre></div>\n<h3 id=\"step-2：创建工作流\"><a href=\"#step-2%EF%BC%9A%E5%88%9B%E5%BB%BA%E5%B7%A5%E4%BD%9C%E6%B5%81\" aria-label=\"step 2：创建工作流 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Step 2：创建工作流</h3>\n<ol>\n<li>登录 <a href=\"https://console.cloud.tencent.com/asw\">应用与编排服务流控制台</a>。</li>\n<li>在状态机页面，单击【新建】，进入创建工作流页面中，选择使用【代码创建】：</li>\n</ol>\n<p><img src=\"https://main.qcloudimg.com/raw/d6f96a674e5f105e3c38ecaea01ebcf6.png\"></p>\n<ol start=\"3\">\n<li>直接在代码编辑框中粘贴以下 TCSL 代码：</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">   {\n     &quot;Comment&quot;: &quot;订单处理&quot;,\n     &quot;StartAt&quot;: &quot;GetOrder&quot;,\n     &quot;States&quot;: {\n       &quot;GetOrder&quot;: {\n         &quot;Type&quot;: &quot;Task&quot;,\n         &quot;Comment&quot;: &quot;拉取数据&quot;,\n         &quot;Resource&quot;: &quot;qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/GetOrder&quot;,\n         &quot;Next&quot;: &quot;MapProcess&quot;\n       },\n       &quot;MapProcess&quot;: {\n         &quot;Type&quot;: &quot;Map&quot;,\n         &quot;ItemsPath&quot;: &quot;$.orderList&quot;,\n         &quot;MaxConcurrency&quot;: 6,\n         &quot;Iterator&quot;: {\n           &quot;StartAt&quot;: &quot;ProcessOrder&quot;,\n           &quot;States&quot;: {\n             &quot;ProcessOrder&quot;: {\n               &quot;Type&quot;: &quot;Task&quot;,\n               &quot;Resource&quot;: &quot;qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/ProcessOrder&quot;,\n               &quot;Next&quot;: &quot;ParallelDataProcess&quot;\n             },\n             &quot;ParallelDataProcess&quot;: {\n               &quot;Type&quot;: &quot;Parallel&quot;,\n               &quot;End&quot;: true,\n               &quot;Branches&quot;: [\n                 {\n                   &quot;StartAt&quot;: &quot;GoodsSold&quot;,\n                   &quot;States&quot;: {\n                     &quot;GoodsSold&quot;: {\n                       &quot;InputPath&quot;: &quot;$.goodsInfo&quot;,\n                       &quot;Type&quot;: &quot;Task&quot;,\n                       &quot;Resource&quot;: &quot;qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/GoodsSold&quot;,\n                       &quot;End&quot;: true\n                     }\n                   }\n                 },\n                 {\n                   &quot;StartAt&quot;: &quot;Income&quot;,\n                   &quot;States&quot;: {\n                     &quot;Income&quot;: {\n                       &quot;InputPath&quot;: &quot;$.incomeInfo&quot;,\n                       &quot;Type&quot;: &quot;Task&quot;,\n                       &quot;Resource&quot;: &quot;qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/Income&quot;,\n                       &quot;End&quot;: true\n                     }\n                   }\n                 },\n                 {\n                   &quot;StartAt&quot;: &quot;SalesReturn&quot;,\n                   &quot;States&quot;: {\n                     &quot;SalesReturn&quot;: {\n                       &quot;InputPath&quot;: &quot;$.salesInfo&quot;,\n                       &quot;Type&quot;: &quot;Task&quot;,\n                       &quot;Resource&quot;: &quot;qrn:qcs:asw:ap-guangzhou:12345678:sdk:json:qcloud:scf:Invoke/SalesReturn&quot;,\n                       &quot;End&quot;: true\n                     }\n                   }\n                 }\n               ]\n             }\n           }\n         },\n         &quot;End&quot;: true\n       }\n     }\n   }</code></pre></div>\n<ol start=\"4\">\n<li>单击右上角【下一步】，进入保存界面，输入状态机名称，运行角色选择【新建角色】，类型选择【标准状态机】，单击右上角【完成】，在状态机列表页可以看到创建好的状态机。</li>\n</ol>\n<p><img src=\"https://main.qcloudimg.com/raw/3178bc63ffb10fabf85f2fe35506acf1.png\"></p>\n<blockquote>\n<p>使用已有角色需要先创建角色，并给角色授权相关策略，操作详情参考 <a href=\"https://cloud.tencent.com/document/product/1272/52420\">运行角色</a>。</p>\n</blockquote>\n<h3 id=\"step-3：运行状态机\"><a href=\"#step-3%EF%BC%9A%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81%E6%9C%BA\" aria-label=\"step 3：运行状态机 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Step 3：运行状态机</h3>\n<p>状态机创建完成后，您可以在登录后的主页面查看创建好的状态机。</p>\n<ol>\n<li>单击需要运行的状态机的【名称】，进入状态机。</li>\n</ol>\n<p><img src=\"https://main.qcloudimg.com/raw/7f883e833a57b7a64cb47f222448d3b7.png\"></p>\n<ol start=\"2\">\n<li>您可以在界面中看到状态机的基本信息。单击【工作流执行】下的【开始执行】 。</li>\n</ol>\n<p><img src=\"https://main.qcloudimg.com/raw/66c0b73cd16ef3717001a4d08e313a5d.png\"></p>\n<ol start=\"3\">\n<li>在弹出的“输入”窗口中，以 JSON 格式输入状态机需要的输入内容。例如：</li>\n</ol>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"85499005528504160000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"代码复制成功\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`{&quot;comment&quot;: &quot;invoke workflow&quot;}`, `85499005528504160000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                复制代码<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span><span class=\"token property\">\"comment\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"invoke workflow\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<ol start=\"4\">\n<li>单击【确定】，完成状态执行后，可以在详情页查看执行结果：</li>\n</ol>\n<p><img src=\"https://main.qcloudimg.com/raw/8fa4fb697ca6f31a97d2bebbb725acf4.png\"></p>\n<ol start=\"5\">\n<li>滑动至页面最下方，在【执行历史记录】条目下，您可以查看子节点的运行情况。</li>\n</ol>\n<p>上述步骤介绍了一个订单数据处理场景的基本工作流流程。</p>\n<p>真实的业务场景中每个 Task 节点会涉及配置一些相关参数信息，例如做参数传递、异常重试和错误捕获处理等，更多详情参考 <a href=\"https://cloud.tencent.com/document/product/1272/51544\">状态机语言</a>。</p>\n<h2 id=\"申请试用-asw\"><a href=\"#%E7%94%B3%E8%AF%B7%E8%AF%95%E7%94%A8-asw\" aria-label=\"申请试用 asw permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>申请试用 ASW</h2>\n<p>ASW 目前处于公测阶段，公测阶段免费提供服务。欢迎提出产品改进建议，反馈采纳后即可获得腾讯萌新短鹅公仔！</p>\n<p><img src=\"https://main.qcloudimg.com/raw/7453713b86498abeed1cf9c0e47a5c9d.jpg\"></p>\n<p><img src=\"https://main.qcloudimg.com/raw/4e2a7cb9af30ecb288eb636ae2d19a39.png\" alt=\"反馈入口\"></p>\n<p>立即<a href=\"https://cloud.tencent.com/product/asw?ADTAG=outer.zhihu\">申请公测</a>，我们将会在 3 个工作日内完成审批，并通过短信和站内信通知您，感谢您的支持。</p>\n<hr>\n<blockquote>\n<p><strong>传送门：</strong></p>\n<ul>\n<li>GitHub: <a href=\"https://github.com/serverless/serverless/blob/master/README_CN.md\">github.com/serverless</a></li>\n<li>官网：<a href=\"https://serverless.com/\">serverless.com</a></li>\n</ul>\n</blockquote>\n<p>欢迎访问：<a href=\"https://serverlesscloud.cn/\">Serverless 中文网</a>，您可以在 <a href=\"https://serverlesscloud.cn/best-practice\">最佳实践</a> 里体验更多关于 Serverless 应用的开发！</p>","tableOfContents":"<ul>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86\">工作原理</a></li>\n<li>\n<p><a href=\"/best-practice/2021-01-28-asw-order/#%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4\">操作步骤</a></p>\n<ul>\n<li>\n<p><a href=\"/best-practice/2021-01-28-asw-order/#step-1%EF%BC%9A%E5%88%9B%E5%BB%BA%E4%BA%91%E5%87%BD%E6%95%B0\">Step 1：创建云函数</a></p>\n<ul>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#%E5%88%9B%E5%BB%BA-getorder-%E5%87%BD%E6%95%B0\">创建 GetOrder 函数</a></li>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#%E5%88%9B%E5%BB%BA-processorder-%E5%87%BD%E6%95%B0\">创建 ProcessOrder 函数</a></li>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#%E5%88%9B%E5%BB%BA-goodssold-%E5%87%BD%E6%95%B0\">创建 GoodsSold 函数</a></li>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#%E5%88%9B%E5%BB%BA-income-%E5%87%BD%E6%95%B0\">创建 Income 函数</a></li>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#%E5%88%9B%E5%BB%BA-salesreturn-%E5%87%BD%E6%95%B0\">创建 SalesReturn 函数</a></li>\n</ul>\n</li>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#step-2%EF%BC%9A%E5%88%9B%E5%BB%BA%E5%B7%A5%E4%BD%9C%E6%B5%81\">Step 2：创建工作流</a></li>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#step-3%EF%BC%9A%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81%E6%9C%BA\">Step 3：运行状态机</a></li>\n</ul>\n</li>\n<li><a href=\"/best-practice/2021-01-28-asw-order/#%E7%94%B3%E8%AF%B7%E8%AF%95%E7%94%A8-asw\">申请试用 ASW</a></li>\n</ul>"},"previousBlog":{"id":"c8f89c32-4c6b-51ea-bdca-cb1e94da9320","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/a55d114094dc0d965c1dcaa4f70787fb.jpg","authors":["April"],"categories":["best-practice"],"date":"2021-01-29T00:00:00.000Z","title":"使用 Serverless Wordpress 快速建站，只需三步","description":"首次部署可免费领取 35 元资源代金券！","authorslink":null,"translators":null,"translatorslink":null,"tags":["Serverless","WordPress"],"keywords":null,"outdated":null},"wordCount":{"words":226,"sentences":37,"paragraphs":37},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2021-01-29-sf-wordpress.md","fields":{"slug":"/best-practice/2021-01-29-sf-wordpress/","keywords":["serverless","云函数","Serverless","Wordpress","serverless","部署","tencent","存储"]}},"nextBlog":{"id":"9a17f860-11aa-5369-9940-3b91f3346e89","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/06f91ce743d71fce098149bc5c4c5d7b.jpg","authors":["吴宜展"],"categories":["best-practice"],"date":"2021-01-26T00:00:00.000Z","title":"Serverless 文件上传优化","description":"Base64 编码功能，支持全部触发和 Header 触发以满足不同场景的要求。","authorslink":null,"translators":null,"translatorslink":null,"tags":["Serverless","API 网关"],"keywords":null,"outdated":null},"wordCount":{"words":260,"sentences":41,"paragraphs":41},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2021-01-26-base-64.md","fields":{"slug":"/best-practice/2021-01-26-base-64/","keywords":["serverless","website","云函数","上传","触发","单击","文件","编码"]}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"blogId":"c21445e2-63c7-51ea-96b7-33274e34af3f","previousBlogId":"c8f89c32-4c6b-51ea-bdca-cb1e94da9320","nextBlogId":"9a17f860-11aa-5369-9940-3b91f3346e89"}}}