6

I would like to know what happens if an agent job (with recurring interval) in MS SQL server runs long enough so that it overlaps recurring execution.

According to my tests, paralleled execution does not happen, which is good.

What I'm trying t find out is that will the next execution be ignored because the previous one is not finished yet, OR will it be queued?

By "queued" I mean executing the queued requests immediately after the previous completed discarding the schedule.

Thank you

Seymour
  • 7,043
  • 12
  • 44
  • 51
To Ka
  • 640
  • 8
  • 24

1 Answers1

6

It will not be queued, it will be skipped. Easy to test: Create a job with a WAITFOR DELAY '00:05:00';, schedule job for < 2 minutes from now, then start the job manually. It will run for 5 minutes, once.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
  • Will this cause a higher cpu usage if we have a job scheduled every 1 minutes and the time to completion is 5 minutes. Will it be a better practice to have the final step of the job call the first step again as an alternative? – George Joseph Jun 05 '23 at 03:44
  • @GeorgeJoseph You could try it and compare, but I'm going to say... no, this will not cause any observable change in CPU. Not a big fan of the snake-eats-its-tail thing generally anyway. – Aaron Bertrand Jun 05 '23 at 19:03
  • here is why i think, im assuming that cpu has a queue which would get piled up with future schedules, while the "snake eats its tail" runs the one when the last one finishes – George Joseph Jun 05 '23 at 23:41
  • @GeorgeJoseph Nope, that's not how it works. If it's scheduled to run every minute, and it runs at 3:00:00 PM and takes 2 minutes and 30 seconds, it just won't try to run again until 3:03:00. It doesn't queue up the ones it missed and try to run through them quickly. I don't know why I'm telling you all this; you can just _try it_. – Aaron Bertrand Jun 06 '23 at 00:05
  • I am aware that the mechanism that it wouldn't, cause a parallel run! my specific question was with regards the cpu usage of the process which schedules – George Joseph Jun 07 '23 at 01:21
  • @GeorgeJoseph Don't guess or assume, test! I can tell you 50 times that you are not going to observe any additional CPU because a job gets skipped when it's already running. But I feel like you're only going to believe me when you prove it yourself. So, you should do that. – Aaron Bertrand Jun 07 '23 at 18:30
  • If i could do the test myself i wouldn't have ventured asking this question, but thanks for the feedback. I will check on this – George Joseph Jun 08 '23 at 04:35
  • @GeorgeJoseph What do you mean? You don't have an instance of SQL Server Agent anywhere that you can create a job and see what happens? – Aaron Bertrand Jun 08 '23 at 21:11