0

Hi there,

I was trying to get a Scheduled Job (in SQL Server 2000) to run every second or two. I had three T-Sql blocks I needed to execute every two seconds, and you know you can just schedule recurring times to every minute.

I started out by introducing multiple Minute recurring schedules starting at different second offsets. This is okay unless you really need something more frequent (like I did, and I didn't want to add 30 different schedules by hand).

Then I thought more clearly, all I wanted was to start a job that never stoped, and, to avoid overflowing the server with executions of my 3 T-Sql blocks, do some sleeping meanwhile.
The first part is done by setting the last step to jump to the 1rst step On Success.
The last, and also easy, part is adding a Step to sleep for a period of time, I used a JScript (ActiveX Script) with the following code (for the original go here):

Date.ONE_SECOND = 1000
  function nap (m) {var then = new Date(new Date().getTime() + m); while (new Date() < then) {}}
  nap(<Replace with number of seconds to sleep> * Date.ONE_SECOND)

And there the process goes. To see how well it's going check the Job History and select the checkbox "Show step details".

1
Contributor
1
Reply
2
Views
11 Years
Discussion Span
Last Post by TiagoDias
0

Please note that the Javascript wait depicted is an ACTIVE WAIT, it will consume CPU resources heavily.

It was my mistake, the correct solution should be to use a sleep command line utility (for example sleep from unix-utils: http://unxutils.sourceforge.net/) or use the T-SQL command WAITFOR (ex. WAITFOR DELAY '000:00:02') instead.
Please beware that the WAITFOR command can be less accurate.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.