Search in sources :

Example 1 with JobQueueTable

use of io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable in project cdap by caskdata.

the class CoreSchedulerService method execute.

@SuppressWarnings("UnusedReturnValue")
private <V, T extends Exception> V execute(StoreQueueAndProfileTxRunnable<V, ? extends Exception> runnable, Class<? extends T> tClass) throws T {
    return TransactionRunners.run(transactionRunner, context -> {
        ProgramScheduleStoreDataset store = Schedulers.getScheduleStore(context);
        ProfileStore profileStore = ProfileStore.get(context);
        JobQueueTable queue = JobQueueTable.getJobQueue(context, cConf);
        return runnable.run(store, queue, profileStore);
    }, tClass);
}
Also used : JobQueueTable(io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable) ProgramScheduleStoreDataset(io.cdap.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset) ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore)

Example 2 with JobQueueTable

use of io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable in project cdap by caskdata.

the class CoreSchedulerService method cleanupJobs.

// Attempts to remove all jobs that are in PENDING_LAUNCH state.
// These are jobs that were about to be launched, but the scheduler shut down or crashed after the job was marked
// PENDING_LAUNCH, but before they were actually launched.
// This should only be called at startup.
private void cleanupJobs() {
    try {
        TransactionRunners.run(transactionRunner, context -> {
            JobQueueTable jobQueue = JobQueueTable.getJobQueue(context, cConf);
            try (CloseableIterator<Job> jobIter = jobQueue.fullScan()) {
                LOG.info("Cleaning up jobs in state {}.", Job.State.PENDING_LAUNCH);
                while (jobIter.hasNext()) {
                    Job job = jobIter.next();
                    if (job.getState() == Job.State.PENDING_LAUNCH) {
                        LOG.warn("Removing job because it was left in state {} from a previous run of the scheduler: {} .", Job.State.PENDING_LAUNCH, job);
                        jobQueue.deleteJob(job);
                    }
                }
            }
        }, TransactionException.class);
    } catch (TransactionException exception) {
        LOG.warn("Failed to cleanup jobs upon startup.", exception);
    }
}
Also used : TransactionException(io.cdap.cdap.spi.data.transaction.TransactionException) JobQueueTable(io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable) Job(io.cdap.cdap.internal.app.runtime.schedule.queue.Job)

Example 3 with JobQueueTable

use of io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable in project cdap by caskdata.

the class CoreSchedulerService method execute.

@SuppressWarnings("UnusedReturnValue")
private <V, T extends Exception> V execute(StoreAndQueueTxRunnable<V, ? extends Exception> runnable, Class<? extends T> tClass) throws T {
    return TransactionRunners.run(transactionRunner, context -> {
        ProgramScheduleStoreDataset store = Schedulers.getScheduleStore(context);
        JobQueueTable queue = JobQueueTable.getJobQueue(context, cConf);
        return runnable.run(store, queue);
    }, tClass);
}
Also used : JobQueueTable(io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable) ProgramScheduleStoreDataset(io.cdap.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset)

Example 4 with JobQueueTable

use of io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable in project cdap by caskdata.

the class CoreSchedulerServiceTest method getLastMessageId.

@Nullable
private MessageId getLastMessageId(final TopicId topic) {
    return TransactionRunners.run(transactionRunner, context -> {
        JobQueueTable jobQueue = JobQueueTable.getJobQueue(context, cConf);
        String id = jobQueue.retrieveSubscriberState(topic.getTopic());
        if (id == null) {
            return null;
        }
        byte[] bytes = Bytes.fromHexString(id);
        return new MessageId(bytes);
    });
}
Also used : JobQueueTable(io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable) MessageId(io.cdap.cdap.messaging.data.MessageId) Nullable(javax.annotation.Nullable)

Aggregations

JobQueueTable (io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable)4 ProgramScheduleStoreDataset (io.cdap.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset)2 Job (io.cdap.cdap.internal.app.runtime.schedule.queue.Job)1 ProfileStore (io.cdap.cdap.internal.app.store.profile.ProfileStore)1 MessageId (io.cdap.cdap.messaging.data.MessageId)1 TransactionException (io.cdap.cdap.spi.data.transaction.TransactionException)1 Nullable (javax.annotation.Nullable)1