Is there a way to run Cron Jobs with Ktor? My end ...
# ktor
a
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
Simply launch a coroutine on the application scope with a loop with delay
t
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
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
You need to launch it
Copy code
fun Application.main() {
    launch {
        // polling loop goes here
    }
}
🙏 1
a
Awesome. Can I use
GlobalScope
or
Application
scope?
The loop inside
launch
could be something as simple as
while(true) { ... }