michaelklishin / quartz-mongodb

A MongoDB-based store for the Quartz scheduler. This fork strives to be as feature complete as possible. Originally by MuleSoft.
Other
249 stars 203 forks source link

I am not able to get the schduler run, because there is a strange "open" exception #83

Closed kicOLD closed 9 years ago

kicOLD commented 9 years ago

This is the Exception I get on start

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "default_QuartzSchedulerThread" org.quartz.JobPersistenceException: open [See nested exception: java.lang.IllegalStateException: open]
    at com.novemberain.quartz.mongodb.MongoDBJobStore.releaseAcquiredTrigger(MongoDBJobStore.java:640)
    at org.quartz.core.QuartzSchedulerThread.releaseIfScheduleChangedSignificantly(QuartzSchedulerThread.java:432)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:316)
Caused by: java.lang.IllegalStateException: open
    at org.bson.util.Assertions.isTrue(Assertions.java:36)
    at com.mongodb.DBTCPConnector.releasePort(DBTCPConnector.java:421)
    at com.mongodb.DBCollectionImpl.remove(DBCollectionImpl.java:233)
    at com.mongodb.DBCollectionImpl.remove(DBCollectionImpl.java:201)
    at com.mongodb.DBCollection.remove(DBCollection.java:274)
    at com.mongodb.DBCollection.remove(DBCollection.java:301)
    at com.novemberain.quartz.mongodb.MongoDBJobStore.removeTriggerLock(MongoDBJobStore.java:1202)
    at com.novemberain.quartz.mongodb.MongoDBJobStore.releaseAcquiredTrigger(MongoDBJobStore.java:638)
    ... 2 more

This is my properties file:

# Main Quartz configuration
org.quartz.scheduler.skipUpdateCheck = true
org.quartz.scheduler.instanceName = default
org.quartz.scheduler.jobFactory.class = org.quartz.simpl.SimpleJobFactory
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
# org.quartz.threadPool.threadCount = 5

# Use the MongoDB store
org.quartz.jobStore.class=com.novemberain.quartz.mongodb.MongoDBJobStore
# MongoDB URI (optional if 'org.quartz.jobStore.addresses' is set)
org.quartz.jobStore.mongoUri=mongodb://localhost:27017
# comma separated list of mongodb hosts/replica set seeds (optional if 'org.quartz.jobStore.mongoUri' is set)
#org.quartz.jobStore.addresses=host1,host2
# database name
org.quartz.jobStore.dbName=quartz
# Will be used to create collections like mycol_jobs, mycol_triggers, mycol_calendars, mycol_locks
org.quartz.jobStore.collectionPrefix=
# thread count setting is ignored by the MongoDB store but Quartz requries it
org.quartz.threadPool.threadCount=5

And this is the class I try to run:

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * Created by kic on 22.01.15.
 */
public class TestStore {
    public static void main(String[] args) throws SchedulerException, InterruptedException {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        // define the job and tie it to our HelloJob class
        JobDetail job = newJob(FooJob.class)
                .withIdentity("job1", "group1")
                .build();

        // Trigger the job to run now, and then repeat every 40 seconds
        Trigger trigger = newTrigger()
                .withIdentity("trigger1", "group1")
                .startNow()
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(3)
                        .repeatForever())
                .build();

        // Tell quartz to schedule the job using our trigger
        try {
            scheduler.scheduleJob(job, trigger);
        } catch (Exception e) {
            e.printStackTrace();
        }

        scheduler.start();
        Thread.sleep(6000);
        scheduler.shutdown();
    }

    public class FooJob implements Job {
        @Override
        public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
            System.out.println("lala");
        }
    }
}
michaelklishin commented 9 years ago

This means that MongoDB connection has been already closed.

michaelklishin commented 9 years ago

I'm not sure why you are trying to first schedule a job and then start the scheduler. Please try starting the scheduler first, I expect that to initialise the stores.