Using spring boot, JPA, angular, PostgreSQL
Want to run the process automatically at particular date and time fetch from DB, and update status in DB accordingly
Purpose : We are giving 15 days free registration, let say user registered at 13th Dec., 13:05 then server should stop all the process of that user from 27th Dec., 13:05.
How can I call my function from spring boot automatically at 27th Dec., 13:05 (Available in PostgreSQL DB table)
I have tried scheduler with @Scheduled annotation also, but it runs after given interval of time.
Please suggest or hint any way to achieve this functionality.
I see three options:
- Configure Spring Scheduling.
- Use Polling.
- Build your own Scheduler (which I wouldn't).
Configure Spring Scheduling
You might implement a SchedulingConfigurer
and use the provided ScheduledTaskRegistrar
accordingly.
You should be able to add new cron tasks with addCronTask
or probably refresh all with setCronTask.
I haven't tried it myself though ;-)
Use Polling
If that doesn't work you might fall back to polling with a select min(next_job_date) from jobs;
to find the next job and start it when its ready.