Last active
July 8, 2019 23:09
-
-
Save cmgurba/85039cdff53f20444b3d6fd504f09d5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.c2fo.tpf.job | |
import com.c2fo.tpf.model.graphql.TermSheetApprovedParameters | |
import com.c2fo.tpf.service.ClientService | |
import com.c2fo.tpf.service.EngagementService | |
import com.c2fo.tpf.service.common.ApplicationConfigService | |
import com.c2fo.tpf.service.data.core.JOOQRepository | |
import com.c2fo.tpf.supplierApiModules | |
import io.ktor.http.Url | |
import kotlinx.coroutines.GlobalScope | |
import kotlinx.coroutines.joinAll | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
import org.koin.core.KoinComponent | |
import org.koin.core.context.startKoin | |
import org.koin.core.inject | |
import kotlin.system.measureTimeMillis | |
class K8sTestJobApplication(args: Array<String>) : KoinComponent { | |
val clientService by inject<ClientService>() | |
val engagementService by inject<EngagementService>() | |
val configService by inject<ApplicationConfigService>() | |
val jooqRepository by inject<JOOQRepository>() | |
init { | |
val capitalAppUrl = configService.getString("c2fo.rf.app.url") | |
val qUrl = Url("$capitalAppUrl/receivable-finance/setup") | |
println("args: $args") | |
var emails = listOf("") | |
runBlocking { | |
emails = jooqRepository.jooqTransaction { | |
clientService.getEmailAddressForTermSheetAccepted(this) | |
} | |
} | |
val emailRoutines = emails.map { | |
GlobalScope.launch { | |
var emailParameters = TermSheetApprovedParameters(toEmail = it, completeQuestionnaireUrl = qUrl) | |
engagementService.sendEmail(it, emailParameters, false) | |
} | |
} | |
runBlocking { | |
emailRoutines.joinAll() | |
} | |
} | |
} | |
fun main(args: Array<String>) { | |
startKoin { | |
modules(supplierApiModules + listOf(taskModules)) | |
} | |
val executedTime = measureTimeMillis { | |
try { | |
K8sTestJobApplication(args) | |
} catch (e: Exception) { | |
println("who cares:") | |
e.printStackTrace() | |
} | |
} | |
println("executed time ${executedTime / 1000}s") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment