简体   繁体   English

有没有办法在从 PostgreSQL 数据库表中获取的给定日期时间从 spring 启动自动调用函数?

[英]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:我看到三个选项:

  • Configure Spring Scheduling.配置 Spring 调度。
  • Use Polling.使用轮询。
  • Build your own Scheduler (which I wouldn't).构建您自己的调度程序(我不会)。

Configure Spring Scheduling配置 Spring 调度

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 ;-)不过我自己没试过;-)

Use Polling使用轮询

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.

相关问题 如何从 spring 启动中的实体自动生成表到 shema - how to generate table to shema automatically from entity in spring boot Hibernate 不会在 Spring Boot 中使用 postgresql 自动创建表 - Hibernate not creating Table automatically in spring boot using postgresql 在使用 findall 或其他查询从存储库中获取属性值后更改属性值时,在 Spring 启动 JPA 中禁用数据库更新 - Disable DB Updates in Spring boot JPA when changing the value of a property after it is fetched from the repository using findall or other queries 有没有办法在spring boot中调度一个带参数的函数 - Is there any way to schedule a function with parameters in spring boot Spring-Boot jsonFormat 自动将时间添加到日期字段 - Spring-Boot jsonFormat automatically adds time to the Date field 如何从spring boot应用程序调用oracle函数? - How to call oracle function from spring boot application? 从CircleCi中的Spring Boot访问PostgreSQL 9.6 - Accessing PostgreSQL 9.6 from Spring Boot in CircleCi 使用 spring 引导从 H2 切换到 PostgreSQL - Switching from H2 to PostgreSQL with spring boot 有什么方法可以在Spring-boot应用程序中使用Play DB演变 - Is there any way to use the Play DB evolutions in Spring-boot application 如何调用从 Java 代码返回 TABLE 类型的 postgresql function? - How to call postgresql function that returns TABLE type from Java code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM