gpt4 book ai didi

quartz-scheduler - Quartz 工作依赖

转载 作者:行者123 更新时间:2023-12-04 08:33:14 26 4
gpt4 key购买 nike

我正在使用 Quartz 进行一个项目,并且一直存在与作业的依赖关系的问题。

我们有一个设置,其中 A 和 B 不相互依赖,但 C 是:

A 和 B 可以同时运行,但 C 只能在 A 和 B 都完成的情况下运行。

有没有办法在 Quartz 中设置这种场景,这样 C 只会在 A 和 B 完成时触发?

最佳答案

我认为这是目前的做法:
http://www.quartz-scheduler.org/documentation/faq#FAQ-chain

基于此 FAQ,您可以创建一个等待 A 和 B 完成的作业监听器,然后在发生这种情况后安排作业 C。

PS:这是链接更改时的文本:

How do I chain Job execution? Or, how do I create a workflow?

There currently is no "direct" or "free" way to chain triggers with Quartz. However there are several ways you can accomplish it without much effort. Below is an outline of a couple approaches:

One way is to use a listener (i.e. a TriggerListener, JobListener or SchedulerListener) that can notice the completion of a job/trigger and then immediately schedule a new trigger to fire. This approach can get a bit involved, since you'll have to inform the listener which job follows which - and you may need to worry about persistence of this information. See the listener org.quartz.listeners.JobChainingJobListener which ships with Quartz - as it already has some of this functionality.

Another way is to build a Job that contains within its JobDataMap the name of the next job to fire, and as the job completes (the last step in its execute() method) have the job schedule the next job. Several people are doing this and have had good luck. Most have made a base (abstract) class that is a Job that knows how to get the job name and group out of the JobDataMap using pre-defined keys (constants) and contains code to schedule the identified job. This abstract Job's implementation of execute() delegates to an abstract template method such as "doWork()" (where the extending Job class's real work goes) and then it contains the code for scheduling the follow-up job. Then they simply make extensions of this class that included the work the job should do. The usage of 'durable' jobs, or the overloaded addJob(JobDetail, boolean, boolean) method (added in Quartz 2.2) helps the application define all the jobs at once with their proper data, without yet creating triggers to fire them (other than one trigger to fire the first job in the chain).

In the future, Quartz will provide a much cleaner way to do this, but until then, you'll have to use one of the above approaches, or think of yet another that works better for you.

关于quartz-scheduler - Quartz 工作依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14342408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com