https://kotlinlang.org logo
#ktor
Title
# ktor
a

Adam Hurwitz

12/30/2019, 10:57 PM
Is there a way to run Cron Jobs with Ktor? My end objective is to host a Cron Job written with Kotlin for the Coinverse Android app's backend service to populate data. Much appreciated! 🙏 https://stackoverflow.com/questions/59516599/how-to-run-cron-jobs-in-kotlin-ktor Also, Google has an interesting alpha outside of Ktor that could be a good alternative for running timed tasks to populate data, Using Kotlin with Google Cloud Functions: https://github.com/GoogleCloudPlatform/kotlin-samples/tree/master/functions
c

cy

12/31/2019, 9:46 AM
Simply launch a coroutine on the application scope with a loop with delay
t

TanVD

12/31/2019, 10:17 AM
For AWS we have pretty much same —
@Scheduled
in #kotless. It will also support cloud-based Cron jobs for Ktor starting with 1.3.0
a

Adam Hurwitz

12/31/2019, 4:08 PM
Thanks @cy and @TanVD! @cy, I'm not looking to build any endpoints to make requests with Ktor. The goal is to run the
Coroutine
inside the
Application.main
method to populate data on a given time frequency. Would this implementation work?
Copy code
import io.ktor.application.Application
fun Application.main() {
    // Coroutine with a loop and delay here.
}
c

cy

12/31/2019, 4:09 PM
You need to launch it
Copy code
fun Application.main() {
    launch {
        // polling loop goes here
    }
}
🙏 1
a

Adam Hurwitz

12/31/2019, 4:12 PM
Awesome. Can I use
GlobalScope
or
Application
scope?
The loop inside
launch
could be something as simple as
while(true) { ... }
52 Views