Make Spring Quartz Job Scheduler Run User Action

I use the Spring Quartz Job Scheduler to run jobs on user-selected days. Instead of automatically invoking the task scheduler when the application starts, I need the task scheduler to start on a specific user action.

<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
      <property name="triggers">
            <list>
            <ref bean="testme"/>
           </list>
      </property>     
</bean>

<bean id="testme" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref bean="testme1"/>
        </property>
        <property name="cronExpression">
            <value>0 15 10 1,15 * ?</value>  
        </property>
</bean>

I also need the first user to select the dates necessary to complete the task, for example: Monday and Friday, and then, after clicking the submit button, will the scheduler start from this moment? CronExpression values ​​also change based on user-selected dates. Moreover, the user can later change it to different dates. So can this be done, or is Quartz Job Scheduler not suitable for achieving what I need?

+4
2

CronTriggerBean testme
cronExpression. , .

0

. , , .

, . , Quartz Job Scheduler - , ?

. .

SchedulerFactoryBean bean. SchedulerFactoryBean /:

Scheduler scheduler = schedulerFactory.getScheduler();
JobDetail job = scheduler.getJobDetail("yourJobName", "yourJobGroup");

// possibly do some stuff with the JobDetail...

// get the current trigger
CronTrigger cronTrigger = (CronTrigger) scheduler.getTrigger("yourTriggerName", "yourTriggerGroupName");

// possibly do some stuff with the current Trigger...
if (cronTrigger != null)
   something.doSomeStuff();

// replace the old trigger with a new one.  unless your users are sysadmins, they
// probably don't want to enter cron-type entries.  there are other trigger types
// besides CronTrigger. RTFM and pick the best one for your needs
CronTrigger newTrigger = new CronTrigger();
newTrigger.setName("newTriggerName");
newTrigger.setGroup("yourTriggerGroup");
newTrigger.setCronExpression("valid cron exp here");

// the new trigger must reference the job by name and group
newTrigger.setJobName("yourJobName");
newTrigger.setJobGroup("yourJobGroup");

// replace the old trigger.  this is by name, make sure it all matches up.
scheduler.rescheduleJob("yourJobName",  "yourTriggerGroup", newTrigger);
0

Source: https://habr.com/ru/post/1528936/


All Articles