Skip to content

Commit 1f01aca

Browse files
committed
Add custom job exception
1 parent a56d3af commit 1f01aca

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

IntegrationEngine.ConsoleHost/IntegrationJobs/SampleSqlReport/SampleSqlReportJob.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.Serialization;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace IntegrationEngine.Core.Jobs
9+
{
10+
public class IntegrationJobRunFailureException : Exception
11+
{
12+
public IntegrationJobRunFailureException()
13+
{}
14+
15+
public IntegrationJobRunFailureException(string message)
16+
: base(message)
17+
{}
18+
19+
public IntegrationJobRunFailureException(string message, Exception innerException)
20+
: base(message, innerException)
21+
{}
22+
}
23+
}

0 commit comments

Comments
 (0)