mirror of https://github.com/hykilpikonna/AquaDX
[O] Speed up bootup by making email init async
parent
214a356135
commit
64a27e5708
|
@ -5,15 +5,17 @@ import ext.Str
|
||||||
import icu.samnyan.aqua.net.db.AquaNetUser
|
import icu.samnyan.aqua.net.db.AquaNetUser
|
||||||
import icu.samnyan.aqua.net.db.EmailConfirmation
|
import icu.samnyan.aqua.net.db.EmailConfirmation
|
||||||
import icu.samnyan.aqua.net.db.EmailConfirmationRepo
|
import icu.samnyan.aqua.net.db.EmailConfirmationRepo
|
||||||
import jakarta.annotation.PostConstruct
|
|
||||||
import org.simplejavamail.api.mailer.Mailer
|
import org.simplejavamail.api.mailer.Mailer
|
||||||
import org.simplejavamail.email.EmailBuilder
|
import org.simplejavamail.email.EmailBuilder
|
||||||
import org.simplejavamail.springsupport.SimpleJavaMailSpringSupport
|
import org.simplejavamail.springsupport.SimpleJavaMailSpringSupport
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.boot.context.event.ApplicationStartedEvent
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.context.annotation.Import
|
import org.springframework.context.annotation.Import
|
||||||
|
import org.springframework.context.event.EventListener
|
||||||
|
import org.springframework.scheduling.annotation.Async
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -39,13 +41,12 @@ class EmailService(
|
||||||
val confirmationRepo: EmailConfirmationRepo,
|
val confirmationRepo: EmailConfirmationRepo,
|
||||||
) {
|
) {
|
||||||
val log: Logger = LoggerFactory.getLogger(EmailService::class.java)
|
val log: Logger = LoggerFactory.getLogger(EmailService::class.java)
|
||||||
lateinit var confirmTemplate: Str
|
val confirmTemplate: Str = this::class.java.getResource("/email/confirm.html")?.readText()
|
||||||
|
?: throw Exception("Email Template Not Found")
|
||||||
|
|
||||||
/**
|
@Async
|
||||||
* Test the connection of the email service on startup
|
@EventListener(ApplicationStartedEvent::class)
|
||||||
*/
|
fun test() {
|
||||||
@PostConstruct
|
|
||||||
fun init() {
|
|
||||||
if (!props.enable) return
|
if (!props.enable) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -55,10 +56,6 @@ class EmailService(
|
||||||
log.error("Email Service Connection Failed", e)
|
log.error("Email Service Connection Failed", e)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load confirm email template
|
|
||||||
confirmTemplate = this::class.java.getResource("/email/confirm.html")?.readText() ?:
|
|
||||||
throw Exception("Email Template Not Found")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue