Hello to all, I have a question would someone fro...
# server
p
Hello to all, I have a question would someone from you here is experienced to make a cron job in server-side KTOR application? PS> I have few possible solutions, but one of the best which I have currently in my mind is to schedule some job using Coroutines. Thanks in advance for any kind of answers 🚀
a
Depends what you want. Simplest is using a fixed rate timer. Or coroutine with a delay works too
Some frameworks like vertx give you periodic timers built in
There is also something more heavy like quartz
Or you can offload the cron piece to something external like kubernetes or github actions andnonly keep your logic code
p
@asad.awadia I want to use the crons for different features, such for Payment Gateways (repeating transactions), but like the easiest case is to refresh token each hour for the specific provider under the user.
For instance imaging when the user is add some provider and the token has a expiration period only an hour and I have to refresh, for it I have to run different crons per specific provider under specific user.
a
For repeating transactions the payment provider generally gives a higher level construct like recurring billing. You dont have to do it yourself But if yeah a scheduled fixed rate timer should be good enough for your task
The user should request refresh no?
p
no
a
What kind of token is this?
p
Like normal access token for some third party provider.
And the ex.per is only one hour
a
Yeah so you shouldn't refresh tokens like that - they are meant to be short lived
1
p
Regarding the payment transaction not all of the PG are supporting recurring billing unfortunately.
But If I will not refresh it, the client has to make all auth flow one more time, this is not give a sense...
a
When payments are concerned it is better to auth twice. I get where you are coming from - in that case you should have an access token and a refresh token. The access token has a short duration while the refresh token is much longer. If the access token expires the refresh token is sent by the client and a new access token is issued by the server. If the refresh token expires then full login auth flow
p
On the payments for sure! But the question regarding the auth is completely separate question 😄 Yes you right in normal, the refresh token is on the FE side and they are sending to BE for refresh it, but in our case FE doesn't have this refresh token, and the BE has to do it by himself, anyway I have to check the validity of the refresh token per provider, based on that I will understand if I have to create some cron or will be enough to make only normal refresh token flow with 401 handle.
on the payments, I have to create a cron, because one of the PG which we are using on the other project is not supporting recurring billing....
because of that I'm asked for the ideas of how to realise crons in KTOR app. Anyway, thx, for the answers 😉
a
Put your code that has the logic to do the recurring billing in a container and use kubernetes or use lambda with a cloudwatch trigger
p
Mhm...kubernetes I already discussed with our Software Architecture Lead, and they will not use on that project. Also I already found in that channel some replies under this question(https://kotlinlang.slack.com/archives/C0B8RC352/p1611769856055400), maybe I will use something from there also, but the lambda with a cloudwatch trigger is also a point for think. Thx 😉