Search in sources :

Example 1 with SimpleTrigger

use of org.quartz.SimpleTrigger in project head by mifos.

the class BatchjobsServiceFacadeWebTier method getBatchjobs.

@Override
public List<BatchjobsDto> getBatchjobs(ServletContext context) throws TaskSystemException, FileNotFoundException, IOException, SchedulerException {
    List<BatchjobsDto> batchjobs = new ArrayList<BatchjobsDto>();
    MifosScheduler mifosScheduler = (MifosScheduler) context.getAttribute(MifosScheduler.class.getName());
    Scheduler scheduler = mifosScheduler.getScheduler();
    for (String groupName : scheduler.getJobGroupNames()) {
        for (String jobName : scheduler.getJobNames(groupName)) {
            Trigger[] triggers = scheduler.getTriggersOfJob(jobName, groupName);
            Trigger trigger = triggers.length > 0 ? triggers[0] : null;
            JobDetail jobDetail = scheduler.getJobDetail(jobName, groupName);
            if (trigger != null && jobDetail != null) {
                Date nextFire = trigger.getNextFireTime() != null ? trigger.getNextFireTime() : new Date(0);
                Date lastFire = mifosScheduler.getJobsPreviousRunTime(jobName);
                Date lastSuccessfulRun = mifosScheduler.getJobsLastSuccessfulRunTime(jobName);
                int priority = trigger.getPriority();
                String frequency = "";
                String taskType = "";
                if (trigger instanceof CronTrigger) {
                    frequency = ((CronTrigger) trigger).getCronExpression();
                    taskType = CRON_TRIGGER;
                }
                if (trigger instanceof SimpleTrigger) {
                    frequency = Long.toString(((SimpleTrigger) trigger).getRepeatInterval());
                    taskType = SIMPLE_TRIGGER;
                }
                String previousRunStatus = mifosScheduler.getJobsPreviousRunStatus(jobName);
                int triggerState = scheduler.getTriggerState(trigger.getName(), groupName);
                String failDescription = mifosScheduler.getJobFailDescription(jobName);
                batchjobs.add(new BatchjobsDto(jobName, frequency, taskType, priority, previousRunStatus, lastFire, lastSuccessfulRun, nextFire, triggerState, failDescription));
            }
        }
    }
    return batchjobs;
}
Also used : CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) ArrayList(java.util.ArrayList) BatchjobsDto(org.mifos.application.admin.servicefacade.BatchjobsDto) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) Date(java.util.Date) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger)

Example 2 with SimpleTrigger

use of org.quartz.SimpleTrigger in project head by mifos.

the class MifosBatchJob method computeMissedJobLaunches.

@SuppressWarnings("unchecked")
public List<Date> computeMissedJobLaunches(Date from, Date to, Trigger trigger, boolean onDemandRun) throws Exception {
    List<Date> missedLaunches = new LinkedList<Date>();
    if (trigger instanceof CronTrigger) {
        CronTrigger cronTrigger = new CronTrigger();
        cronTrigger.setStartTime(from);
        cronTrigger.setNextFireTime(from);
        String cronExpression = ((CronTrigger) trigger).getCronExpression();
        try {
            cronTrigger.setCronExpression(cronExpression);
        } catch (ParseException pe) {
            throw new Exception(pe);
        }
        List<Date> computationOutcome = TriggerUtils.computeFireTimesBetween(cronTrigger, null, from, to);
        missedLaunches.addAll(computationOutcome);
        missedLaunches.remove(0);
        if (!onDemandRun && missedLaunches.size() > 0) {
            missedLaunches.remove(missedLaunches.size() - 1);
        }
    } else if (trigger instanceof SimpleTrigger) {
        SimpleTrigger simpleTrigger = new SimpleTrigger();
        simpleTrigger.setStartTime(from);
        simpleTrigger.setNextFireTime(from);
        simpleTrigger.setRepeatInterval(((SimpleTrigger) trigger).getRepeatInterval());
        simpleTrigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
        List<Date> computationOutcome = TriggerUtils.computeFireTimesBetween(simpleTrigger, null, from, to);
        missedLaunches.addAll(computationOutcome);
        missedLaunches.remove(0);
        if (!onDemandRun && missedLaunches.size() > 0) {
            missedLaunches.remove(missedLaunches.size() - 1);
        }
    }
    return missedLaunches;
}
Also used : CronTrigger(org.quartz.CronTrigger) LinkedList(java.util.LinkedList) List(java.util.List) ParseException(java.text.ParseException) SimpleTrigger(org.quartz.SimpleTrigger) LinkedList(java.util.LinkedList) Date(java.util.Date) ParseException(java.text.ParseException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) JobExecutionException(org.quartz.JobExecutionException) JobInstanceAlreadyCompleteException(org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException)

Example 3 with SimpleTrigger

use of org.quartz.SimpleTrigger in project openhab1-addons by openhab.

the class MapDBPersistenceService method scheduleJob.

/**
     * Schedules new quartz scheduler jobs for committing transactions and
     * backing up the database
     */
private void scheduleJob() {
    try {
        Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
        // schedule commit-job
        JobDetail job = newJob(CommitJob.class).withIdentity("Commit_Transaction", SCHEDULER_GROUP).build();
        SimpleTrigger trigger = newTrigger().withIdentity("Commit_Transaction", SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(commitInterval)).build();
        sched.scheduleJob(job, trigger);
        logger.debug("Scheduled Commit-Job with interval {}sec.", commitInterval);
    } catch (SchedulerException e) {
        logger.warn("Could not create Job: {}", e.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 4 with SimpleTrigger

use of org.quartz.SimpleTrigger in project openhab1-addons by openhab.

the class GCalPersistenceService method scheduleUploadJob.

/**
     * Schedules new quartz scheduler job for uploading calendar entries to Google
     */
private void scheduleUploadJob() {
    try {
        scheduler = StdSchedulerFactory.getDefaultScheduler();
        JobDetail job = newJob(SynchronizationJob.class).withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP).build();
        SimpleTrigger trigger = newTrigger().withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(uploadInterval)).build();
        scheduler.scheduleJob(job, trigger);
        logger.debug("Scheduled Google Calendar Upload-Job with interval '{}'", uploadInterval);
    } catch (SchedulerException e) {
        logger.warn("Could not create Google Calendar Upload-Job: {}", e.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) SimpleTrigger(org.quartz.SimpleTrigger)

Example 5 with SimpleTrigger

use of org.quartz.SimpleTrigger in project openhab1-addons by openhab.

the class Db4oPersistenceService method scheduleJob.

/**
     * Schedules new quartz scheduler jobs for committing transactions and
     * backing up the database
     */
private void scheduleJob() {
    try {
        Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
        // schedule commit-job
        JobDetail job = newJob(CommitJob.class).withIdentity("Commit_Transaction", SCHEDULER_GROUP).build();
        SimpleTrigger trigger = newTrigger().withIdentity("Commit_Transaction", SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(commitInterval)).build();
        sched.scheduleJob(job, trigger);
        logger.debug("Scheduled Commit-Job with interval {}sec.", commitInterval);
        // schedule backup-job
        JobDetail backupJob = newJob(BackupJob.class).withIdentity("Backup_DB", SCHEDULER_GROUP).build();
        CronTrigger backupTrigger = newTrigger().withIdentity("Backup_DB", SCHEDULER_GROUP).withSchedule(CronScheduleBuilder.cronSchedule(backupInterval)).build();
        sched.scheduleJob(backupJob, backupTrigger);
        logger.debug("Scheduled Backup-Job with cron expression '{}'", backupInterval);
    } catch (SchedulerException e) {
        logger.warn("Could not create Job: {}", e.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Aggregations

SimpleTrigger (org.quartz.SimpleTrigger)75 CronTrigger (org.quartz.CronTrigger)27 SchedulerException (org.quartz.SchedulerException)27 JobDetail (org.quartz.JobDetail)24 Date (java.util.Date)22 Scheduler (org.quartz.Scheduler)21 Trigger (org.quartz.Trigger)20 Test (org.junit.Test)11 JobDataMap (org.quartz.JobDataMap)11 ArrayList (java.util.ArrayList)9 JobDetailBean (org.springframework.scheduling.quartz.JobDetailBean)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 SimpleDateFormat (java.text.SimpleDateFormat)5 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)5 DatasetDAO (org.akaza.openclinica.dao.extract.DatasetDAO)5 TriggerKey (org.quartz.TriggerKey)5 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)4 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)4