石英功能

Quartz capabilities

我正在尝试使用 Java 创建一个 Quartz 调度程序,它将能够调用 API 并传入数据。

我对 Quartz 完全陌生,但现在我理解了 Job 的概念以及如何创建它。我了解触发概念以及如何触发 我了解调度程序的工作原理。

我遇到困难的是如何将需要传递给 API 的信息传递进去。我有一个 API 被调用的示例,数据被输入到数据库中,但信息已被硬编码到 class 中,并被传递到 JobDetails 中。

即。用户向系统传递一条消息,该消息需要在 12 小时内而不是之前发送给用户,所以我计划创建一个作业和一个触发器以将执行时间设置为 12 小时。如何将消息传递给调度程序?这条消息应该存储在哪里?我正在尝试做的事情可能吗?我是否误解了 Quartz 的功能?

感谢您的宝贵时间。如有任何帮助,我们将不胜感激。

看看JobDataMap。如果您为每个用户操作创建一个新作业,您可以将消息存储在其中,该消息将在执行期间可用。

JobDataMap Holds state information for Job instances.

JobDataMap instances are stored once when the Job is added to a scheduler. They are also re-persisted after every execution of jobs annotated with @PersistJobDataAfterExecution.

JobDataMap instances can also be stored with a Trigger. This can be useful in the case where you have a Job that is stored in the scheduler for regular/repeated use by multiple Triggers, yet with each independent triggering, you want to supply the Job with different data inputs.

The JobExecutionContext passed to a Job at execution time also contains a convenience JobDataMap that is the result of merging the contents of the trigger's JobDataMap (if any) over the Job's JobDataMap (if any).

如果您只有一个作业,但您要为每个用户操作创建一个新触发器,则可以按照给定的解决方案 here

第三个选项是,对于每个用户操作,保留消息和时间以将电子邮件发送到数据库。有一个定期运行并扫描数据库以查找必须发送电子邮件的合格记录的作业