[英]Is there any way to call function automatically from spring boot, at given date time fetched from PostgreSQL DB table?
Using spring boot, JPA, angular, PostgreSQL使用 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.目的:我们提供 15 天免费注册,假设用户在 12 月 13 日 13:05 注册,那么服务器应该从 12 月 27 日 13:05 停止该用户的所有进程。
How can I call my function from spring boot automatically at 27th Dec., 13:05 (Available in PostgreSQL DB table)如何在 12 月 27 日 13:05 从 spring boot 自动调用我的函数(在 PostgreSQL DB 表中可用)
I have tried scheduler with @Scheduled annotation also, but it runs after given interval of time.我也尝试过带有 @Scheduled 注释的调度程序,但它在给定的时间间隔后运行。
Please suggest or hint any way to achieve this functionality.请建议或提示任何方式来实现此功能。
I see three options:我看到三个选项:
You might implement a SchedulingConfigurer
and use the provided ScheduledTaskRegistrar
accordingly.您可以实现
SchedulingConfigurer
并相应地使用提供的ScheduledTaskRegistrar
。
You should be able to add new cron tasks with addCronTask
or probably refresh all with setCronTask.您应该能够使用
addCronTask
添加新的 cron 任务,或者使用addCronTask
刷新所有任务。
I haven't tried it myself though ;-)不过我自己没试过;-)
If that doesn't work you might fall back to polling with a select min(next_job_date) from jobs;
如果这不起作用,您可能会退回到使用
select min(next_job_date) from jobs;
进行轮询select min(next_job_date) from jobs;
to find the next job and start it when its ready.找到下一份工作并在准备好后开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.