feat: 改为单次运行
This commit is contained in:
@@ -33,7 +33,7 @@ dependencies {
|
|||||||
implementation("cn.hutool:hutool-crypto:5.8.16")
|
implementation("cn.hutool:hutool-crypto:5.8.16")
|
||||||
|
|
||||||
implementation("org.springframework.retry:spring-retry")
|
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")
|
implementation("org.springframework.boot:spring-boot-starter-mail")
|
||||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package com.lanyuanxiaoyao.messenger
|
|||||||
|
|
||||||
import com.lanyuanxiaoyao.messenger.runner.OdsScreenshotRunner
|
import com.lanyuanxiaoyao.messenger.runner.OdsScreenshotRunner
|
||||||
import jakarta.annotation.Resource
|
import jakarta.annotation.Resource
|
||||||
import java.io.File
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import org.springframework.boot.ApplicationArguments
|
import org.springframework.boot.ApplicationArguments
|
||||||
import org.springframework.boot.ApplicationRunner
|
import org.springframework.boot.ApplicationRunner
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
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.EnableConfigurationProperties
|
||||||
import org.springframework.boot.context.properties.bind.ConstructorBinding
|
import org.springframework.boot.context.properties.bind.ConstructorBinding
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling
|
|
||||||
|
|
||||||
@ConfigurationProperties(prefix = "messenger")
|
@ConfigurationProperties(prefix = "messenger")
|
||||||
data class TestProperties @ConstructorBinding constructor(
|
data class TestProperties @ConstructorBinding constructor(
|
||||||
@@ -22,7 +19,6 @@ data class TestProperties @ConstructorBinding constructor(
|
|||||||
data class DriverProperties @ConstructorBinding constructor(
|
data class DriverProperties @ConstructorBinding constructor(
|
||||||
val driverPath: String,
|
val driverPath: String,
|
||||||
val binaryPath: String,
|
val binaryPath: String,
|
||||||
val targetPath: String,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@ConfigurationProperties(prefix = "messenger.mail")
|
@ConfigurationProperties(prefix = "messenger.mail")
|
||||||
@@ -30,35 +26,14 @@ data class MailProperties @ConstructorBinding constructor(
|
|||||||
val targets: List<String>,
|
val targets: List<String>,
|
||||||
)
|
)
|
||||||
|
|
||||||
@EnableScheduling
|
|
||||||
@EnableConfigurationProperties(TestProperties::class, DriverProperties::class, MailProperties::class)
|
@EnableConfigurationProperties(TestProperties::class, DriverProperties::class, MailProperties::class)
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
class MessengerApplication : ApplicationRunner {
|
class MessengerApplication : ApplicationRunner {
|
||||||
private val log = LoggerFactory.getLogger(MessengerApplication::class.java)
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private lateinit var testProperties: TestProperties
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private lateinit var driverProperties: DriverProperties
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private lateinit var runner: OdsScreenshotRunner
|
private lateinit var runner: OdsScreenshotRunner
|
||||||
|
|
||||||
override fun run(args: ApplicationArguments?) {
|
override fun run(args: ApplicationArguments?) {
|
||||||
log.info("Target path: {}", driverProperties.targetPath)
|
runner.run()
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.lanyuanxiaoyao.messenger.DriverProperties
|
|||||||
import com.lanyuanxiaoyao.messenger.MailProperties
|
import com.lanyuanxiaoyao.messenger.MailProperties
|
||||||
import com.lanyuanxiaoyao.messenger.TestProperties
|
import com.lanyuanxiaoyao.messenger.TestProperties
|
||||||
import com.lanyuanxiaoyao.messenger.chrome
|
import com.lanyuanxiaoyao.messenger.chrome
|
||||||
import com.lanyuanxiaoyao.messenger.sender.LocalFileSender
|
|
||||||
import com.lanyuanxiaoyao.messenger.sender.MailSender
|
import com.lanyuanxiaoyao.messenger.sender.MailSender
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
@@ -83,9 +82,6 @@ class OdsScreenshotRunner(
|
|||||||
|
|
||||||
val targetFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")
|
val targetFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")
|
||||||
val data = driver.getScreenshotAs(OutputType.BYTES)
|
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)
|
MailSender(testProperties, mailProperties, javaMailSender).send("ODS 监控截图 ${targetFormatter.format(now)}", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,10 @@ logging:
|
|||||||
pattern:
|
pattern:
|
||||||
console: '%date{MM-dd HH:mm:ss} %-5level [%t] %C{35}: %msg%n%throwable'
|
console: '%date{MM-dd HH:mm:ss} %-5level [%t] %C{35}: %msg%n%throwable'
|
||||||
messenger:
|
messenger:
|
||||||
test: true
|
test: false
|
||||||
driver:
|
driver:
|
||||||
driver-path: /Users/lanyuanxiaoyao/Downloads/chromium/134/macOS-1345775/chromedriver
|
driver-path: /Users/lanyuanxiaoyao/Downloads/chromium/134/macOS-1345775/chromedriver
|
||||||
binary-path: /Users/lanyuanxiaoyao/Downloads/chromium/134/macOS-1345775/Chromium.app/Contents/MacOS/Chromium
|
binary-path: /Users/lanyuanxiaoyao/Downloads/chromium/134/macOS-1345775/Chromium.app/Contents/MacOS/Chromium
|
||||||
target-path: /Users/lanyuanxiaoyao/Desktop
|
|
||||||
mail:
|
mail:
|
||||||
targets:
|
targets:
|
||||||
# me
|
# me
|
||||||
|
|||||||
Reference in New Issue
Block a user