Skip to content

Commit

Permalink
feat: #92 batch function bean 으로 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
KarmaPol committed Mar 21, 2024
1 parent 2dcd047 commit 2df6608
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
32 changes: 20 additions & 12 deletions infra/infra-lambda/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,28 @@ dependencies {
implementation("org.springframework.boot.experimental:spring-boot-thin-layout:1.0.28.RELEASE")
}

configurations {
create("shaded")
tasks.withType<Jar> {
// Spring Application 시작점
manifest {
attributes["Start-Class"] = "com.kw.infralamda.LambdaBatchApplication"
}
}

val shade by tasks.registering(Jar::class) {
from(configurations["shaded"].map { if (it.isDirectory) it else zipTree(it) })
configurations["shaded"].forEach { dep ->
from(dep) {
exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
}
}
archiveClassifier.set("aws")
tasks.assemble {
dependsOn("shadowJar")
}

artifacts {
add("archives", shade)
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
archiveFileName.set("batch.jar")
dependencies {
exclude("org.springframework.cloud:spring-cloud-function-web")
}
mergeServiceFiles()
append("META-INF/spring.handlers")
append("META-INF/spring.schemas")
append("META-INF/spring.tooling")
transform(com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer::class.java) {
paths.add("META-INF/spring.factories")
mergeStrategy = "append"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ import com.kw.data.domain.bundle.Bundle
import com.kw.data.domain.bundle.repository.BundleRepository
import com.kw.data.domain.question.Question
import com.kw.data.domain.question.repository.QuestionRepository
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import java.util.function.Consumer
import kotlin.math.pow

@Component
@Transactional
class LambdaConsumer(private val questionRepository: QuestionRepository,
private val bundleRepository: BundleRepository): Consumer<Any>
private val bundleRepository: BundleRepository)
{
private val G = 0.8
private val EXPOSECOUNT_WEIGHT = 1
private val SHARECOUNT_WEIGHT = 1
private val VIEWCOUNT_WEIGHT = 1
private val SCRAPCOUNT_WEIGHT = 1

override fun accept(t: Any) {
updateQuestionPopularity()
updateBundlesPopularity()
@Bean
fun batchPopularity(): () -> Unit {
return {
updateQuestionPopularity()
updateBundlesPopularity()
}
}

private fun updateBundlesPopularity() {
Expand Down
4 changes: 3 additions & 1 deletion infra/infra-lambda/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ spring:
active: dev
cloud:
function:
definition: lambdaConsumer
definition: batchPopularity
main:
banner-mode: off
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kw.infralamda

import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class InfraLamdaApplicationTests {

@Test
fun contextLoads() {
}

}

0 comments on commit 2df6608

Please sign in to comment.