如何在Kotlin Ktor中运行Cron Jobs? [英] How to Run Cron Jobs in Kotlin Ktor?

查看:180
本文介绍了如何在Kotlin Ktor中运行Cron Jobs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过 Ktor 运行Cron Jobs?我的最终目标是为 Coinverse应用的后端服务以填充数据.

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 app's backend service to populate data.

我目前在AppEngine上托管多个用Kotlin编写的Java .jar 应用.我正在使用 Cron Job 用于计划任务,因为 .jar 应用程序存在更多的依赖性问题.

I'm currently hosting multiple Java .jar apps written in Kotlin on AppEngine. I'm looking to refactor these apps into Ktor apps on AppEngine with a Cron Job for scheduled tasks, as the .jar apps have more issues with dependencies.

我正在寻找Ktor等效于Cloud Functions'

I'm looking for Ktor's equivalent to Cloud Functions' built-in implementation for Cron Jobs with JavaScript.

functions.pubsub.schedule

备份选项:如果Ktor不具有此功能,而我想将代码保留在Kotlin中,则Google会有一个alpha,

Back-up option: If Ktor does not have this feature and I want to keep the code in Kotlin, Google has an alpha, Using Kotlin with Google Cloud Functions. It appears Kotlin + Cloud Functions' built-in implementation could be used with this approach.

推荐答案

JetBrains小组的谢尔盖·马什科夫(Sergey Mashkov)在 kotlinlang中提出建议 Slack组使用无限循环和

Sergey Mashkov from the JetBrains team suggests in the kotlinlang Slack group to launch a Kotlin Coroutine on the Application scope using an infinite loop and delay.

然后, Ktor 应用可以是

Then, the Ktor app can be deployed to AppEngine.

fun Application.main() {
    launch {
        while(true) {
            delay(600000)
            // Populate data here.
        }
    }
}

这篇关于如何在Kotlin Ktor中运行Cron Jobs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆