Page 1 of 1
Job log from Multi Instance jobs
Posted: Thu Mar 17, 2005 6:51 am
by sankarsadasivan
Hi
I am trying to get the job logs of Multi instance server jobs and trying to wirte it in an OS file.
I am trying to use the following function
DSGetLogSummary(JobHandle, EventType, StartTime, EndTime, MaxNumber)
This function returns a dynamic array.
I am not sure how to declare and access dynamic arrays..
Can anybody throw some light how to use dynamic arrays and/or using this DSGetLogSummary function?.
Any other better alternative to get logs from multi instance jobs are also welcome.
Thanks in advance
Cheers
Sankar
Posted: Thu Mar 17, 2005 7:08 am
by ArndW
Sankar,
a dynamic array is just a string where the elements (in this case, separate lines of output) are separated by special characters. The mnemonic code @FM (field mark) is used in this case. If you wanted to write this out to a file you can do something along the lines of:
Code: Select all
SummaryArray = DSGetLogSummary(JobHandle, EventType, StartTime, EndTime, MaxNumber)
ArrayLines = DCOUNT(SummaryArray,@FM) ;** count number of lines
OPENSEQ '/tmp/TextLogFile' TO SeqOutFilePtr ON ERROR CALL DSLogFatal('unable to open file','')
FOR Counter = 1 TO ArrayLines
WRITESEQ FIELD(SummaryArray,@FM,Counter) ON SeqOutFilePtr ELSE CALL DSLogFatal('unable to write to file','')
NEXT Counter
WEOFSEQ SeqOutFilePtr ELSE CALL DSLogFatal('unable to write EOF to file','')
CLOSESEQ SeqOutFilePtr
** Note "SummaryArray<Counter>" can be used instead of the FIELD function
Job log from Multi Instance jobs
Posted: Thu Mar 17, 2005 10:42 am
by sankarsadasivan
Thanks ArndW.
That was quite useful, I enhanced the framework suggested by you to suit multi instant jobs and following is the code...Might be useful for some...
Thanks again for your help
Rgds
Sankar
************************************************************** Attaching the job handle of the job, whose log has to be written -
* I.JobName and I.LogFile are parameters
*************************************************************
hJob1 = DSAttachJob(I.JobName, DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed":JobName, "JobControl")
Abort
End
************************************************************** Calculating the job start time and the current time - the window for *getting the log and the invocation id of the job
*************************************************************
JobStartTime = DSGetJobInfo (hJob1, DSJ.JOBSTARTTIMESTAMP)
CurrentTime = Oconv(Date(),"D-YMD[4,2,2]"):' ':Field(TimeDate(), " ", 1, 1)
JobInvocationId = DSGetJobInfo (hJob1, DSJ.JOBINVOCATIONID)
Call DSLogInfo("Job Start time":JobStartTime,"JobControl")
Call DSLogInfo("Current time":CurrentTime,"JobControl")
************************************************************** Fetching the job log info using DSGetLogSummary in to the dynamic
* array LOGANY - Indicates all sort of log info
* 0 indicates unlimited records of log
*************************************************************
SummaryArray = DSGetLogSummary(hJob1, DSJ.LOGANY ,JobStartTime,CurrentTime,0)
*************************************************************
* Computing the number of lines of log, filtering the log based on
* invocation id and writting into the log file
*************************************************************
ArrayLines = DCOUNT(SummaryArray,@FM) ;** count number of lines
OpenSeq I.LogFile To SeqOutFilePtr Then
WeofSeq SeqOutFilePtr ;* write end-of-file mark immediately
End
FOR Counter = 1 TO ArrayLines
TempLine = FIELD(SummaryArray,@FM,Counter)
If FIELD(TempLine,'\',4) = JobInvocationId
Then
WriteSeq TempLine To SeqOutFilePtr
On Error
Call DSLogFatal("Error from status=":Status(),"JobControl")
End
Else
Call DSLogInfo ("Unable to Write to ","JobControl")
End
End
NEXT Counter
CloseSeq SeqOutFilePtr
*************************************************************
*End
*************************************************************
Posted: Fri Mar 18, 2005 1:50 am
by ArndW
Sankar,
good job; I love it when I post a rough framework and let whomever (in this case yourself) flesh out the basic idea and make it implementable! I'm glad it's working out for you.
(Hope nobody reading/posting the 2 concurrent CREATE threads looks at my code snippet - I did it again
![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
)
Re: Job log from Multi Instance jobs
Posted: Mon Dec 12, 2005 2:22 pm
by Titto
Where do we code the following code is it in JobControl or create it as a After/Before job routine.
Any help is appreciated!!
sankarsadasivan wrote:Thanks ArndW.
That was quite useful, I enhanced the framework suggested by you to suit multi instant jobs and following is the code...Might be useful for some...
Thanks again for your help
Rgds
Sankar
************************************************************** Attaching the job handle of the job, whose log has to be written -
* I.JobName and I.LogFile are parameters
*************************************************************
hJob1 = DSAttachJob(I.JobName, DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed":JobName, "JobControl")
Abort
End
************************************************************** Calculating the job start time and the current time - the window for *getting the log and the invocation id of the job
*************************************************************
JobStartTime = DSGetJobInfo (hJob1, DSJ.JOBSTARTTIMESTAMP)
CurrentTime = Oconv(Date(),"D-YMD[4,2,2]"):' ':Field(TimeDate(), " ", 1, 1)
JobInvocationId = DSGetJobInfo (hJob1, DSJ.JOBINVOCATIONID)
Call DSLogInfo("Job Start time":JobStartTime,"JobControl")
Call DSLogInfo("Current time":CurrentTime,"JobControl")
************************************************************** Fetching the job log info using DSGetLogSummary in to the dynamic
* array LOGANY - Indicates all sort of log info
* 0 indicates unlimited records of log
*************************************************************
SummaryArray = DSGetLogSummary(hJob1, DSJ.LOGANY ,JobStartTime,CurrentTime,0)
*************************************************************
* Computing the number of lines of log, filtering the log based on
* invocation id and writting into the log file
*************************************************************
ArrayLines = DCOUNT(SummaryArray,@FM) ;** count number of lines
OpenSeq I.LogFile To SeqOutFilePtr Then
WeofSeq SeqOutFilePtr ;* write end-of-file mark immediately
End
FOR Counter = 1 TO ArrayLines
TempLine = FIELD(SummaryArray,@FM,Counter)
If FIELD(TempLine,'\',4) = JobInvocationId
Then
WriteSeq TempLine To SeqOutFilePtr
On Error
Call DSLogFatal("Error from status=":Status(),"JobControl")
End
Else
Call DSLogInfo ("Unable to Write to ","JobControl")
End
End
NEXT Counter
CloseSeq SeqOutFilePtr
*************************************************************
*End
*************************************************************
Posted: Tue Dec 13, 2005 1:26 am
by ArndW
You can write/execute the code discussed in this thread either in a Job Control section or in a before/after subroutine or even in a normal routine and call it from wherever you can call routines. Important is that the code never gets called with the jobname and instance of the calling process, due to a bug in DSAttachJob() the process will hang for 30 minutes and then return an error in attach.