0

My Problem is that the scheduled method "subscription" is called twice.

This is the template I use.

https://github.com/JetBrains/gcp-samples/tree/master/google-appengine-sample

When I use $mvn spring-boot:run is working fine in local

But I use $mvn appengine:deploy scheduled is called twice.

My code:

@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...
                }
            }
        }
    }
}

My app.yaml:

runtime: java
env: flex
runtime_config:
  jdk: openjdk8

2 Answers2

0

I check my GCP.

I have two instances in the same version.

Is this related?

0

Check is there any two instance of your server? this cron job will be unique for only one server.