English 中文(简体)
重新安排使用Quartz的1-Shot工作岗位
原标题:Rescheduling a One-Shot job using Quartz

我不想使用根据时间间隔安排工作,而是在工作完成后重新安排工作。 工作可能在1分钟、2分钟等时间内完成,但需要重新安排到1分钟(或x)之后。

我已经尝试以这种方式使用雷患,但有人开枪。

Scheduling for the first time:

Trigger alertJobTrigger = new SimpleTrigger("alertJobTrigger", 
                                            "triggerGroup1", 
                                            DateTime.UtcNow.AddSeconds(60), 
                                            null, 
                                            0, 
                                            TimeSpan.Zero);
 scheduler.ScheduleJob(alertJobDetail, alertJobTrigger);

在工作完成后重新安排同一工作:

Trigger trigger = Global.scheduler.GetTrigger("alertJobTrigger",
                                              "triggerGroup1");

Trigger newTrigger = new SimpleTrigger("alertJobTrigger",
                                        "triggerGroup1",
                                        trigger.JobName,
                                        trigger.JobGroup,
                                        DateTime.UtcNow.AddSeconds(60), 
                                        null, 
                                        0,
                                        TimeSpan.Zero);     

Global.scheduler.RescheduleJob(trigger.JobName, trigger.JobGroup, newTrigger);
问题回答

如果你需要重新安排工作,重复工作,相当于工作执行时间,那么你必须指示触发者这样做。

否则,如果你需要在同一时间(重复)后执行的工作,那么你可以具体说明<代码>repeatCount=-1和repeat Interval = TimeSpan.From Seconds(.)。 如果解雇工作需要更长时间,则防止同一工作多次执行。 用户可使用<代码>。 DisallowContant Execution] Depende on the main work to prevent that.

Do not create a new Trigger. Use the same trigger while rescheduling. This should work:

Trigger trigger = Global.scheduler.GetTrigger("alertJobTrigger","triggerGroup1");

trigger.set(); //set whichever values you want.

Global.scheduler.RescheduleJob(trigger.JobName, trigger.JobGroup, trigger);




相关问题
Using Aggregate Functions Inside a Trigger In MySQL

I have a People table with several attributes including age . Each time I insert a new tuple into this table, I would like to find out the average age of all the people listed in the table. If the ...

Mysql trigger/events vs Cronjob

I have an auction website which let my users place an unlimited amount of autobiddings. To monitor these autobiddings something has to check the database every second. My question is if it is ...

creation of trigger

I have this trigger procedure CASE_A as UPDATE table1 SET field1 = (SELECT bus FROM view1 WHERE table1.document = view1.document) end; the below trigger is supposed to execute the above ...

Inserting trigger (SQL 2005)

I have a temp table (question_desc, ans1, ans2, ans3, ans4, correct_ans, marks) with say 10 entries. From this table I have to insert values in two other tables: questions (q_id(auto-generated), ...

Before trigger in SQL Server

I have 2 tables: survey (id(PK), name) and survey_to_topic (survey_id(PK,FK,not null), topic_id(PK,FK,not null)). When I try to delete from survey table, I get exception: "The DELETE statement ...

Jquery mouseover/mouseout triggering inconsistently

I have two sortable lists, one being nested, with a mouse over effect on the li elements of the nested sortable list. My problem is that the mouseover and mouseout functions are being called ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签