It's reading notes time! It is a habit I started a long time ago, close to 600 weeks ago in fact, where I share a list of all the articles, blog posts, and books that catch my interest during the week.
If you think you may have interesting content, share it!
Is Your Container Image Really Distroless? (Laurent Goderre) - Nice post that explains a new way to improve security and more while building our container by going distroless.
Azure PowerShell Tips and Tricks (Paul Harrison) - PowerShell is a very interesting and useful script language.All those tips are pure wisdom!
DevOps
Beautiful .NET Test Reports Using GitHub Actions (Sean Killeen) - It's true that the unit test result in Azure DevOps looks amazing. Pretty nice adaptation in GitHub Action, could/ should it be native?
An Introduction to Azure Functions (Matt Soucoup ) - If you are looking to get started on Azure function or looking for the Microsoft serverless offer, this post is definitely a good place to start.
Developing bots for Hangouts Chat (Wesley Chun) - If you are using GSuite and still not leveraging bots... This post is a nice starting point to get inspired.
I love Azure functions; I think they are very useful in many scenarios. I use them very often when I want to extend some functionality of on existing systems, to avoid having to open the Pandora box (aka. code). Recently, I was involved on a project where we used the Azure Functions as a schedule task to process (and generate) a lot of data into a database. We used VSTS to deploy the solution in a staging slot, and everything was really great. If you are interested to learn more about it, see my previous post. In fact, it was working so well that the Azure Function was running and doing it's job even while in staging slots...
In this quick post, I will share two options to prevent an Azure Function of running while in Stagging slot.
Option 1: Kudu to the rescue
If you have created a few functions, you probably already know that you have access to some Environment variables. They are very useful. I was pretty sure one exists specifying the current slot, but I didn't know the name of it. Even more, I forgot that all environment variables are displayed in the Kudu interface. D'oh! Thanks to Bruce Chen, that answered my question on StackoverFlow and help me to remember it was all there.
To get to your environment variables list, go in portal.azure.com. Open your Azure function and select the main note (1). The from the right section select the Platform features tab. Then finaly, in the Development Tools section select the Advanced tools (Kudu).
That will open the Kudu interface in a new tab. You just need to select the Environment tab and you will see them!
Now one more thing before we are reading to go. At the time, this post is published, Function slots are still in preview so don't forget to activate it ;)
Let's create a simple Azure Function to show how it works.
using System;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info($"JustDemoFunc got triggered at: {DateTime.Now}");
var slotName = System.Environment.GetEnvironmentVariable("APPSETTING_WEBSITE_SLOT_NAME", EnvironmentVariableTarget.Process);
if (!string.Equals("production", slotName , StringComparison.OrdinalIgnoreCase))
{
log.Info($"{DateTime.Now:s} Function is in stagging.");
return;
}
log.Info($"{DateTime.Now:s} Function is in Production is will be executed.");
}
This is a C# timer function. Every time it will be executed (every 5 minutes) it will write to log that it got triggered. Than with System.Environment.GetEnvironmentVariable("APPSETTING_WEBSITE_SLOT_NAME", EnvironmentVariableTarget.Process) it's grabbing our slot name. By default the name is Production so if it's something else... we get out. See the log when in production slot.
JustDemoFunc got triggered at: 9/24/2017 3:28:16 PM
2017-09-24T15:28:16 Function is in Production is will be executed.
Function completed (Success, Id=###, Duration=21ms)
And now the same code, but running in another slot, in this case named Stagging.
JustDemoFunc got triggered at: 9/24/2017 3:25:29 PM
2017-09-24T15:25:29 Function is in stagging.
Function completed (Success, Id=###, Duration=161ms)
Option 2: Sticky Setting it is
Another option is also possible using Application Settings. For that, simply add a new Setting, in this case named: ShouldItRun. Now let's jump into the code.
using System;
using System.Configuration;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info($"JustDemoFunc got triggered at: {DateTime.Now}");
if (!Convert.ToBoolean(ConfigurationManager.AppSettings["ShouldItRun"]))
{
log.Info($"{DateTime.Now:s} Function is in stagging.");
return;
}
log.Info($"{DateTime.Now:s} Function is in Production is will be executed.");
}
To be able to read your application setting you will need using System.Configuration. Then a quick call to ConfigurationManager.AppSettings["ShouldItRun"] will return the value of your setting. Once again, see the log from the production slot.
JustDemoFunc got triggered at: 9/24/2017 4:03:43 PM
2017-09-24T16:03:43 Function is in Production is will be executed.
Function completed (Success, Id=###, Duration=30ms)
And in the staging slot.
JustDemoFunc got triggered at: 9/24/2017 4:02:21 PM
2017-09-24T16:02:21 Function is in stagging.
Function completed (Success, Id=###, Duration=8ms)
.NET Rocks! Azure Event Grid with Dan Rosanova (Carl Franklin, Richard Campbell) - I really liked that episode with Dan. It was nice listening to him talking an making reference to Biztalk and Logic App.
OpenAPI is not what I thought (Darrel Miller ) - I hear you my friend, loud and clear. Let's use OpenAPI the way it should be. Very interesting post for an inside man sharing his thoughts about the purpose of the tool.
#222: Patrick Lencioni—Getting Hiring Right (EntreLeadership Team) - It was my first episode of this podcast, but definitely not the last one. Very interesting speakers... nice books referenced... loved it.
Why Your Boss Makes You Punch a Time Clock (Suzanne Lucas Suzanne Lucas is a freelance writer who spent 10 years in corporate human resources, where she hired, fired, managed the numbers, and double-checked with t) - Most of us have to do timesheets... I'm sure that at one point, you asked yourself the reason about it. It's time read an answer, in this post.
Making the Complex Simple - Not sure how to "classify" this post, is it a top list of the best bad practices, or literally "du bonbon"? A post to read, and relax.
C# Tips By Jason Roberts Publisher: Leanpub Released: December 2014
This book it undoubtedly for people who already know C#. If you want to learn C# by doing the best practices, I would strongly suggest to start with something else. However, if you already know how to code, and you want to improve your, or got this little plus; this book is a must.
It’s not a very big book, but all the zones are covered. It’s split into three parts. The first one will provides many good this to improve the performance of your code, customizes your debug experience, and more. The second part will focus on the very useful design patterns that we should all have in our back pocket. Finally, the third and last section introduces tools and frameworks (NUnits, Moq, etc.) to facilitate your work.
I would definitely recommend this book to any developer. The book is available in all the digital format for free, but if you like it consider giving a donation. :)
Miscellaneous
Finding an Invisible NAS on a Network (Alexandre Brisebois) - I like those stories where people, like us, learn something the “hard way” , and share their fresh experience.
Build End-to-End Apps with TypeScript (Gil Fink) - Amazing tutorial that gives the opportunity to learn a lot about recent language and tools. A mandatory reading for all web developers.
Is Your Application Built for the Cloud? - Interesting questioning about when to know if our application is built for the cloud, and nice list of pattern that are really well compatible with cloud solutions.