11package io .hyperfoil .tools .horreum .notification ;
22
3+ import static java .nio .charset .StandardCharsets .UTF_8 ;
4+
35import java .net .URLEncoder ;
4- import java .nio . charset . StandardCharsets ;
6+ import java .text . DateFormat ;
57import java .text .SimpleDateFormat ;
68import java .time .Duration ;
79import java .time .Instant ;
1113import jakarta .inject .Inject ;
1214
1315import org .eclipse .microprofile .config .inject .ConfigProperty ;
14- import org .jboss .logging .Logger ;
1516
1617import io .hyperfoil .tools .horreum .events .DatasetChanges ;
1718import io .hyperfoil .tools .horreum .svc .MissingValuesEvent ;
1819import io .hyperfoil .tools .horreum .svc .ServiceException ;
20+ import io .quarkus .logging .Log ;
1921import io .quarkus .mailer .Mail ;
2022import io .quarkus .mailer .reactive .ReactiveMailer ;
2123import io .quarkus .qute .Location ;
@@ -47,7 +49,7 @@ public class EmailPlugin implements NotificationPlugin {
4749 @ Inject
4850 ReactiveMailer mailer ;
4951
50- private final Logger log = Logger . getLogger ( getClass () );
52+ private final DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" );
5153
5254 @ Override
5355 public String method () {
@@ -77,26 +79,26 @@ protected EmailNotification(String username, String data) {
7779 @ Override
7880 public void notifyChanges (DatasetChanges event ) {
7981 String subject = subjectPrefix + " Change in " + event .testName ;
80- String content = changeNotificationEmail
82+ changeNotificationEmail
8183 .data ("username" , username )
8284 .data ("testName" , event .testName )
83- .data ("fingerprint" ,
84- URLEncoder .encode (event .fingerprint != null ? event .fingerprint : "" , StandardCharsets .UTF_8 ))
85+ .data ("fingerprint" , URLEncoder .encode (event .fingerprint != null ? event .fingerprint : "" , UTF_8 ))
8586 .data ("baseUrl" , baseUrl )
8687 .data ("testId" , String .valueOf (event .dataset .testId ))
8788 .data ("runId" , event .dataset .runId )
8889 .data ("datasetOrdinal" , event .dataset .ordinal )
8990 .data ("changes" , event .changes ())
90- .render ();
91- mailer .send (Mail .withHtml (data , subject , content )).await ().atMost (sendMailTimeout );
92- log .debug ("Sending mail: " + content );
91+ .createUni ().subscribe ().with (content -> {
92+ mailer .send (Mail .withHtml (data , subject , content )).await ().atMost (sendMailTimeout );
93+ Log .debug ("Sending mail: " + content );
94+ });
9395 }
9496
9597 @ Override
9698 public void notifyMissingDataset (String testName , int testId , String ruleName , long maxStaleness ,
9799 Instant lastTimestamp ) {
98100 String subject = String .format ("%s Missing expected data for %s/%s" , subjectPrefix , testName , ruleName );
99- String content = missingDatasetNotificationEmail
101+ missingDatasetNotificationEmail
100102 .data ("username" , username )
101103 .data ("testName" , testName )
102104 .data ("testId" , String .valueOf (testId ))
@@ -106,19 +108,18 @@ public void notifyMissingDataset(String testName, int testId, String ruleName, l
106108 .data ("currentStaleness" ,
107109 lastTimestamp == null ? "yet"
108110 : "in " + prettyPrintTime (System .currentTimeMillis () - lastTimestamp .toEpochMilli ()))
109- .data ("lastTimestamp" ,
110- lastTimestamp == null ? null
111- : new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" ).format (Date .from (lastTimestamp )))
112- .render ();
113- mailer .send (Mail .withHtml (data , subject , content )).await ().atMost (sendMailTimeout );
114- log .debug ("Sending mail: " + content );
111+ .data ("lastTimestamp" , lastTimestamp == null ? null : dateFormat .format (Date .from (lastTimestamp )))
112+ .createUni ().subscribe ().with (content -> {
113+ mailer .send (Mail .withHtml (data , subject , content )).await ().atMost (sendMailTimeout );
114+ Log .debug ("Sending mail: " + content );
115+ });
115116 }
116117
117118 @ Override
118119 public void notifyMissingValues (String testName , String fingerprint , MissingValuesEvent event ) {
119120 String subject = String .format ("%s Missing change detection values in test %s, dataset %d#%d" ,
120121 subjectPrefix , testName , event .dataset .runId , event .dataset .ordinal + 1 );
121- String content = missingValuesNotificationEmail
122+ missingValuesNotificationEmail
122123 .data ("username" , username )
123124 .data ("testName" , testName )
124125 .data ("testId" , String .valueOf (event .dataset .testId ))
@@ -127,25 +128,27 @@ public void notifyMissingValues(String testName, String fingerprint, MissingValu
127128 .data ("runId" , event .dataset .runId )
128129 .data ("datasetOrdinal" , event .dataset .ordinal )
129130 .data ("variables" , event .variables )
130- .render ();
131- mailer .send (Mail .withHtml (data , subject , content )).await ().atMost (sendMailTimeout );
132- log .debug ("Sending mail: " + content );
131+ .createUni ().subscribe ().with (content -> {
132+ mailer .send (Mail .withHtml (data , subject , content )).await ().atMost (sendMailTimeout );
133+ Log .debug ("Sending mail: " + content );
134+ });
133135 }
134136
135137 @ Override
136138 public void notifyExpectedRun (String testName , int testId , long before , String expectedBy , String backlink ) {
137139 String subject = subjectPrefix + " Missing expected run for " + testName ;
138- String content = expectedRunNotificationEmail
140+ expectedRunNotificationEmail
139141 .data ("username" , username )
140142 .data ("testName" , testName )
141143 .data ("testId" , String .valueOf (testId ))
142144 .data ("baseUrl" , baseUrl )
143- .data ("before" , new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) .format (new Date (before )))
145+ .data ("before" , dateFormat .format (new Date (before )))
144146 .data ("expectedBy" , expectedBy )
145147 .data ("backlink" , backlink )
146- .render ();
147- mailer .send (Mail .withHtml (data , subject , content )).await ().atMost (sendMailTimeout );
148- log .debug ("Sending mail: " + content );
148+ .createUni ().subscribe ().with (content -> {
149+ mailer .send (Mail .withHtml (data , subject , content )).await ().atMost (sendMailTimeout );
150+ Log .debug ("Sending mail: " + content );
151+ });
149152 }
150153 }
151154
0 commit comments