0
votes

I have a Node.JS GAE service running with a CRON process that sends messages. GAE spins up multiple instances which results in multiple messages being sent.

Ideally my code could "see" that it's an additional instance and suppress the messages? Is there any way that my code can determine this? Otherwise I will have to co-ordinate the instances via some sort of external resource (shared memory / DB etc)...

1

1 Answers

1
votes

While it might be possible to obtain the information about the other instances running (for example via the Admin API apps.services.versions.instances.list method), that info alone won't be sufficient to properly implement the logic you seek - if there are multiple instances running at the time your instance-dependent "CRON processes" fire the logic will produce the same results on all instances, you still need some coordination to determine which of the running instances is "the master" one on which the messages should be sent, most likely based on some external resource. Not trivial if you take into consideration the possibility of instances dying/starting up at any time, including while the CRON processes are in progress.

I'd suggest using the GAE cron service instead (look for a section name containing Scheduling in the left side navigation bar on the documentation pages for your particular runtime) or, if you prefer, Cloud Tasks, neither of which will multiply the work depending on the number of running instances, thus completely avoiding the issue.

Note that you will still need to take care of possible retries in the event of failure in handling the cron requests, your cron jobs should be idempotent.