@@ -11,24 +11,31 @@ public class SampleSqlReportJob : SqlJob
1111 {
1212 public override void Run ( )
1313 {
14- var report = new SampleReport ( ) {
15- Created = DateTime . Now ,
16- Data = new System . Collections . Generic . List < SampleDatum > ( ) ,
17- //Data = RunQuery<SampleDatum>(),
18- } ;
14+ try
15+ {
16+ var report = new SampleReport ( ) {
17+ Created = DateTime . Now ,
18+ Data = new System . Collections . Generic . List < SampleDatum > ( ) ,
19+ //Data = RunQuery<SampleDatum>(),
20+ } ;
1921
20- // Pass into Razor engine
21- string template = "Created on <strong>@Model.Created</strong> with <strong>@Model.Data.Count</strong> records." ;
22- var html = Engine . Razor . RunCompile ( template , "template-01" , typeof ( SampleReport ) , report ) ;
22+ // Pass into Razor engine
23+ string template = "Created on <strong>@Model.Created</strong> with <strong>@Model.Data.Count</strong> records." ;
24+ var html = Engine . Razor . RunCompile ( template , "template-01" , typeof ( SampleReport ) , report ) ;
2325
24- // Send Mail
25- var mailMessage = new MailMessage ( ) ;
26- mailMessage . To . Add ( "ethanhann@gmail.com" ) ;
27- mailMessage . Subject = "Sample SQL Report" ;
28- mailMessage . From = new MailAddress ( "root@localhost" ) ;
29- mailMessage . Body = html ;
30- mailMessage . IsBodyHtml = true ;
31- MailClient . Send ( mailMessage ) ;
26+ // Send Mail
27+ var mailMessage = new MailMessage ( ) ;
28+ mailMessage . To . Add ( "ethanhann@gmail.com" ) ;
29+ mailMessage . Subject = "Sample SQL Report" ;
30+ mailMessage . From = new MailAddress ( "root@localhost" ) ;
31+ mailMessage . Body = html ;
32+ mailMessage . IsBodyHtml = true ;
33+ MailClient . Send ( mailMessage ) ;
34+ }
35+ catch ( Exception exception )
36+ {
37+ throw new IntegrationJobRunFailureException ( "SampleSqlReportJob failed." , exception ) ;
38+ }
3239 }
3340 }
3441}
0 commit comments