我的问题是调度方法“订阅”被调用两次。
这是我使用的模板。
https://github.com/JetBrains/gcp-samples/tree/master/google-appengine-sample
当我使用$mvn spring-boot:run
在当地工作正常
但我使用$mvn appengine:deploy
预定被召唤两次。
我的代码:
@Component
class ScheduledTasks {
@Scheduled(cron = "0 0 * * * *")
fun subscription() {
var hasBeenInitialized = false
val firebaseApps = FirebaseApp.getApps()
for (app in firebaseApps) {
if (app.name == FirebaseApp.DEFAULT_APP_NAME) {
hasBeenInitialized = true
}
}
if(!hasBeenInitialized) {
InitializeGCP()
}
var db = FirestoreClient.getFirestore()
val query = db.collection("subscription").get()
val querySnapshot = query.get()
val documents = querySnapshot.documents
for (document in documents) {
if (localTime.equals(document.getString("time"))) {
...post to my ChatBot Api...
}
}
}
}
}
我的app.yaml:
runtime: java
env: flex
runtime_config:
jdk: openjdk8
检查你的服务器有两个实例吗?这个cron作业对于一个服务器来说是唯一的。
我查看了我的GCP。
我在同一版本中有两个实例。
这有关系吗?