Page 1 of 1

Reseting and Running a Job from Routine

Posted: Fri Jul 10, 2009 5:12 am
by anupam
Here is the piece of code

Code: Select all

$INCLUDE DSINCLUDE JOBCONTROL.H



      JobName=Trim(Arg1)

      JobHandle = DSAttachJob (JobName, DSJ.ERRWARN)


      Status = DSGetJobInfo (JobHandle, DSJ.JOBSTATUS)

      If Status= DSJS.RUNFAILED or Status= DSJS.CRASHED

      THEN
         ErrCode=DSRunJob(JobHandle , DSJ.RUNRESET )
         ErrCode=DSWaitForJob(JobHandle)
      END

      ErrCode=DSRunJob(JobHandle , DSJ.RUNNORMAL )
      ErrCode=DSWaitForJob(JobHandle)



      ErrCode=DSDetachJob(JobHandle)
      Ans=ErrCode

When the job is in runnable state, this routines works fine and run it. When the job is not in runnable state, it resets it but do not run the job.

My requirement is that it should reset as well run the job if the job is in not runnable state.

Pls advice where I am missing

Posted: Fri Jul 10, 2009 6:37 am
by chulett
Don't see anything obviously wrong. :?

Look into using DSPrepareJob instead of all that IF-THEN checking though, one stop shopping.

Posted: Fri Jul 10, 2009 7:05 am
by ArndW
This is a tricky issue, which I think leads back to how the JobHandle is returned on resetting the job. I would recommend adding a line

Code: Select all

JobHandle=DSPrepareJob(JobHandle)
as Craig suggested to replace your if-then-else construct. Note that DSPrepareJob() returns a different JobHandle when it resets the job, thus the assignment statement.

Code: Select all

$INCLUDE DSINCLUDE JOBCONTROL.H 
   JobName   = Trim(Arg1) 
   JobHandle = DSAttachJob(JobName, DSJ.ERRWARN) 
   Status    = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS) 
   IF Status = DSJS.RUNFAILED or Status= DSJS.CRASHED THEN JobHandle = DSPrepareJob(JobHandle)
   Dummy     = DSRunJob(JobHandle , DSJ.RUNNORMAL ) 
   Dummy     = DSWaitForJob(JobHandle) 
   Ans       = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS) 
   Dummy     = DSDetachJob(JobHandle) 
[/code]

Posted: Fri Jul 10, 2009 7:10 am
by chulett
Ah... was wondering about the job handle. Still better to leverage DSPrepareJob IMHO.

(hey, it was 6AM and the coffee hadn't kicked in yet) :wink: