azureazure-logic-appsazure-storage-account

Updating azure Storage Account table through Logic Apps


I am currently creating a logic app, to handle some emails. The logic is simple, when i receive a mail of a certain type, the mail gets send to another address. Every mail of that type received in the next 30 minutes then get ignored.

In my storage account, i have a table with boolean property 'isCooldown'. So when the first mail is received, it is sent to another address. isCooldown is then set to true, so the next emails that triggers the app, doesn't get forwarded.

My problem is updating the table. My first workflow went: Forward email -> Get entity (v2) -> get etag (compose) -> replace entity (Update isCoolDown) -> delay -> get entity (v2) -> get etag -> replace entity (Update isCoolDown to false).

This works, but causes problem when multiple instances of the app is running. I think it is due to the etag. When on instance retrieves the etag, another instance has replaced the entity and etag, so the old etag doesn't work, and the replace entity then fails.

I have tried the 'update table' action, which is a part of the In-App Azure table storage. Not sure why there is two action types of 'Azure Table Storage'. But Update Entity fails entirely. For connection string, i have tried storage account -> security + network -> Access keys -> connection string. I have also tried choosing Managed Indentity as Authentication type, and then for Table Storage Endpoint i picked storage account -> settings -> endpoints -> primary endpoint/table service. When using connection string it fails with error: WorkflowAppOAuthTokenFailure. When using Table Storage Endpoint i get MethodNotAllowed.

Any suggestions what causes these errors, and how i can update my table properly, preferably without using etags?


Solution

  • The usage of ETag ensures data consistency but can conflict with your multi-instance logic app.

    Instead of "Replace Entity", use the "Merge Entity" action. The Merge Entity operation updates only the specified properties and does not require you to specify the ETag.

    Option 2 would be InsertOrMerge Operation. If your logic app is configured to work with HTTP-based connectors, you can use an HTTP action to perform an InsertOrMerge operation, which updates the entity if it exists or creates it otherwise.

    So the workflow would be:

    1. Trigger: When a new email is received.
    2. Check Cooldown: Query the table to check isCooldown. If isCooldown is true, terminate the flow.
    3. Update Cooldown to true: Use Merge Entity or InsertOrMerge to set isCooldown to true.
    4. Forward Email.
    5. Delay for 30 minutes.
    6. Update Cooldown to false: Use Merge Entity or InsertOrMerge to reset isCooldown.