Remember to set Scheduled Task to future in Biztalk 2016
(Update 15.3.2021)
According to Sandro Pereira’s blog post Scheduled Task Adapter is now updated and these triggering issues should be issues no more. Get the new adapter version here https://github.com/sandroasp/BizTalk-Scheduled-Task-Adapter/tree/master/BTS2020
(Updated 19.12.2019)
If you have worked with Biztalk you have probably bumbed into Scheduled Task Adapter. It’s a great tool to trigger scheduled things in Biztalk. I’ve used it extensively in e.g. Biztalk 2013 R2, but not in Biztalk 2016 until late. Now when I started using Scheduled Task Adapter in Biztalk 2016, I noticed some strange behaviour in how tasks get triggered.
Example 1: Schedule task to run every minute
Let’s set the task to trigger every minute. Start the rloc and watch rloc to send message every minute. Let’s have a look how things looks in tracking. We see that there’s message every minute and seconds show 00.
Now let’s disable the receive location and leave it disabled for a minute or two. Then we start the rloc when seconds in the clock shows about 30 seconds past last minute. You’d think that the task would trigger every minute when seconds show 00. But no, now it triggers somewhere between 20-50 seconds on the clock.
Example 2: Schedule task to run every hour
Next let’s set the schedule to run the trigger every one hour e.g. at 19:30. The scheduled task runs as expected. Now we’ll change the trigger time to 18:35 as like 55 minutes to the past, but trigger should still launch at 19:35, since it’s set to trigger every hour. No, it will not. It triggers at 20:30:31, so like quite exactly one hour from the time when we changed the schedule. Also it will not trigger at 20:35. Very strange indeed.
Example 3: Schedule task to run every five minutes
Last let’s set the rloc to trigger every five minutes. We’ll set trigger time to 20:40. Task triggers fine at 20:40 and 20:45. Now let’s disable the rloc at 20:46 and enable it again at 20:48. You’d excpect the task to trigger at 20:50. Let’s see what happens. No, nothing at 20:50. Let’s wait few minutes. At 20:53 the task triggers. That is five minutes after we enabled the rloc. We are starting to see a pattern here.
Unfortunately I didn’t have time to test how daily, weekly and monthly schedules will handle past time or rloc disabling. If you have tried these, let me know how it went.
Solution
Now there’s a simple solution to avoid these little quirks. Every time you touch your Scheduled Task, remember to set the trigger time (and date) to the time when you want your Scheduled Task to trigger next time. So always have it set to future when you change schedule or enable disabled receive location. That way you can be sure that your task will trigger when you want it to trigger.
And finally, when you (or your CI/CD) import bindings where you have Scheduled Tasks, remember to go through them and you won’t get nasty scheduling surprises.
Update 19.12.2019 Just noticed that restarting host instance that runs scheduled tasks also affects schedules just like disabling/enabling rloc. Unfortunately this makes Scheduled Task Adapter quite unusable in cases when you need to trigger tasks at exact times. I hope that they fix the adapter.