March 6, 2006 at 1:39 pm
I have a job scheduled once a minute to scan the inbox via xp_readmail.
Each message meeting criteria is processed in the following manner:
1. The attachment file is saved.
2. The attachment file is moved to a "Import Queue" folder.
3. An entry is added to an ImportQueue table, identifying the file for later import.
4. The email is deleted.
If the job takes longer than a minute (my scheduled job interval), how to do I prevent the next scheduled job from running "On-Top-Of" (simultaneously) the current running job?
I thought about saving the @@spid and login_time to a small table at the begining of the import run. Subsequent runs would determine if that @@spid and login_time still exist...If they do, abort the job (since it is still running)
Is there a better way to do this? Using Windows XP.
Thanks!
Bruce Wilson
Datastream Consulting, LLC
March 6, 2006 at 1:47 pm
It is my experience if a job is already running you can't start another job until the first one completes.
If you are actually having the same job get started twice, even though the first job has not completed then you might try this.
As the first step of the job disable the job schedule. The second step through next to last step does what ever you want the job to do. Then as the last step enable the job schedule again. This way the schedule will be turned off while the job is running.
Gregory A. Larsen, MVP
March 8, 2006 at 11:43 am
Greg,
Thanks for the information. I was curious so I did some testing:
I wrote a stored procedure that inserts a record with the current date/time in a table and then waits for 5 minutes.
I created a job to call the stored procedure.
I scheduled the job to run every 1 minutes.
Examining the table records, I saw a record inserted every 5+ minutes.
This proves "Only one instance of the job can be run at a time" (from Online Books) is correct.
Thanks,
Bruce
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply