Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2003
    Posts
    60

    Unanswered: Preventing schedule job to run

    Hi,

    I have 2 jobs schedule to run after every alternate hour. Job A runs at 1 am, 3 am, 5 am etc. and job B runs at 2 am, 4 am , 6 am.

    If job A is still running I would like Job B not to start at the scheduled time. How can I achieve this?

    Thanks in Advance .... j

  2. #2
    Join Date
    Oct 2002
    Location
    Leics, England
    Posts
    5
    Very simply... first step in Job A could be to update a flag on the DB, last step would be to remove it. First step in Job B would be to check the flag, if present it bombs if it's not there then continue.

  3. #3
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    If you mean to have Job B not run at all, and let Job A potentially run twice in a row, then you could do it this way:

    Create a table in say the pubs database called Status (col1 varchar(10))

    The first step in Job A will be to put a row into this table. The last step in Job A will be to delete the table (think of it as an on/off switch)

    The first step in Job B would be a check to see if a row exists, and if it does, then select 1/0 (or any other error of your choice that will trigger the OnJobStepFailure to trigger.

    Set the failure action of step 1 of Job B to be exit the job, then you are done.

    Not too sure what you would have to do to get Job B to run at say 2:30 or so, if you can not have Job A run twice in a row.

    Hope this helps.

  4. #4
    Join Date
    Mar 2003
    Posts
    60
    Can I disable Job B or its schedule untill job A finishes? And once it finishes can I enable it?

  5. #5
    Join Date
    Dec 2002
    Posts
    63
    Yeah, you can do that, just do the following...

    USE msdb
    UPDATE sysjobs
    SET enabled = 1
    WHERE jobid = <jobid>

    to enable the job and then set it back to 0 to disable it.

    Another option would be to add job B as a step of job A. And just let it always run as soon as job A finishes. Not sure if that is an option though.

    Hope this helps.

  6. #6
    Join Date
    Mar 2003
    Posts
    60
    Can I disable Job B or its schedule untill job A finishes? And once it finishes can I enable it?

  7. #7
    Join Date
    Dec 2002
    Posts
    63
    Sure... use the method Kuthula posted above, only instead of a flag in a table, have job A disable job B as the first step, and then enable it as the last step. using the update to sysjobs in msdb.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •