Page 1 of 1

Batch Job - send email issue

Posted: Tue Oct 02, 2007 5:31 pm
by shrey3a
Hi Gurus,

I've created a batch job which run all the jobs in parallel from a category.
I want to send an email if the job is finished with warnings with subject as job name or message as job name.

I'm able to send email for any jobs abort or finished with warnings but the subject is not dynamic i.e. Job Name , below is the code for same.

Thanks in advance for help

I even tried to create a normal batch job by adding all the jobs thru generated code and was able to send email individually but then jobs do not run in parallel I removed the dependency from dependency tab somehow they execute in sequence.

ProjName = DSGetProjectInfo (DSJ.PROJECTNAME)

TrimmedProjName = Field(Trim(ProjName), "_", 1, 2)
FolderName = 'chart'

cmd="SELECT NAME FMT '60R' FROM DS_JOBS WHERE CATEGORY LIKE '%abc\chart' ;"


Call DSExecute("UV",cmd,output,sysretcode)

Call DSLogInfo("Command Is: ":cmd,"Batch Job")

Call DSLogInfo("Output from the command: ":output,"Batch Job")

Final=""

n=DCount(output,@FM)

output=EReplace(output,Char(10),"")

For i=1 To n Step 1

A=Field(output,@FM,i)

JobName=Trim(A)

If IsNull(JobName)=1 OR Count(JobName,"...") > 0 OR Len(JobName) < 1 OR Count(JobName,"records listed.") OR Count(JobName,"\\\abc\chart")
Then

x=1

End Else

If Len(JobName) > 0 Then

* Setup JobName, run it, wait for it to finish, and test for success

hJob1 = DSAttachJob(JobName, DSJ.ERRWARN)
ErrCode = DSRunJob( hJob1, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob1)
Status = DSGetJobInfo( hJob1, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED OR Status = DSJS.RUNWARN
Then
Call DSExecute("UNIX",'/usr/bin/mailx -s JobName "a@yahoo.com"','0','0')
End
End

End
Next i
Call DSLogInfo("Batch Job Completed", "JobControl")

Posted: Tue Oct 02, 2007 5:36 pm
by ArndW
Please enclose your program in "code" tags to make it legible.

You code issues a call to DSWaitForJob(), this is why it executes in sequence.

Posted: Wed Oct 03, 2007 9:02 am
by shrey3a
Our requirement is to run the jobs in particular category and if any job is failed or finished with warning then send an email for that particular job name.


I'm using the below code to check the status of all jobs in a category and even able to send an email but somehow the subject of email is not dynamic i.e. equal to job name.

**************************************
cmd="SELECT NAME FMT '60R' FROM DS_JOBS WHERE CATEGORY LIKE '%Chartfields\Fin_To_EPM\Server' ;"

Call DSExecute("UV",cmd,output,sysretcode)

Call DSLogInfo("Command Is: ":cmd,"Batch Job")

Call DSLogInfo("Output from the command: ":output,"Batch Job")

Final=""

n=DCount(output,@FM)

output=EReplace(output,Char(10),"")

For i=1 To n Step 1

A=Field(output,@FM,i)

JobName=Trim(A)
hJob1 = DSAttachJob(JobName, DSJ.ERRNONE)
Status = DSGetJobInfo( hJob1, DSJ.JOBSTATUS)

If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED OR Status = DSJS.RUNWARN
Then
Call DSExecute("UNIX",'/usr/bin/mailx -s JobName "a@yahoo.com"','0','0')

End

Next i

Posted: Wed Oct 03, 2007 1:59 pm
by ray.wurlod

Code: Select all

Call DSExecute("UNIX",'/usr/bin/mailx -s ' : JobName : ' "a@yahoo.com"','0','0')