implement first draft for email reporting
							parent
							
								
									7b1d7c5dc9
								
							
						
					
					
						commit
						2be1af365d
					
				| @ -0,0 +1,7 @@ | |||||||
|  | package alfred.web.core.event | ||||||
|  | 
 | ||||||
|  | import alfred.web.core.build.BuildContext | ||||||
|  | 
 | ||||||
|  | data class BuildFinished( | ||||||
|  |     val ctx: BuildContext | ||||||
|  | ) | ||||||
| @ -0,0 +1,36 @@ | |||||||
|  | package alfred.web.core.event.listener | ||||||
|  | 
 | ||||||
|  | import alfred.web.core.event.BuildFinished | ||||||
|  | import org.springframework.beans.factory.annotation.Value | ||||||
|  | import org.springframework.context.event.EventListener | ||||||
|  | import org.springframework.mail.MailSender | ||||||
|  | import org.springframework.mail.SimpleMailMessage | ||||||
|  | import org.springframework.scheduling.annotation.Async | ||||||
|  | import org.springframework.stereotype.Component | ||||||
|  | 
 | ||||||
|  | @Component | ||||||
|  | class SendMailOnFinish( | ||||||
|  |     @Value("\${ALFRED_MAIL_FROM}") | ||||||
|  |     val sender: String, | ||||||
|  |     val mailSender: MailSender | ||||||
|  | ) { | ||||||
|  | 
 | ||||||
|  |     @EventListener | ||||||
|  |     @Async | ||||||
|  |     fun onBuildFinished(event: BuildFinished) { | ||||||
|  |         if (event.ctx.config.mailReportTo === null) { | ||||||
|  |             return | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         val ctx = event.ctx | ||||||
|  |         val msg = SimpleMailMessage().apply { | ||||||
|  |             from = sender | ||||||
|  |             subject = "Build ${ctx.buildId} finished" | ||||||
|  |             setTo(event.ctx.config.mailReportTo) | ||||||
|  |             text = ctx.logFile.backingFile.readLines().joinToString("\n") | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         mailSender.send(msg) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in New Issue
	
	 Josha von Gizycki
						Josha von Gizycki