Image not found Collapse All | Expand All | Show Default


EtlChkSeqJobsNotRun
DataStage Job Report
Generated 2005-02-15 08:26:49pm

 - Job Design  

Image not found

 - Job Information  

 - Job Properties (8) 

Property Value
Object Type Server 
Short Description Last Changed: 01-06-2005 
Full Description Job: EtlChkSeqJobsNotRun
-------------------------------------------------------------------------------------
Non-technical description:
Check to see if all jobs in a sequence finished OK.
-------------------------------------------------------------------------------------
Business rules:
Run at the end of a sequence.
Also run in DSJobReportDbDriver.
-------------------------------------------------------------------------------------
Rules for restarting this job:
Just rerun.
-------------------------------------------------------------------------------------
Parameters:
1. SeqName
2. EmailFlag
3. CheckParentFlag
4. EmailTo
5. DebugSw
-------------------------------------------------------------------------------------
Sources:
tbd
-------------------------------------------------------------------------------------
Targets:
tbd
-------------------------------------------------------------------------------------
Modification History:
-------------------------------------------------------------------------------------
UserId Date Version Modification Description
-------------------------------------------------------------------------------------
kduke 01-06-2005 1 Created job.
-------------------------------------------------------------------------------------
 
Category EtlStats 
Multiple Instance True 
Job Version Number 40.0.0 
Hash File Cache Sharing False 
Job Control * ------------------------------------------------------------
* EtlChkSeqJobsNotRun
* Decription:
* Also check the parent sequence to see if if failed to run
* all the jobs in the sequence.
* Should email a message to someone if any other sequence failed.
* ------------------------------------------------------------
* Parameters:
* 1. SeqName
* 2. EmailFlag
* 3. CheckParentFlag
* 4. EmailTo
* 5. DebugSw
* ------------------------------------------------------------
* Created : 2005-01-05 Kim Greggory Duke
* Last Modified : 2005-01-05 Kim Created.
* ------------------------------------------------------------
* $INCLUDE DSINCLUDE JOBCONTROL.H
* ------------------------------------------------------------
DEFFUN EmailToRtn(JobCategory) CALLING "DSU.EmailToRtn"
* -----------------------------------------------------------------
Ans = ""
JobName = 'EtlChkSeqJobsNotRun'
ThisJobName = JobName
JobsNotRun = ''
JobsAborted = ''
JobsWithWarnings = ''
JobsToEmail = ''
LogMsgs = ''
CrLf = char(13):char(10)
* ------------------------------------------------------------
open 'DS_JOBS' to DsJobs else
ErrMsg = "Error: Unable to open DS_JOBS"
gosub ErrRtn
goto TheEnd
end
open 'DS_JOBOBJECTS' to DsJobObjects else
ErrMsg = "Error: Unable to open DS_JOBOBJECTS"
gosub ErrRtn
goto TheEnd
end
HtmlPath = "Sql2Html"
open 'Sql2Html' to HtmlDir else
Cmd = 'CREATE.FILE Sql2Html 19'
execute Cmd capturing output
open 'Sql2Html' to HtmlDir else
ErrMsg = "Error: Unable to open Sql2Html"
gosub ErrRtn
goto TheEnd
end
end
LogoPath = 'OurLogo.jpg'
FilePath = './'
If System(91) = 0 Then
Shell = "UNIX"
Sep = '/'
OtherSep = '\'
End Else
Shell = "DOS"
Sep = '\'
OtherSep = Sep
End
convert OtherSep to Sep in LogoPath
convert OtherSep to Sep in FilePath
* ------------------------------------------------------------
* Get JobNo
* ------------------------------------------------------------
MainSeqName = SeqName
MainStartDate = ''
MainStartTime = ''
MainSeqStatus = ''
read JobRec from DsJobs, SeqName then
JobNo = JobRec<5>
JobCategory = JobRec<3>
ObjId = 'J\':JobNo:'\ROOT'
read ObjRec from DsJobObjects, ObjId then
MutipleInstanceFlag = ObjRec<59>
JobType = ObjRec<40>
if JobType = '2' then
Cnt = 0
DependJob = SeqName
* ------------------------------------------------------------
* loop thru dependent job names
* ------------------------------------------------------------
ChkSeqName = SeqName
gosub GetStartTime
* ------------------------------------------------------------
* do check parent here
* ------------------------------------------------------------
NoJobs = dcount(ObjRec<31>, @VM)
for i = 1 to NoJobs
DependJob = ObjRec<31,i>
DependType = ObjRec<32,i>
if DependType = '0' then
* ------------------------------------------------------------
* attach, get status, get StartTime
* ------------------------------------------------------------
gosub GetStartTime
end
next i
LogMsg = CrLf:change(LogMsgs, @FM, CrLf):CrLf
Call DSLogInfo(LogMsg, "JobControl")
* ------------------------------------------------------------
LogMsg = CrLf:'Jobs With Warnings:':CrLf:change(JobsWithWarnings, @FM, CrLf):CrLf
Call DSLogInfo(LogMsg, "JobControl")
* ------------------------------------------------------------
LogMsg = CrLf:'JobsAborted:':CrLf:change(JobsAborted, @FM, CrLf):CrLf
Call DSLogInfo(LogMsg, "JobControl")
* ------------------------------------------------------------
LogMsg = CrLf:'Jobs Not Run:':CrLf:change(JobsNotRun, @FM, CrLf):CrLf
Call DSLogInfo(LogMsg, "JobControl")
if JobsNotRun = '' and JobsAborted = '' then
LogMsg = MainSeqName:' succeeded.'
end else
if LastRunStatus = DSJS.RUNOK then
* ------------------------------------------------------------
* email log of failed job or job with warnings
* ------------------------------------------------------------
if JobsAborted = '' or JobsAborted = MainSeqName then
JobsToLog = JobsWithWarnings :@FM: MainSeqName
gosub BuildLogFiles
end else
JobsToLog = JobsAborted
gosub BuildLogFiles
end
end
LogMsg = MainSeqName:' aborted.'
end
Call DSLogInfo(LogMsg, "JobControl")
end else
* ------------------------------------------------------------
* not a sequence
* ------------------------------------------------------------
ErrMsg = 'Error: ':SeqName:' not a valid sequence'
gosub ErrRtn
end
end else
ErrMsg = 'Error: ':SeqName:' not a valid Job. No ':ObjId:' record.'
gosub ErrRtn
end
end else
ErrMsg = 'Error: ':SeqName:' not a valid Job.'
gosub ErrRtn
end
goto TheEnd
* ------------------------------------------------------------
GetStartTime:
Cnt += 1
JobReportName = "DSJobReportDb.":convert(".","_",DependJob)
read DependJobRec from DsJobs, DependJob then
DependJobJobNo = DependJobRec<5>
DependJobObjId = 'J\':DependJobJobNo:'\ROOT'
read DependJobObjRec from DsJobObjects, DependJobObjId then
MutipleInstanceFlag = DependJobObjRec<59>
if MutipleInstanceFlag <> 1 then

* Call DSLogInfo("Getting row counts for ":DependJob, "JobControl")
* ------------------------------------------------------------
* Setup DSJobReportDb, run it, wait for it to finish, and test for success
* ------------------------------------------------------------
hJob1 = DSAttachJob(DependJob, DSJ.ERRFATAL)
If NOT(hJob1) Then
ErrMsg = "Error: Job Attach Failed: ":DependJob
gosub ErrRtn
goto SkipCheck
End
* ------------------------------------------------------------
LastRunStatus = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
Begin case
case LastRunStatus = DSJS.RUNNING
LogMsg = DependJob:" Status: ":LastRunStatus:" Running in ":ChkSeqName
case LastRunStatus = DSJS.RUNOK
LogMsg = DependJob:" Status: ":LastRunStatus:" Finished in ":ChkSeqName
case LastRunStatus = DSJS.RUNWARN
LogMsg = DependJob:" Status: ":LastRunStatus:" Finished (see log) in ":ChkSeqName
JobsWithWarnings<-1> = DependJob
case LastRunStatus = DSJS.RUNFAILED
LogMsg = DependJob:" Status: ":LastRunStatus:" Aborted in ":ChkSeqName
JobsAborted<-1> = DependJob
case LastRunStatus = DSJS.CRASHED
LogMsg = DependJob:" Status: ":LastRunStatus:" Aborted in ":ChkSeqName
JobsAborted<-1> = DependJob
case LastRunStatus = DSJS.STOPPED
LogMsg = DependJob:" Status: ":LastRunStatus:" Stopped in ":ChkSeqName
JobsAborted<-1> = DependJob
case @TRUE
LogMsg = DependJob:" Status: ":LastRunStatus:" Unknown in ":ChkSeqName
JobsAborted<-1> = DependJob
end case
* Call DSLogInfo(LogMsg, "JobControl")
StartedDateTime = DSGetJobInfo(hJob1, DSJ.JOBSTARTTIMESTAMP)
if MainSeqName = DependJob then
MainStartedDateTime = StartedDateTime
MainSeqStatus = LastRunStatus
end
ErrCode = DSDetachJob(hJob1)
LogMsg = LogMsg:" Started: ":StartedDateTime
LogMsgs<-1> = Cnt:'. ':LogMsg
if MainStartedDateTime > StartedDateTime then
JobsNotRun<-1> = DependJob
end
end else
ErrMsg = 'Error: ':DependJob:' unable to get status for multiple instance job without InvocationId.'
gosub ErrRtn
end
end else
ErrMsg = 'Error: ':DependJob:' not a valid Job. No ':DependJobObjId:' record.'
gosub ErrRtn
end
end else
ErrMsg = 'Error: ':DependJob:' not a valid Job.'
gosub ErrRtn
end
SkipCheck:
return
* ------------------------------------------------------------
BuildLogFiles:
if EmailFlag then
* Cmd = 'SH Scripts':Sep:'Email.ksh ':EmailTo:' ':MsgJobName:' ':HtmlPath:Sep:HtmlId:' SqlResults'
if EmailTo = '' or index('All,Kim,Ron,Sharon',EmailTo,1)=0 then
EmailTo = EmailToRtn(JobCategory)
end
Cmd = 'SH Scripts':Sep:'Email.ksh ':EmailTo:' ':JobName
NoJobs = dcount(JobsToLog, @FM)
for i=1 to NoJobs
DependJob = JobsToLog
LogMsg = 'Build log file for: ':DependJob
Call DSLogInfo(LogMsg , "JobControl")
* ------------------------------------------------------------
* Setup GenHtmlJobLog, run it, wait for it to finish, and test for success
* ------------------------------------------------------------
hJob2 = DSAttachJob("GenHtmlJobLog.":FileName, DSJ.ERRFATAL)
If NOT(hJob2) Then
Call DSLogFatal("Job Attach Failed: GenHtmlJobLog", "JobControl")
Abort
End
ErrCode = DSSetParam(hJob2, "EmailFlag", @FALSE)
ErrCode = DSSetParam(hJob2, "EmailTo", EmailTo)
ErrCode = DSSetParam(hJob2, "JobNameToLog", DependJob)
ErrCode = DSSetParam(hJob2, "DebugSw", DebugSw)
ErrCode = DSRunJob(hJob2, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob2)
Status = DSGetJobInfo(hJob2, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
* Fatal Error - No Return
Call DSLogFatal("Job Failed: GenHtmlJobLog", "JobControl")
End
FileName = DependJob:'_Log'
HtmlId = FileName:'.html'
Cmd := ' ':HtmlPath:Sep:HtmlId
next i
HtmlId = 'OurLogo.jpg'
Cmd := ' ':HtmlPath:Sep:HtmlId
LogMsg = 'Email log files for: ':MainSeqName
Call DSLogInfo(LogMsg , "JobControl")
Cmd := ' ':MainSeqName:' problem job logs.'
Call DSLogInfo("Execute: " : Cmd, JobName)
execute Cmd capturing output returning RtnCode
Call DSLogInfo("Command Results: " : output, JobName)
end
return
* ------------------------------------------------------------
ErrRtn:
Call DSLogInfo(ErrMsg , "JobControl")
* Call DSLogFatal(ErrMsg, "JobControl")
* abort
return
* ------------------------------------------------------------
TheEnd:  

 - Parameters (5) 

Parameter Name Prompt Default Value Help Text
SeqName  SeqName  SeqTimeDim   
EmailFlag  EmailFlag   
CheckParentFlag  CheckParentFlag   
EmailTo  EmailTo  xxx   
DebugSw  DebugSw   

 - Stages (0) 



 - Source Stages (0) 


 - Processing Stages (0) 


 - Target Stages (0) 





Ascential and DataStage are trademarks of Ascential Software Corporation or its affiliates and may be registered in the United States or other jurisdictions.
For questions or comments regarding this utility, contact tony.curcio@ascentialsoftware.com.