使用API​​更新Azure Logic App的触发频率

时间:2017-06-07 09:26:18

标签: c# azure azure-logic-apps

我正在尝试使用Azure Logic SDK更新逻辑应用程序的重复频率和间隔,但是此错误消息失败

  

Microsoft.Rest.Azure.CloudException :不支持修补工作流程'kk-test-logic-app'的请求。   可以修补属性对象中的所有字段。

这是一段代码片段,展示了我要做的事情。

    var workflow = await _client.Value.Workflows.GetAsync(resourceGroupName, workflowName);

    dynamic workflowDefinition = workflow.Definition;
    workflowDefinition.triggers[triggerName]["recurrence"] = JToken.FromObject(new { frequency = triggerFrequency, interval = triggerInterval });

    await _client.Value.Workflows.UpdateAsync(resourceGroupName, workflowName, workflow);

其中_client为Lazy<LogicManagementClient>

以下是我尝试更新的触发器的定义(使用Fiddler):

  "triggers": {
    "When_a_new_email_arrives": {
      "recurrence": {
        "frequency": "Hour",
        "interval": 2
      },
      "splitOn": "@triggerBody()?.value",
      "type": "ApiConnection",
      "inputs": {
        "host": {
          "api": {
            "runtimeUrl": "https://logic-apis-southindia.azure-apim.net/apim/office365"
          },
          "connection": {
            "name": "@parameters('$connections')['office365']['connectionId']"
          }
        },
        "method": "get",
        "path": "/Mail/OnNewEmail",
        "queries": {
          "folderPath": "Inbox",
          "importance": "Any"
        }
      }
    }
  }

请注意,我能够成功检索工作流,workflowRuns,workflowTriggers等。只有更新操作失败。有关如何使用SDK更新工作流属性的任何想法?

更新 正如Amor-MSFT在下面的评论中所指出的,这是一个缺陷,作为一种解决方法,我目前正在使用CreateOrUpdateAsync而不是UpdateAsync。已在GitHub中创建new defect以引起SDK开发团队的注意。

1 个答案:

答案 0 :(得分:0)

  

触发器当前每30秒执行一次,检查是否从某个电子邮件地址收到了新邮件,并且是否按预期运行良好。我正在尝试使用我提供的代码将重复频率从30秒更改为2小时。

我创建了一个邮件触发器,如果​​我使用调用UpdateAsync方法,我可以重现该问题。根据Azure Logic C#SDK的source code,它根据响应消息发送不支持的PATCH请求。将HTTP方法更改为PUT后,我可以更新工作流程。这是我用来发送PUT请求的示例代码。

string triggerName = "When_a_new_email_arrives";
string resourceGroupName = "my resourcegroup name";
string workflowName = "my-LogicApp";
string subscriptionID = "my-subscriptionID";
var workflow = await _client.Workflows.GetAsync(resourceGroupName, workflowName);

string url = string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Logic/workflows/{2}?api-version=2016-06-01",
    subscriptionID, resourceGroupName, workflowName);
HttpClient client = new HttpClient();
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Put, url);
message.Headers.Add("Authorization", "Bearer put your token here");
message.Headers.Add("Accept", "application/json");
message.Headers.Add("Expect", "100-continue");

dynamic workflowDefinition = workflow.Definition;
workflowDefinition.triggers[triggerName]["recurrence"] = JToken.FromObject(new { frequency = "Minute", interval = 20 });

string s = workflow.ToString();
string workflowString = JsonConvert.SerializeObject(workflow, _client.SerializationSettings);

message.Content = new StringContent(workflowString, Encoding.UTF8, "application/json");
await client.SendAsync(message);