Hello all, I am new to Kotlin.. I have a rest API ...
# server
s
Hello all, I am new to Kotlin.. I have a rest API built on Javalin..I want to add a feature which takes customer details from DB and charges them fees on first of every month..but it shouldn't be a endpoint to be triggered by a cron job from someplace else..it should be internal to the app (should be in another thread, I guess since rest endpoints will be maintained by one thread??) How do I go about this?
y
you probably need a job-scheduler. it will be triggered internally. try to put the scheduler code in the main func, before starting the server. you can do it with plain java classes: https://stackoverflow.com/questions/22163662/how-to-create-a-java-cron-job or using quartz library http://www.quartz-scheduler.org/documentation/quartz-2.3.0/quick-start.html
s
@Yevgeni Liskovich thank you for this information.. Could you please let me know how do I add quartz dependency in build.gradle.kts file..I have tried multiple things and still getting errors (sorry for such a dumb question..I am new to the whole Java vertical as such..coming from python)
y
you need to add: implementation(“org.quartz-schedulerquartz2.3.2”) under dependencies scope: dependencies { implementation(“org.quartz-schedulerquartz2.3.2") }
a
If your use case is not too intense - you maybe able to get by with a scheduleAtFixedRateTimer thing directly in main (at startup of app) that scans your DB and does the work