<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CRON Expressions &#8211; Sibeesh Passion</title>
	<atom:link href="https://mail.sibeeshpassion.com/tag/cron-expressions/feed/" rel="self" type="application/rss+xml" />
	<link>https://mail.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 17 Jul 2019 17:42:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>CRON Expressions &#8211; Sibeesh Passion</title>
	<link>https://mail.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>TimerTrigger Azure Function to Upload to Azure Blob Daily</title>
		<link>https://mail.sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/</link>
					<comments>https://mail.sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 17 Jul 2019 17:36:35 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Blob]]></category>
		<category><![CDATA[Azure Blobs]]></category>
		<category><![CDATA[Azure Function]]></category>
		<category><![CDATA[Azure Function and Azure Storage Blob]]></category>
		<category><![CDATA[Azure Storage]]></category>
		<category><![CDATA[CRON Expressions]]></category>
		<category><![CDATA[Time Trigger Azure Function]]></category>
		<category><![CDATA[Upload to Azure Blob]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=13840</guid>

					<description><![CDATA[[toc] Introduction Working with Azure Function is always fun and with the help of other Azure Services, it gets even better. Here in this article, we are going to see how we can use the TimerTrigger of Azure Function to upload some file to the Azure Blob storage daily. The basic idea is to have job running every data at a specific time to perform the upload. I believe, this is enough for the introduction, let us start implementing them. Background If you are new to Azure Functions, I recommend you to read some related articles from here. The possibilities [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>Working with Azure Function is always fun and with the help of other Azure Services, it gets even better. Here in this article, we are going to see how we can use the TimerTrigger of Azure Function to upload some file to the Azure Blob storage daily. The basic idea is to have job running every data at a specific time to perform the upload. I believe, this is enough for the introduction, let us start implementing them.</p>



<h2 class="wp-block-heading">Background</h2>



<p>If you are new to Azure Functions, I recommend you to read some related articles from <a href="https://sibeeshpassion.com/tag/azure-function/"><em>here</em></a>. The possibilities that you can do with Azure Function is countless, and here we are going to discuss one of them. We live in a world everything is automated, nobody is interested in doing any manual works. Writing an automated Job which runs everyday at a given time is never been easier with the help of Azure Function. </p>



<h2 class="wp-block-heading">Prerequisites</h2>



<ul class="wp-block-list"><li>You should have a valid Azure Subscription </li><li>You should have a running Azure Function</li><li>If you are not sure about how to create an Azure Function App, <a href="https://sibeeshpassion.com/iothubtrigger-azure-function-and-azure-iot-hub/#creating-an-azure-function-app"><em>this post</em></a> may help you.</li><li>You should have a valid Azure Storage Account</li></ul>



<h2 class="wp-block-heading">Azure Function and Azure Blob</h2>



<h3 class="wp-block-heading">Get the Storage Connection String</h3>



<p>By default a new key with the name AzureWebJobsStorage will be created when you create an Azure Function in your Visual Studio Azure Function App. If it doesn&#8217;t you should create this in your local.settings.json file by getting the connection string from your storage account. </p>



<p>To get the connection string, go to your storage account and click on Access Keys under Settings blade. And then copy any one of the connection string listed. You can use this value to create the AzureWebJobsStorage key under Values in the local.settings.json file. You should also create this in the Azure Function configuration in the Azure Portal, as this local.settings.json file is just for local and it will not be pushed to the Azure Function when you publish your Functions.</p>



<h3 class="wp-block-heading">Creating an Azure Function in Function App</h3>



<p>To create a new Azure Function in the Azure Function App, right click on your project and then click on <strong>Add</strong> and then select <strong>New Azure Function</strong>. In the coming pop up you should be given an option to name your Azure Function. Once that is done you can choose what trigger you want to use, in this case I will select <strong>TimeTrigger</strong>. </p>



<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="649" height="422" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Creating-Time-Trigger-Azure-Function.png" alt="" class="wp-image-13841" srcset="/wp-content/uploads/2019/07/Creating-Time-Trigger-Azure-Function.png 649w, /wp-content/uploads/2019/07/Creating-Time-Trigger-Azure-Function-300x195.png 300w, /wp-content/uploads/2019/07/Creating-Time-Trigger-Azure-Function-425x276.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>Azure Function with Time Trigger</figcaption></figure>



<p>Once you click on Ok, a new Function will be created for you with the time interval of 5 minutes. The Time Trigger Function uses NCronTab library to intercept the CRON expression. This is the expression that you see under the Schedule option on the above image. A usual CRON express has the below fields in it.</p>



<script src="https://gist.github.com/SibeeshVenu/7ed2aec377fe6750e9ba6239039399f2.js"></script>



<p>If you see the code you can see that a function Run is been created for you, with the time interval you had set.</p>



<script src="https://gist.github.com/SibeeshVenu/197d93ab68a634528ec81cc96bba5911.js"></script>



<p>Now we can say our Azure Function to run everyday at 9.45 AM by changing the CRON expression.</p>



<script src="https://gist.github.com/SibeeshVenu/f2fab09a36ac46c430759ee332fed5ae.js"></script>



<p>You can learn more about the CRON expressions <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer#cron-expressions">here</a>.</p>



<h3 class="wp-block-heading">Upload the Data to Azure Blob</h3>



<p>Now that we have our Azure Function ready to be run everyday as we wanted. It is time to write some code to generate the data and upload it to the blob. Before we do that we should make sure that we have installed the required Nuget package Microsoft.Azure.Storage.Blob.</p>



<figure class="wp-block-image"><img decoding="async" width="493" height="161" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Install-Microsoft.Azure_.Storage.Blob_.png" alt="" class="wp-image-13843" srcset="/wp-content/uploads/2019/07/Install-Microsoft.Azure_.Storage.Blob_.png 493w, /wp-content/uploads/2019/07/Install-Microsoft.Azure_.Storage.Blob_-300x98.png 300w, /wp-content/uploads/2019/07/Install-Microsoft.Azure_.Storage.Blob_-425x139.png 425w" sizes="(max-width: 493px) 100vw, 493px" /><figcaption> Install Microsoft.Azure.Storage.Blob </figcaption></figure>



<p>Now we can rewrite the complete Function code as below.</p>



<script src="https://gist.github.com/SibeeshVenu/d197438dbe31e7f54e3a2907ecf9afe0.js"></script>



<p>As you can see that, I am creating an instance of CloudStorageAccount and then create a blob client by calling the function CreateCloudBlobClient(). Once we get that, we get the blob container reference by using the function GetContainerReference() and then get the block blob and finally call the UploadFromStreamAsync() function to upload the stream data. </p>



<p>The line var stream = getTheImportedData.ConvertToStream(); is to get the stream data from an API, which returns a JSON and then I convert it to a stream by calling an extension method. </p>



<script src="https://gist.github.com/SibeeshVenu/68f9c7d76b2510b547d90508f276fa5f.js"></script>



<p>Here EnviornmentVariables.StorageConnectionString is part of a shared static class which returns the AzureWebJobsStorage we set in the local.settings.json file.</p>



<script src="https://gist.github.com/SibeeshVenu/f24829a6b62cf31399ea95ec15d70d2e.js"></script>



<h2 class="wp-block-heading">Output</h2>



<p>Now let us run our function in local and test. You should see an output as preceding.</p>



<figure class="wp-block-image"><img decoding="async" width="649" height="100" src="https://sibeeshpassion.com/wp-content/uploads/2019/07/Http-Trigger-Azure-Function-Output.png" alt="" class="wp-image-13844" srcset="/wp-content/uploads/2019/07/Http-Trigger-Azure-Function-Output.png 649w, /wp-content/uploads/2019/07/Http-Trigger-Azure-Function-Output-300x46.png 300w, /wp-content/uploads/2019/07/Http-Trigger-Azure-Function-Output-425x65.png 425w" sizes="(max-width: 649px) 100vw, 649px" /><figcaption>Time Trigger Azure Function Output</figcaption></figure>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Wow!. Now we have learned,</p>



<ul class="wp-block-list"><li>about Azure Function and setting up the same</li><li>about Time Trigger in Azure Function</li><li>about CRON expressions in Azure Function</li><li>how to upload data to Azure blob using Azure Function</li></ul>



<p>You can always ready my Azure articles&nbsp;<a href="https://sibeeshpassion.com/category/azure/">here</a>.</p>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post as useful? Kindly do not forget to share me your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mail.sibeeshpassion.com/timertrigger-azure-function-to-upload-to-azure-blob-daily/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
