0

When a manager creates a task and sets the activation date in the future, it's supposed to be stored in the DB. No message is being dispatched out to the regarded workers, until a day or two before it's due. When the time's approaching, an email's being sent out to the subordinates.

Previously I've resolved that using a locally run Windows Service that scheduled the messaging. However, as I'm implementing something similar in the Azure, I'm not sure how to resolve it (other than actually hosting my own Windows Server in the cloud, of course, but kind of defeats the whole point).

Since my MVC application is strictly event driven, I've browsed around in the Azure portal to find a utility to schedule or postpone a method being invoked. No luck. So at the moment, all the emails are dispensed immediately and the scheduling is performed by keeping the message in the inbox until it's time (or manually setting up an appointment).

How should I approach the issue?

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438

3 Answers3

1

One solution to run background tasks is to use Web Jobs. Web Jobs can run on a schedule (let's say once per day), manually or triggered by a message in a queue.

CSharpRocks
  • 6,791
  • 1
  • 21
  • 27
  • You say **one solution**. Are there other (equivalently neat) approaches? Please take a peek at the comment to the other answer as well. – Konrad Viltersten Apr 17 '16 at 11:34
1

You can use Azure WebJobs. Basically, create a WebJob and schedule it to regularly check the data in your database for upcoming tasks and then notify people.

Mehmet Aras
  • 5,284
  • 1
  • 25
  • 32
  • That's new to me. Sounds interesting, though. So you're saying that you'd set up a web job that using JavaScript (which's one of the valid extensions according to the link of yours) that basically calls an action method (let's say *SendReminders*) every now and then? – Konrad Viltersten Apr 17 '16 at 11:33
  • You can do it that way depending on your existing logic or simply send reminders within that webjob as well. You can also do it differently perhaps with Azure Automation by writing a runbook that handles sending out reminders and then have a webhook that invokes the runbook. You still need something that periodically checks the upcoming tasks and invokes the webhook and that something can be a webjob too. There are different ways but I will go with webjobs. – Mehmet Aras Apr 17 '16 at 14:14
1

Other possible solution is to use Queueing mechanism. You can use Azure Storage Queues or Service Bus Queues.

The way it would work is when a task is created and saved in the database, you will write a message in a queue. This message will contain details about the task (may be a task id). However that message will be invisible by default and will only become visible after certain amount of time (you will calculate this period based on when you would need to send out the email). When the visibility timeout period expires, the message will become available to be consumed in the queue. Then you will have a WebJob with a Queue trigger (i.e. the WebJob will become alive when there's a message in the queue). In your WebJob code, you will fetch the task information from the database and send the notification to concerned person.

If you're using Azure Storage Queue, the property you would be interested in is InitialVisibilityTimeout. Please see this thread for more details: Azure storage queue message (show at specific time).

If you're using Azure Service Bus Queue, the property you would be interested in is BrokeredMessage.ScheduledEnqueueTimeUtc. You can read more about this property here: https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.brokeredmessage.scheduledenqueuetimeutc.aspx.

Community
  • 1
  • 1
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • This is also a good approach to consider. It frees you from periodically checking the database. When a message surfaces, it is time to process it meaning send reminders. One thing to watch out though is that if your business logic allows activation dates to be modified or tasks to be removed, etc., then you will also need to update the corresponding message in the queue. – Mehmet Aras Apr 17 '16 at 16:51