Saturday, April 9, 2016

Azure Logic App to send email if other cloud app stops running

I created an Azure Logic App today that runs once per day and does the following:
  1. Call a stored procedure in an Azure SQL database. The stored procedure returns the number of hours since an application last ran to completion.
  2. If the return code from the stored procedure is greater than 6, send an email (using Office 365) to me.


If I were to create an app for this (e.g., a WebJob), I'd have to add in the SQL connectivity plumbing (or use Entity Framework) and add code to send an email. That's still an easy application to write and deploy in Azure, but being able to put together a small app (workflow) like this in just a few minutes is pretty great.

As of this post, Logic Apps is still in Preview, so it has lots of issues that the team will work out. One problem I ran into was trying to use the SQL connector's OutputParameters return object in a Logic Apps Condition step. I wanted to know if the OutputParameters value was greater than 6. When running the app, I ran into the following error:

{"code":"InvalidTemplate","message":"Unable to process template language expressions for action 'Send_Email' at line '1' and column '11': 'The template language function 'greater' expects exactly two parameter of matching types. The function was invoked with values of type 'Object' and 'Integer' that do not match.'."}

I then went into the "Code View" and wrapped the condition expression with an int() function call, but then the Logic App threw this error:

{"code":"InvalidTemplate","message":"Unable to process template language expressions for action 'Send_Email' at line '1' and column '11': 'The template language function 'int' was invoked with an invalid parameter. The value cannot be converted to the target type.'."}

Finally, I tried using a ReturnCode value from the stored procedure (as shown in the screenshot) and that worked; I was able to compare the integer return value to a specified integer value.

Logic Apps still has a ways to go to be ready for prime time but in this case it worked out well for what I was trying to achieve. And it's one less Visual Studio project to maintain!