Hey Everyone, I'm attempting to have my Ktor app's...
# server
a
Hey Everyone, I'm attempting to have my Ktor app's main method run once deployed to AppEngine. Currently the Ktor application's main method is only called when the app's hosted route is called: https://[yourProjectName].appspot.com. In the applications's main method is logic to retrieve content from an API request based on a Timer and save that information to a Firestore database which a client consumes. Thanks for the help! 🙂
r
Which kind of scaling do you use for your AppEngine ? Reading https://cloud.google.com/appengine/docs/standard/go/how-instances-are-managed leads me to believe "instances are created on demand to handle requests" means that no request = no startup, so you wouldn't be able to do anything to force it to start from the kotlin/ktor/gradle side of things
n
#ktor ?
👍 1
k
added an answer on SO. You probably need to set up a Java style static main method.
a
Thank you @rlejolivet. The instance I deployed is set to autoscaled. In contrast, when I deploy a compiled Jar to GCP with autoscaled enabled it runs the main method from the start which is the behavior I'm trying to replicate with ktor.
@kenkyee Thanks! If I setup a Java style main static method the app runs as expected in IntelliJ. However, deploying the Java main static method with Ktor, GCP cannot find the main method. It appears the Ktor main configuration is required if deploying with Ktor. • Java style main configuration (works locally): object Initialization { @JvmStatic fun main(args: Array<String>) { // App logic here. } } • Ktor main configuration (works on GCP only when you go to the hosted endpoint https://[yourProjectName].appspot.com): import io.ktor.application.Application fun Application.main() { // App logic here. }
k
Maybe try having the Java main call the ktor Application.main?
a
@kenkyee IntelliJ won't allow that unfortunately.
I shall repost in the #ktor channel as this is question is a better fit there and I did not see that channel originally.
👍 2
b
What are you using to execute your
embeddedServer
?