Image not found Collapse All | Expand All | Show Default


MonitorSeq
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: MonitorSeq
-------------------------------------------------------------------------------------
Non-technical description:
This job will wait on the main sequence to start running.
It will build a list of the sequences to run.
As they run it will check on them after each sleep interval.
When the sequences finish then run EtlChkSeqJobsNotRun
This will make sure all jobs in this child sequence ran properly.
-------------------------------------------------------------------------------------
Business rules:

-------------------------------------------------------------------------------------
Rules for restarting this job:
Just rerun.
-------------------------------------------------------------------------------------
Parameters:
1. SeqName
2. EmailFlag
3. EmailTo
4. 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 * ------------------------------------------------------------
* MonitorSeq
* ------------------------------------------------------------
* Decription:
* This job will wait on the main sequence to start running.
* It will build a list of the sequences to run.
* As they run it will check on them after each sleep interval.
* When the sequences finish then run EtlChkSeqJobsNotRun
* This will make sure all jobs in this child sequence ran properly.
* ------------------------------------------------------------
* Parameters:
* 1. SeqName
* 2. EmailFlag
* 3. EmailTo
* 4. DebugSw
* ------------------------------------------------------------
* Created : 2005-01-05 Kim Greggory Duke
* Last Modified : 2005-01-05 Kim Created.
* ------------------------------------------------------------
Ans = ""
JobName = 'MonitorSeq'
ThisJobName = JobName
StopId = JobName:'Stop.':SeqName
CrLf = char(13):char(10)
SleepTime = 60 * 3 ; * seconds
* SleepTime = 30 ; * seconds
MaxWaitTime = 60 * 30 ; * seconds
ExceededWaitTime = @FALSE
MaxRunTime = 60 * 60 * 24 ; * seconds
ExceededRunTime = @FALSE
* ------------------------------------------------------------
open 'VOC' to VOC else
ErrMsg = "Error: Unable to open VOC"
gosub ErrRtn
goto TheEnd
end
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
* ------------------------------------------------------------
MyStartDate = DATE()
MyStartTime = TIME()
MyStartedDateTime = oconv(MyStartDate, "D4-YMD[4,2,2]"):" ":oconv(MyStartTime, "MTS")
MainSeqName = SeqName
MainStartDate = ''
MainStartTime = ''
MainSeqStatus = ''
DependJobList = ''
* ------------------------------------------------------------
* Get JobNo
* ------------------------------------------------------------
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
* ------------------------------------------------------------
* build job list
* ------------------------------------------------------------
NoJobs = dcount(ObjRec<31>, @VM)
for i = 1 to NoJobs
DependJob = ObjRec<31,i>
DependType = ObjRec<32,i>
if DependType = '0' then
DependJobList<-1> = DependJob
end
next i
end else
* ------------------------------------------------------------
* not a sequence
* ------------------------------------------------------------
ErrMsg = 'Error: ':SeqName:' not a valid sequence'
gosub ErrRtn
goto TheEnd
end
end else
* ------------------------------------------------------------
* SeqName not a valid job
* ------------------------------------------------------------
ErrMsg = 'Error: ':SeqName:' not a valid Job. No ':ObjId:' record.'
gosub ErrRtn
goto TheEnd
end
end else
ErrMsg = 'Error: ':SeqName:' not a valid Job.'
gosub ErrRtn
goto TheEnd
end
* ------------------------------------------------------------
* Main
* ------------------------------------------------------------
* Delete VOC, MonitorSeqStop
* Get SeqName.
* Loop
* Check VOC, MonitorSeqStop
* stop
* Attach to job
* get status
* until running
* Loop
* Get DependJob from SeqJob
* if finished running
* run EtlChkSeqJobsNotRun
* delete from list
* JobName = next in list
* while jobs left to check
* done monitoring
* ------------------------------------------------------------
delete VOC, StopId else null
* ------------------------------------------------------------
DependJob = SeqName
ChkSeqName = SeqName
gosub GetStartTime
if DebugSw then
LogMsg = " MyStartedDateTime: ":MyStartedDateTime:" StartedDateTime: ":StartedDateTime
Call DSLogInfo(LogMsg, "JobControl")
end
loop
gosub GetStartTime
Begin case
case LastRunStatus = DSJS.RUNNING
SeqStarted = @TRUE
case MyStartedDateTime <= StartedDateTime
SeqStarted = @TRUE
case @TRUE
SeqStarted = @FALSE
End case
gosub GetMyRunTime
read VocRec from VOC, StopId then
ErrMsg = 'Error: Stopped by VOC, ':StopId
gosub ErrRtn
goto TheEnd
end
if ExceededWaitTime then
ErrMsg = 'Error: ExceededWaitTime ':ExceededWaitTime:' seconds exceeded. ':SeqName:' job never started.'
gosub ErrRtn
goto TheEnd
end
sleep SleepTime
until SeqStarted do
repeat
* ------------------------------------------------------------
* loop thru dependent job names
* ------------------------------------------------------------
ContFlag = @TRUE
Loop
read VocRec from VOC, StopId then
ContFlag = @FALSE
end
if DependJobList = '' then
ContFlag = @FALSE
end
while ContFlag do
JobDelete = @FALSE
NoJobs = dcount(DependJobList, @FM)
for i = 1 to NoJobs until JobDelete
DependJob = DependJobList
if DebugSw then
LogMsg = " Checking run times: ":DependJob
Call DSLogInfo(LogMsg, "JobControl")
end
gosub GetStartTime
if JobStarted and JobFinished then
if IsSequence then
* ------------------------------------------------------------
* Run EtlChkSeqJobsNotRun here
* ------------------------------------------------------------
* Setup EtlChkSeqJobsNotRun.DependJob, run it, wait for it to finish, and test for success
hJob2 = DSAttachJob("EtlChkSeqJobsNotRun.":DependJob, DSJ.ERRFATAL)
If NOT(hJob2) Then
Call DSLogInfo("Job Attach Failed: EtlChkSeqJobsNotRun.":DependJob, "JobControl")
* Abort
End Else
LastRunStatus = DSGetJobInfo(hJob2, DSJ.JOBSTATUS)
If LastRunStatus = DSJS.RUNFAILED Or LastRunStatus = DSJS.CRASHED Or LastRunStatus = DSJS.STOPPED Then
Call DSLogInfo("EtlChkSeqJobsNotRun.":DependJob, "Reseting job and last run status")
ErrCode = DSRunJob(hJob2, DSJ.RUNRESET)
ErrCode = DSWaitForJob(hJob2)
ErrCode = DSDetachJob(hJob2)
hJob2 = DSAttachJob("EtlChkSeqJobsNotRun.":DependJob, DSJ.ERRFATAL)
If NOT(hJob2) Then
Call DSLogFatal("Job Attach Failed: ":"EtlChkSeqJobsNotRun.":DependJob, "JobControl")
Abort
End
end
ErrCode = DSSetParam(hJob2, "SeqName", DependJob)
ErrCode = DSSetParam(hJob2, "EmailFlag", EmailFlag)
ErrCode = DSSetParam(hJob2, "CheckParentFlag", '1')
ErrCode = DSSetParam(hJob2, "EmailTo", EmailTo)
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 DSLogInfo("Job Failed: EtlChkSeqJobsNotRun.":DependJob, "JobControl")
End
End
End ; * IsSequence
if DebugSw then
LogMsg = " DependJob: ":DependJob:" finished."
Call DSLogInfo(LogMsg, "JobControl")
end
JobDelete = @TRUE
del DependJobList
end else
if ErrMsg <> '' or (JobStarted and JobAborted) then
JobDelete = @TRUE
del DependJobList
end
end
next i
gosub GetMyRunTime
if ExceededRunTime then
ErrMsg = 'Error: ExceededRunTime ':ExceededRunTime:' seconds exceeded. ':SeqName:' job never finished.'
gosub ErrRtn
goto TheEnd
end
sleep SleepTime
repeat
* ------------------------------------------------------------
DependJob = SeqName
hJob2 = DSAttachJob("EtlChkSeqJobsNotRun.":DependJob, DSJ.ERRFATAL)
If NOT(hJob2) Then
Call DSLogInfo("Job Attach Failed: EtlChkSeqJobsNotRun.":DependJob, "JobControl")
* Abort
End Else
LastRunStatus = DSGetJobInfo(hJob2, DSJ.JOBSTATUS)
If LastRunStatus = DSJS.RUNFAILED Or LastRunStatus = DSJS.CRASHED Or LastRunStatus = DSJS.STOPPED Then
Call DSLogInfo("EtlChkSeqJobsNotRun.":DependJob, "Reseting job and last run status")
ErrCode = DSRunJob(hJob2, DSJ.RUNRESET)
ErrCode = DSWaitForJob(hJob2)
ErrCode = DSDetachJob(hJob2)
hJob2 = DSAttachJob("EtlChkSeqJobsNotRun.":DependJob, DSJ.ERRFATAL)
If NOT(hJob2) Then
Call DSLogFatal("Job Attach Failed: ":"EtlChkSeqJobsNotRun.":DependJob, "JobControl")
Abort
End
end
ErrCode = DSSetParam(hJob2, "SeqName", DependJob)
ErrCode = DSSetParam(hJob2, "EmailFlag", EmailFlag)
ErrCode = DSSetParam(hJob2, "CheckParentFlag", '1')
ErrCode = DSSetParam(hJob2, "EmailTo", EmailTo)
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 DSLogInfo("Job Failed: EtlChkSeqJobsNotRun.":DependJob, "JobControl")
End
End
goto TheEnd
* ------------------------------------------------------------
GetMyRunTime:
MyRunTime = (DATE() - MyStartDate) * 24 * 60 * 60
MyRunTime += TIME() - MyStartTime
if MyRunTime > MaxWaitTime then
ExceededWaitTime = @TRUE
end
if MyRunTime > MaxRunTime then
ExceededRunTime = @TRUE
end
return
* ------------------------------------------------------------
GetStartTime:
ErrMsg = ''
Cnt += 1
read DependJobRec from DsJobs, DependJob then
DependJobJobNo = DependJobRec<5>
DependJobObjId = 'J\':DependJobJobNo:'\ROOT'
read DependJobObjRec from DsJobObjects, DependJobObjId then
JobType = DependJobObjRec<40>
if JobType = '2' then
IsSequence = @TRUE
end else
IsSequence = @FALSE
end
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
* ------------------------------------------------------------
JobAborted = @FALSE
JobFinished = @FALSE
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
JobFinished = @TRUE
case LastRunStatus = DSJS.RUNWARN
LogMsg = DependJob:" Status: ":LastRunStatus:" Finished (see log) in ":ChkSeqName
JobsWithWarnings = DependJob
JobFinished = @TRUE
case LastRunStatus = DSJS.RUNFAILED
LogMsg = DependJob:" Status: ":LastRunStatus:" Aborted in ":ChkSeqName
JobAborted = @TRUE
case LastRunStatus = DSJS.CRASHED
LogMsg = DependJob:" Status: ":LastRunStatus:" Aborted in ":ChkSeqName
JobAborted = @TRUE
case LastRunStatus = DSJS.STOPPED
LogMsg = DependJob:" Status: ":LastRunStatus:" Stopped in ":ChkSeqName
JobAborted = @TRUE
case @TRUE
LogMsg = DependJob:" Status: ":LastRunStatus:" Unknown in ":ChkSeqName
JobAborted = @TRUE
end case
if DebugSw then 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
JobStarted = @TRUE
end else
JobStarted = @FALSE
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
* ------------------------------------------------------------
ErrRtn:
Call DSLogInfo(ErrMsg , "JobControl")
* Call DSLogFatal(ErrMsg, "JobControl")
* abort
return
* ------------------------------------------------------------
TheEnd:  

 - Parameters (4) 

Parameter Name Prompt Default Value Help Text
SeqName  SeqName  SeqTimeDim   
EmailFlag  EmailFlag   
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.