Fixed minor key mistake.

This commit is contained in:
Christian P. MOMON 2018-09-21 18:34:42 +02:00
parent f2f9bceae5
commit d2a1f6b340
2 changed files with 38 additions and 7 deletions

View File

@ -37,7 +37,7 @@ irc.channel=#april-test
notify.at15.cron=0 45 11 ? * * notify.at15.cron=0 45 11 ? * *
notify.at15.irc=Revue hebdomadaire dans 15 minutes notify.at15.irc=Revue hebdomadaire dans 15 minutes
notify.at15.twitter=Revue hebdomadaire April à 12h sur notre salon : http://april.org/salon-irc-de-lapril\nCette revue ne dure qu\'une quinzaine de minutes et permet d\'avoir une idée des actions en cours et à venir.\nVous pouvez aussi juste nous faire un coucou. Et ça met en appétit :) notify.at15.twitter=Revue hebdomadaire April à 12h sur notre salon : http://april.org/salon-irc-de-lapril\nCette revue ne dure qu\'une quinzaine de minutes et permet d\'avoir une idée des actions en cours et à venir.\nVous pouvez aussi juste nous faire un coucou. Et ça met en appétit :)
notify.at5.image=/srv/foo/photo-pizza.jpg notify.at15.image=/srv/foo/photo-pizza.jpg
#notify.at30.cron=0 30 11 ? * * #notify.at30.cron=0 30 11 ? * *
#notify.at30.irc=Revue hebdomadaire dans 30 minutes #notify.at30.irc=Revue hebdomadaire dans 30 minutes

View File

@ -19,18 +19,23 @@
*/ */
package org.april.hebdobot.cron; package org.april.hebdobot.cron;
import java.util.Date;
import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.Hebdobot;
import org.quartz.CronScheduleBuilder; import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder; import org.quartz.JobBuilder;
import org.quartz.JobDetail; import org.quartz.JobDetail;
import org.quartz.Scheduler; import org.quartz.Scheduler;
import org.quartz.SchedulerException; import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger; import org.quartz.Trigger;
import org.quartz.TriggerBuilder; import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
import org.quartz.TriggerListener; import org.quartz.TriggerListener;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.StdSchedulerFactory; import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.KeyMatcher; import org.quartz.impl.matchers.KeyMatcher;
import org.quartz.impl.triggers.SimpleTriggerImpl;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -77,13 +82,39 @@ public class CronManager
*/ */
public void addCron(final CronValue cron) throws SchedulerException public void addCron(final CronValue cron) throws SchedulerException
{ {
Trigger trigger = TriggerBuilder.newTrigger().withDescription(cron.getName()).withIdentity(cron.getName()) {
.withSchedule(CronScheduleBuilder.cronSchedule(cron.getCron())).build(); final JobDetailImpl jobDetail = new JobDetailImpl();
JobDetail job = JobBuilder.newJob(CronFooJob.class).withIdentity(cron.getName()).build(); jobDetail.setName("Mon job");
this.scheduler.scheduleJob(job, trigger); jobDetail.setJobClass(CronFooJob.class);
TriggerListener listener = new CronListener(this.bot, cron); JobDetail job = JobBuilder.newJob(CronFooJob.class).withIdentity(cron.getName()).build();
this.scheduler.getListenerManager().addTriggerListener(listener, KeyMatcher.keyEquals(new TriggerKey(cron.getName())));
{
final SimpleTriggerImpl trigger = new SimpleTriggerImpl();
trigger.setName("Trigger execution toutes les 5 secondes");
trigger.setDescription("Foo");
trigger.setStartTime(new Date(System.currentTimeMillis() + 1000));
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
trigger.setRepeatInterval(5000);
}
{
TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger();
builder.withDescription(cron.getName());
builder.withIdentity(cron.getName());
builder.withSchedule(CronScheduleBuilder.cronSchedule(cron.getCron()));
Trigger trigger = builder.build();
}
}
{
Trigger trigger = TriggerBuilder.newTrigger().withDescription(cron.getName()).withIdentity(cron.getName())
.withSchedule(CronScheduleBuilder.cronSchedule(cron.getCron())).build();
JobDetail job = JobBuilder.newJob(CronFooJob.class).withIdentity(cron.getName()).build();
this.scheduler.scheduleJob(job, trigger);
TriggerListener listener = new CronListener(this.bot, cron);
this.scheduler.getListenerManager().addTriggerListener(listener, KeyMatcher.keyEquals(new TriggerKey(cron.getName())));
}
logger.info("Added cron value: " + cron.getName()); logger.info("Added cron value: " + cron.getName());
} }