Page 1 of 1
Error handling in server routines
Posted: Tue Oct 15, 2013 5:18 am
by DSRajesh
Dear All,
I am using the below code for job statistics in server routine
If the job name which we are not passing is invalid or not avaialable then how to handle the error which occur with the routine.
Can any one suggest me how to handle this case with failing the routine.
Posted: Tue Oct 15, 2013 5:19 am
by DSRajesh
sorry missed out to give the code which i am using
below is the code
Code: Select all
SINCLUDE JOBCONTROL.H
Equate RoutineName To 'GetJobInfo'
JobHandle = ''
Int = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS)
Begin Case
Case Int = DSJS.RUNFAILED
Info = 'Aborted'
Case Int = DSJS.RUNOK
Info = 'Completed'
Case Int = DSJS.RUNWARN
Info = 'Warning'
Case Int = DSJS.RUNNING
Count = DSGetJobInfo(JobHandle, DSJ.DSJ.JOBEOTCOUNT)
Info = 'Running' : 'Count of Rows Complete' : Count
Case @True ; * all other values
Info = 'Not Defined'
End Case
StartTime = DSGetJobInfo(JobHandle, DSJ.JOBSTARTTIMESTAMP)
EndTime = DSGetJobInfo(JobHandle, DSJ.JO
Posted: Tue Oct 15, 2013 5:24 am
by ArndW
the routine as posted won't work correctly, since nowhere do you assign "JobHandle" - this should be done with DSJ.ME or DSAttachJob().
What is the variable you are passing in as your job parameter?
Posted: Tue Oct 15, 2013 6:02 am
by DSRajesh
sorry,below is the code:
Code: Select all
$INCLUDE DSINCLUDE JOBCONTROL.H
Equate RoutineName To 'GetJobInfo'
JobHandle = ''
JobHandle = DSAttachJob(JobName, DSJ.ERRNONE)
Int = DSGetJobInfo(JobHandle, DSJ.JOBSTATUS)
Begin Case
Case Int = DSJS.RUNFAILED
Job_Status = 'Aborted'
Case Int = DSJS.RUNOK
Job_Status = 'Finished'
Case Int = DSJS.RUNWARN
Job_Status = 'Finished with Warnings'
Case @True; * all other values
Info = 'UnKnown'
End Case
StartTime = DSGetJobInfo(JobHandle, DSJ.JOBSTARTTIMESTAMP)
EndTime = DSGetJobInfo(JobHandle, DSJ.JOBLASTTIMESTAMP)
Ans = Job_Status : '|' : StartTime : '|' : EndTime
The input variable which i am using is JobName
Posted: Tue Oct 15, 2013 6:46 am
by DSRajesh
Arndw,
Could you please suggest me on this.
Posted: Tue Oct 15, 2013 8:44 am
by ArndW
It is important not to try to DSAttachJob() your own job, that can cause a hang situation, so you should add:
Code: Select all
IF (JobName <> DSGetJobInfo(DSJ.ME,DSJ.JOBNAME) )
THEN
... your code
END
ELSE
Job_Status = 'Running'
END
Note you forget DSJS.RUNNING in your list.
Generally if the DSAttachJob() call fails, the return value will be 0. While this is not explicitly documented, it does work that way and that is what I use to determine if a DSAttachJob() call was succesfull or not.
Posted: Tue Oct 15, 2013 9:57 am
by ray.wurlod
Make this the first option within your CASE construct.
Code: Select all
Case Int = DSJE.BADHANDLE
Job_Status = 'Error'
Call DSLogWarn("Unable to attach job " : DQuote(JobName) : ".", RoutineName)
Posted: Tue Oct 15, 2013 10:10 am
by ArndW
Good one, I hadn't used DSJE.BADHANDLE. You still need to ensure that you don't inadvertantly try to do a DSAttachJob() to your own job but that CASE option is more elegant than an if-then-else construct.
Posted: Tue Oct 15, 2013 11:24 am
by chulett
Basically, you need to decide what needs to happen when a 'failure' is detected. Do you pass back something as the 'Ans'wer that will indicate a problem that is then handled by the caller or will you abort the routine itself?