rajadilipkolli
rajadilipkolli

Reputation: 3601

How to run cron job at users time zone using spring boot

We have users from all over the world using application. Our requirement is to run cron job at 12 am daily at users time zone and only for users in that time zone.

How can this be achieved using spring boot??

Upvotes: 2

Views: 848

Answers (2)

Elisha Senoo
Elisha Senoo

Reputation: 3594

You have to convert all the cron job times (12 am) in the user's time zones, to the equivalent times on your server, by adding or subtracting hours to compensate for the time difference. With the server time zone equivalent of the cron job times, you can schedule all the cron jobs.

Upvotes: 1

kj007
kj007

Reputation: 6254

In @Scheduled notation you can pass Zone but only single time zone so you need to manage it with custom logic.

I believe your user record has included with time zone so to order to achieve it, You will need to set the cron job to run every half an hour(cover all time zones to include + 1/2 an hour), Get all timezones which has midnight then get users in those time zones to run logic for them..

Upvotes: 1

Related Questions