1
0

feat: 改为单次运行

This commit is contained in:
2025-06-19 16:23:23 +08:00
parent f2bad71f1d
commit d87ddfefe6
4 changed files with 3 additions and 33 deletions

View File

@@ -33,7 +33,7 @@ dependencies {
implementation("cn.hutool:hutool-crypto:5.8.16")
implementation("org.springframework.retry:spring-retry")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-mail")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

View File

@@ -2,8 +2,6 @@ package com.lanyuanxiaoyao.messenger
import com.lanyuanxiaoyao.messenger.runner.OdsScreenshotRunner
import jakarta.annotation.Resource
import java.io.File
import org.slf4j.LoggerFactory
import org.springframework.boot.ApplicationArguments
import org.springframework.boot.ApplicationRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
@@ -11,7 +9,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.context.properties.bind.ConstructorBinding
import org.springframework.boot.runApplication
import org.springframework.scheduling.annotation.EnableScheduling
@ConfigurationProperties(prefix = "messenger")
data class TestProperties @ConstructorBinding constructor(
@@ -22,7 +19,6 @@ data class TestProperties @ConstructorBinding constructor(
data class DriverProperties @ConstructorBinding constructor(
val driverPath: String,
val binaryPath: String,
val targetPath: String,
)
@ConfigurationProperties(prefix = "messenger.mail")
@@ -30,35 +26,14 @@ data class MailProperties @ConstructorBinding constructor(
val targets: List<String>,
)
@EnableScheduling
@EnableConfigurationProperties(TestProperties::class, DriverProperties::class, MailProperties::class)
@SpringBootApplication
class MessengerApplication : ApplicationRunner {
private val log = LoggerFactory.getLogger(MessengerApplication::class.java)
@Resource
private lateinit var testProperties: TestProperties
@Resource
private lateinit var driverProperties: DriverProperties
@Resource
private lateinit var runner: OdsScreenshotRunner
override fun run(args: ApplicationArguments?) {
log.info("Target path: {}", driverProperties.targetPath)
if (driverProperties.targetPath.isBlank()) {
throw RuntimeException("Target path is blank")
}
if (!File(driverProperties.targetPath).exists()) {
throw RuntimeException("Target path doesn't exist")
}
if (testProperties.test) {
log.info("Test start")
runner.run()
log.info("Test end")
}
runner.run()
}
}

View File

@@ -4,7 +4,6 @@ import com.lanyuanxiaoyao.messenger.DriverProperties
import com.lanyuanxiaoyao.messenger.MailProperties
import com.lanyuanxiaoyao.messenger.TestProperties
import com.lanyuanxiaoyao.messenger.chrome
import com.lanyuanxiaoyao.messenger.sender.LocalFileSender
import com.lanyuanxiaoyao.messenger.sender.MailSender
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
@@ -83,9 +82,6 @@ class OdsScreenshotRunner(
val targetFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")
val data = driver.getScreenshotAs(OutputType.BYTES)
if (!testProperties.test) {
LocalFileSender(driverProperties.targetPath).send("${targetFormatter.format(now)}.png", data)
}
MailSender(testProperties, mailProperties, javaMailSender).send("ODS 监控截图 ${targetFormatter.format(now)}", data)
}
}

View File

@@ -15,11 +15,10 @@ logging:
pattern:
console: '%date{MM-dd HH:mm:ss} %-5level [%t] %C{35}: %msg%n%throwable'
messenger:
test: true
test: false
driver:
driver-path: /Users/lanyuanxiaoyao/Downloads/chromium/134/macOS-1345775/chromedriver
binary-path: /Users/lanyuanxiaoyao/Downloads/chromium/134/macOS-1345775/Chromium.app/Contents/MacOS/Chromium
target-path: /Users/lanyuanxiaoyao/Desktop
mail:
targets:
# me