[resolved] Email notification in case of job failure
Hi,
I have a job that takes all data from oracle table and insert it in to ms sql table.
Ex: tOracleInput==>tmap==>tmsSqlOutput
Now, in case the job fails - due to any reason (say database went down or incorrect connection settings or any mismatch etc), I want to capture the error log in a email. I want to notify by sending email that the job has been failed with the error code attached in email body.
I tried 2 approaches using tSendMail component as given below:
Approach1 : tOracleInput==>tmap==>tmsSqlOutput==>onComponentError==>tSendMail
Approach2: tOracleInput==>tmap==>tmsSqlOutput==>onComponentError==>tDie
and tLogCatcher==>tSendMail
But I was not able to get the expected result with these 2 approaches.
Please help me out here!! Appreciate the responses with solutions.
Hi
What's the problem? You don't receive the email or the error message is null in the email body? Any case, the job design looks like:
tOracle--main--tMssql
tLogCatcher--main--tJavaRow
|
onsubjobok
|
tSendmail
uncheck the option 'die on error' on all the component, so that the job will throw the exception once fails and die.
on tJavaRow:
globalMap.put("errorCode", input_row.message);
on the message body of tsendmail:
"the error message is: "+(String)globalMap.get("errorCode")
uncheck the option 'die on error' on all the components.
Hi
What's the problem? You don't receive the email or the error message is null in the email body? Any case, the job design looks like:
tOracle--main--tMssql
tLogCatcher--main--tJavaRow
|
onsubjobok
|
tSendmail
uncheck the option 'die on error' on all the component, so that the job will throw the exception once fails and die.
on tJavaRow:
globalMap.put("errorCode", input_row.message);
on the message body of tsendmail:
"the error message is: "+(String)globalMap.get("errorCode")
uncheck the option 'die on error' on all the components.
Hi Shong,
I was working on the other approach for this same functionality. When there is any failure to Talend Job, I have written a java class which sends email. This routine I have saved in the Routines section in talend. Now, how to call this routine when the job fails?
Suppose I have the routine named "sendEmail" and I have written the usual java mail code to send email(It has a main() method and inside main (), the send() method is called. This send() method sends the email actually). Now, in order to call this routine when our talend job fails, will it be called as:
tlogCatcher--onSubjobOk-->tJava
On tJava: just sendMail.this ? It did not work this way, so was wondering if you can give your inputs!
Hi
There should not be a main() method in the routine, please take a look at the system routines. To call a routine method, the format is routineName.methodName, for example:
tlogCatcher--onSubjobOk-->tJava
on tJava:sendEmail.send()
Best regards
Shong
Hello,
I was trying to implement several approaches of sending email. I tried sending email if the job fails to run and sending attachment with the email. Now I was trying with sending a plain email if the job fails and below was the code I wrote for it -
tOracleInput-->tMap-->tMySQLOutput
tLogCatcher--row1-->tFileOutputXML
|
onSubjobOk
|
tSendMail1
Now I have set all the properties. when I run the job, it triggers email 2 times. I verified the parameters and there is really nothing specific mentioned in this simple job which will trigger email twice.
Can anyone please help me here, why am I getting 2 emails instead of one simple email - as per this flow. . ?
Thanks
Xan
Hi Xan
I don't understand why it sends two emaisl either. Even, I don't believe the two emails are sent from the same component in this job. Do you have other subjobs in this job?
Best regards
Shong