Microsoft DevOps & Azure Functions: Implement recu

2019-08-28 05:35发布

问题:

I have a task to implement an Azure Function which is triggered by an HTTP-Webhook defined in Microsoft DevOps (VSTS).

The idea is as follows:

  • We have a backlog-structure (let's say: Epic > Feature > User Story > Task)
  • If i set the state of any of those items to 'Done', all underlying items should also change to 'Done'

What i have done so far

  • I have enabled a webhook in DevOps which triggers on update of any workitem and sends this item as JSON to an Azure Function
  • I have written the Azure Function which is invoked by an HTTP-request and get's the URL of the item which has triggered the request
    • The function then gets all items which are a child of the first workitem
    • The function patches all found child items with the state of the first item
    • All direct children are updated on DevOps

What i need
I'm trying to figure out an option to enable recursive update. Not only direct children should be updated, but also all their children (if they have some) and so on. I thought about the following ways to accomplish this and need your guidance:

  • Get all direct children as JSON and then send HTTP-request's to the same function, passing all child item's

  • call the function within the function (don't even know if this works) and pass the children as JSON

  • find a way to handle all the logic in this single function (dumb foreach-nesting to ensure all backlog-hierarchy levels are processed)

If any code snippets are needed just tell me and i will provide the requested parts (right now i'm quite unsure what part of my code i should publish and would be helpful)

回答1:

From your list of approaches:

  • Get all direct children as JSON and then send HTTP-request's to the same function, passing all child item's
    [Please see Fan-Out/Fan-In scenarios in Durable functions. This will achieve what you are looking for]

  • call the function within the function (don't even know if this works) and pass the children as JSON
    [This is not recommended. Please see here for best practices]

  • find a way to handle all the logic in this single function (dumb
    foreach-nesting to ensure all backlog-hierarchy levels are processed) [Same here. This is not recommended. In general it best practice to avoid long running functions]