Is this an ok way to run backround tasks in ktor? ...
# ktor
k
Is this an ok way to run backround tasks in ktor?
Copy code
suspend fun Application.runJobs(jobService: JobService) {
    withContext(this.coroutineContext) {
        launch {
            while (true) {
                delay(1000)
                println("hello")
            }
        }
    }
}
s
Application
extends
CoroutineScope
so the
withContext
is not needed afaik. That is the correct way to run background jobs that need to have same lifecycle as
Application
.
๐Ÿ™Œ 1
k
Yeah you're right. I am trying to add some scheduled tasks like Quartz provide, but I have always felt that Quartz is a bit heavy handed so I am hoping I can keep it simple with coroutines ๐Ÿ™‚
Creating an ETL application with Ktor and Arrow, great experience so far!
s
Awesome ๐Ÿ™Œ I don't have much experience with Quartz, but I am very happy with Ktor and KotlinX Coroutines. It's much simpler than any other similar library I worked with in Java. Also love Arrow but I am a bit biased ๐Ÿ˜œ
arrow 1
k
I watched the videos you did with Jetbrains recently. I had chosen a stack of Ktor/Arrow/SQLDelight a long time ago for some small microservice. And after I finished it I saw you had made some videos with JetBrains... Had to do some refactoring after I watched them. Really good stuff, keep it up!
๐Ÿ™๐Ÿพ 1
๐Ÿ™ 1
a
@Kristian Nedrevold can you kindly drop a link to the video?.
s

https://www.youtube.com/watch?v=g79A6HmbW5Mโ–พ

๐Ÿ’ฏ 1