[ 
https://issues.apache.org/jira/browse/DELTASPIKE-542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13938369#comment-13938369
 ] 

Jörg Mattes commented on DELTASPIKE-542:
----------------------------------------

Hi Gerhard,
I tried it, and it works fine. Here's the QuartzScheduler.registerNewJob():

    public void registerNewJob(Class<? extends Job> jobClass) {
        JobKey jobKey = createJobKey(jobClass);

        try {
            if (this.scheduler.getJobDetail(jobKey) != null) {
                return;
            }

            Scheduled scheduled = jobClass.getAnnotation(Scheduled.class);

            String description = scheduled.description();

            if ("".equals(scheduled.description())) {
                description = jobClass.getName();
            }

            JobDetail jobDetail = 
JobBuilder.newJob(jobClass).withDescription(description).withIdentity(jobKey).build();
            Trigger trigger = 
TriggerBuilder.newTrigger().withSchedule(CronScheduleBuilder.cronSchedule(scheduled.cronExpression())).build();

            this.scheduler.scheduleJob(jobDetail, trigger);
        } catch (SchedulerException e) {
            throw ExceptionUtils.throwAsRuntimeException(e);
        }
    }

I added the if clause right after the try statement, that's all.
Of course, the consequence is that any changes I make in the cronExpression of 
@Scheduled won't be reflected once that JobDetail's cron trigger is on the 
database, but that is only to be expected when using JdbcJobstore, since the 
job config is on db.
On second thought: I could refine the if-clause and use 
scheduler.rescheduleJob(). That should probably work and update the db with the 
new cron expression. Want me to try?



> Problem with JdbcJobstore
> -------------------------
>
>                 Key: DELTASPIKE-542
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-542
>             Project: DeltaSpike
>          Issue Type: Bug
>          Components: Scheduler
>    Affects Versions: 0.6
>         Environment: Tomcat 7
>            Reporter: Jörg Mattes
>             Fix For: 0.7
>
>
> The Deltaspike Scheduler runs fine if Quartz is configured with RAMJobStore. 
> But if Quartz runs with JdbcJobstore, QuartzScheduler.registerNewJob() fails 
> (stacktrace below). I think a simple check like
>             if (this.scheduler.getJobDetail(jobKey) != null) {
>                 return;
>             }
> would already help.
> Caused by: org.quartz.ObjectAlreadyExistsException: Unable to store Job : 
> 'DEFAULT.PastDueScanJob', because one already exists with this identification.
>       at 
> org.quartz.impl.jdbcjobstore.JobStoreSupport.storeJob(JobStoreSupport.java:1108)
>       at 
> org.quartz.impl.jdbcjobstore.JobStoreSupport$2.executeVoid(JobStoreSupport.java:1062)
>       at 
> org.quartz.impl.jdbcjobstore.JobStoreSupport$VoidTransactionCallback.execute(JobStoreSupport.java:3703)
>       at 
> org.quartz.impl.jdbcjobstore.JobStoreSupport$VoidTransactionCallback.execute(JobStoreSupport.java:3701)
>       at 
> org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3787)
>       at 
> org.quartz.impl.jdbcjobstore.JobStoreTX.executeInLock(JobStoreTX.java:93)
>       at 
> org.quartz.impl.jdbcjobstore.JobStoreSupport.storeJobAndTrigger(JobStoreSupport.java:1058)
>       at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:886)
>       at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:249)
>       at 
> org.apache.deltaspike.scheduler.impl.QuartzScheduler.registerNewJob(QuartzScheduler.java:107)
>       at 
> org.apache.deltaspike.scheduler.impl.SchedulerExtension.scheduleJobs(SchedulerExtension.java:126)
>       at 
> org.apache.deltaspike.scheduler.impl.SchedulerExtension$Proxy$_$$_WeldClientProxy.scheduleJobs(SchedulerExtension$Proxy$_$$_WeldClientProxy.java)



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to