Search in sources :

Example 26 with TriggerKey

use of org.quartz.TriggerKey in project jbpm by kiegroup.

the class DeploymentsAwareStdJDBCDelegate method selectTriggerToAcquire.

@Override
public List<TriggerKey> selectTriggerToAcquire(Connection conn, long noLaterThan, long noEarlierThan, int maxCount) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;
    List<TriggerKey> nextTriggers = new LinkedList<TriggerKey>();
    try {
        List<String> deploymentIds = quartzUtils.getDeployments();
        ps = conn.prepareStatement(rtp(quartzUtils.nextTriggerQuery(deploymentIds)));
        // Set max rows to retrieve
        if (maxCount < 1)
            // we want at least one trigger back.
            maxCount = 1;
        ps.setMaxRows(maxCount);
        // Try to give jdbc driver a hint to hopefully not pull over more than the few rows we actually need.
        // Note: in some jdbc drivers, such as MySQL, you must set maxRows before fetchSize, or you get exception!
        ps.setFetchSize(maxCount);
        ps.setString(1, STATE_WAITING);
        ps.setBigDecimal(2, new BigDecimal(String.valueOf(noLaterThan)));
        ps.setBigDecimal(3, new BigDecimal(String.valueOf(noEarlierThan)));
        int index = 4;
        for (String deployment : deploymentIds) {
            ps.setString(index++, deployment);
        }
        rs = ps.executeQuery();
        while (rs.next() && nextTriggers.size() <= maxCount) {
            nextTriggers.add(triggerKey(rs.getString(COL_TRIGGER_NAME), rs.getString(COL_TRIGGER_GROUP)));
        }
        return nextTriggers;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) LinkedList(java.util.LinkedList) BigDecimal(java.math.BigDecimal)

Example 27 with TriggerKey

use of org.quartz.TriggerKey in project jbpm by kiegroup.

the class DeploymentsAwareStdJDBCDelegate method selectMisfiredTriggersInState.

@Override
public List<TriggerKey> selectMisfiredTriggersInState(Connection conn, String state, long ts) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        List<String> deploymentIds = quartzUtils.getDeployments();
        ps = conn.prepareStatement(rtp(quartzUtils.misfiredTriggersQuery(deploymentIds)));
        ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts)));
        ps.setString(2, state);
        int index = 3;
        for (String deployment : deploymentIds) {
            ps.setString(index++, deployment);
        }
        rs = ps.executeQuery();
        LinkedList<TriggerKey> list = new LinkedList<TriggerKey>();
        while (rs.next()) {
            String triggerName = rs.getString(COL_TRIGGER_NAME);
            String groupName = rs.getString(COL_TRIGGER_GROUP);
            list.add(triggerKey(triggerName, groupName));
        }
        return list;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) LinkedList(java.util.LinkedList)

Example 28 with TriggerKey

use of org.quartz.TriggerKey in project openolat by klemens.

the class StatisticsAdminController method refreshUIState.

private void refreshUIState() {
    log_.info("refreshUIState: schedulerFactoryBean found");
    boolean enabled = false;
    String cronExpression = "";
    Trigger.TriggerState triggerState;
    try {
        TriggerKey triggerKey = new TriggerKey("updateStatisticsTrigger", null);
        triggerState = scheduler.getTriggerState(triggerKey);
        enabled = triggerState != Trigger.TriggerState.NONE && triggerState != Trigger.TriggerState.ERROR;
        Trigger trigger = scheduler.getTrigger(triggerKey);
        if (trigger == null) {
            enabled &= false;
        } else {
            enabled &= trigger.getJobKey().getName().equals("org.olat.statistics.job.enabled");
            if (trigger instanceof CronTrigger) {
                log_.info("refreshUIState: org.olat.statistics.job.enabled check, enabled now: " + enabled);
                cronExpression = ((CronTrigger) trigger).getCronExpression();
            }
        }
        log_.info("refreshUIState: updateStatisticsTrigger state was " + triggerState + ", enabled now: " + enabled);
    } catch (SchedulerException e) {
        log_.warn("refreshUIState: Got a SchedulerException while asking for the updateStatisticsTrigger's state", e);
    }
    StatisticUpdateManager statisticUpdateManager = getStatisticUpdateManager();
    if (statisticUpdateManager == null) {
        log_.info("refreshUIState: statisticUpdateManager not configured");
        enabled = false;
    } else {
        enabled &= statisticUpdateManager.isEnabled();
        log_.info("refreshUIState: statisticUpdateManager configured, enabled now: " + enabled);
    }
    if (enabled) {
        content.contextPut("status", getTranslator().translate("statistics.status.enabled", new String[] { cronExpression }));
    } else {
        content.contextPut("status", getTranslator().translate("statistics.status.disabled"));
    }
    content.contextPut("statisticEnabled", enabled);
    recalcLastUpdated();
    updateStatisticUpdateOngoingFlag();
}
Also used : TriggerKey(org.quartz.TriggerKey) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) StatisticUpdateManager(org.olat.course.statistic.StatisticUpdateManager)

Example 29 with TriggerKey

use of org.quartz.TriggerKey in project ovirt-engine by oVirt.

the class SchedulerUtilBaseImpl method triggerJob.

@Override
public void triggerJob(String jobId) {
    try {
        List<? extends Trigger> existingTriggers = sched.getTriggersOfJob(jobKey(jobId, Scheduler.DEFAULT_GROUP));
        if (!existingTriggers.isEmpty()) {
            // Note: we assume that every job has exactly one trigger
            Trigger oldTrigger = existingTriggers.get(0);
            TriggerKey oldTriggerKey = oldTrigger.getKey();
            Trigger newTrigger = newTrigger().withIdentity(oldTriggerKey).startAt(getFutureDate(0, TimeUnit.MILLISECONDS)).build();
            rescheduleAJob(oldTriggerKey.getName(), oldTriggerKey.getGroup(), newTrigger);
        } else {
            log.error("failed to trigger a job with id={}, job has no trigger", jobId);
        }
    } catch (SchedulerException se) {
        log.error("failed to trigger a job with id={}: {}", jobId, se.getMessage());
        log.debug("Exception", se);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException)

Example 30 with TriggerKey

use of org.quartz.TriggerKey in project cdap by caskdata.

the class DatasetBasedTimeScheduleStore method readSchedulesFromPersistentStore.

// Get schedule information from persistent store
private void readSchedulesFromPersistentStore() throws Exception {
    final List<JobDetail> jobs = Lists.newArrayList();
    final List<TriggerStatusV2> triggers = Lists.newArrayList();
    factory.createExecutor(ImmutableList.of((TransactionAware) table)).execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Row result = table.get(JOB_KEY);
            if (!result.isEmpty()) {
                for (byte[] bytes : result.getColumns().values()) {
                    JobDetail jobDetail = (JobDetail) SerializationUtils.deserialize(bytes);
                    // If the job detail doesn't contain version id, add one.
                    jobDetail = addDefaultAppVersionIfNeeded(jobDetail);
                    LOG.debug("Schedule: Job with key {} found", jobDetail.getKey());
                    jobs.add(jobDetail);
                }
            } else {
                LOG.debug("Schedule: No Jobs found in Job store");
            }
            result = table.get(TRIGGER_KEY);
            if (!result.isEmpty()) {
                for (byte[] bytes : result.getColumns().values()) {
                    TriggerStatusV2 trigger = (TriggerStatusV2) SerializationUtils.deserialize(bytes);
                    addDefaultAppVersionIfNeeded(trigger);
                    if (trigger.state.equals(Trigger.TriggerState.NORMAL) || trigger.state.equals(Trigger.TriggerState.PAUSED)) {
                        triggers.add(trigger);
                        LOG.debug("Schedule: trigger with key {} added", trigger.trigger.getKey());
                    } else {
                        LOG.debug("Schedule: trigger with key {} and state {} skipped", trigger.trigger.getKey(), trigger.state);
                    }
                }
            } else {
                LOG.debug("Schedule: No triggers found in job store");
            }
        }
    });
    Set<JobKey> jobKeys = new HashSet<>();
    for (JobDetail job : jobs) {
        super.storeJob(job, true);
        jobKeys.add(job.getKey());
    }
    Set<TriggerKey> triggersWithNoJob = new HashSet<>();
    for (TriggerStatusV2 trigger : triggers) {
        if (!jobKeys.contains(trigger.trigger.getJobKey())) {
            triggersWithNoJob.add(trigger.trigger.getKey());
            continue;
        }
        super.storeTrigger(trigger.trigger, true);
        // because the scheduler is actually not started at this point.
        if (trigger.state == Trigger.TriggerState.PAUSED) {
            super.pauseTrigger(trigger.trigger.getKey());
        }
    }
    for (TriggerKey key : triggersWithNoJob) {
        LOG.error(String.format("No Job was found for the Trigger key '%s'." + " Deleting the trigger entry from the store.", key));
        executeDelete(key);
    }
}
Also used : TransactionExecutor(org.apache.tephra.TransactionExecutor) TransactionFailureException(org.apache.tephra.TransactionFailureException) JobPersistenceException(org.quartz.JobPersistenceException) TransactionConflictException(org.apache.tephra.TransactionConflictException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) ObjectAlreadyExistsException(org.quartz.ObjectAlreadyExistsException) IOException(java.io.IOException) TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) Row(co.cask.cdap.api.dataset.table.Row) HashSet(java.util.HashSet)

Aggregations

TriggerKey (org.quartz.TriggerKey)116 Trigger (org.quartz.Trigger)49 SchedulerException (org.quartz.SchedulerException)34 JobKey (org.quartz.JobKey)33 CronTrigger (org.quartz.CronTrigger)25 JobDetail (org.quartz.JobDetail)22 Scheduler (org.quartz.Scheduler)22 Test (org.junit.Test)18 SimpleTrigger (org.quartz.SimpleTrigger)15 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 ArrayList (java.util.ArrayList)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 HashMap (java.util.HashMap)9 Date (java.util.Date)6 List (java.util.List)5 CronScheduleBuilder (org.quartz.CronScheduleBuilder)5 BigDecimal (java.math.BigDecimal)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ParseException (java.text.ParseException)4