Souvik Ghosh
Souvik Ghosh

Reputation: 4616

Scheduled task in Azure

I am using Azure Cosmos DB. I have some collections as shown in snapshot below-

enter image description here

Now, I want to create a scheduled task which will retrieve all the data from collection- "CurrentDay" and do some calculation and store the value in another collection- "datewise". Similarly, I will need to retrieve all the data from collection- "datewise" and based one some calculation store the data in "monthwise" and then to "yearly".

I looked for some option in Scheduler in Azure portal and tried creating a scheduler but it seems I don't have sufficient permission license to use that feature. Basically I haven't used that so I am not sure it will work.

Had it been in SQL Server I could have done that using custom code in C#. The only option I currently have is to use REST API calls to fetch data, calculate in C# and Post it back to Azure Cosmos DB. Is there any better way of doing this?

Please let me know if I can provide any details.

Upvotes: 0

Views: 645

Answers (2)

Rob Reagan
Rob Reagan

Reputation: 7686

I'd encapsulate your logic in an Azure WebJob method, and mark the method with a TimerTrigger. The TimerTrigger will call your given method on the schedule that you specify. This has a few less moving parts. If you were to go the scheduler route, you're still going to have to have the scheduler call some endpoint in order to perform the work. Packaging up your logic and schedule in a WebJob will simplify things a bit.

On a side note, if all data lived in the same collection, I'd suggest writing a stored procedure to perform these calculations. But alas, stored procedures in Cosmos are bounded at the collection level.

Upvotes: 1

Adam Brown
Adam Brown

Reputation: 1729

I think using a scheduled task (on Azure) and getting the data via the REST API is probably what you want to do. There are several reasons why this isn't as bad as you might think:

  1. Your server and your database are right next to each other in the data centre, so you don't need to pay for data transfer.

  2. Latency is very low and bandwidth is very high, so you'll be limited by the database performance more than anything else (you can run parallel tasks in your scheduled task to make sure of this).

  3. The REST API has a very well supported official C# client library.

Of course it depends on the scale of data we're talking about as to how you should provision your scheduled task.

Upvotes: 1

Related Questions