Quartz job is executed multiple times simultaneously and immediately

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Quartz job is executed multiple times simultaneously and immediately

talldave
hi all, have a quartz job i've set up as follows:

class S3DataVerificationJob {
       
        // schedule monday-friday at 5am
        static triggers = {
                cron cronExpression: '0 0 5 ? * MON-FRI'
        }
        // verification logic
        def s3DataVerificationService
       
        // execute task
       def execute()
        {
                log.debug( "starting S3 Data Verification Job" )
                s3DataVerificationService.verifyS3Data()
                log.debug( "S3 Data Verification Job complete" )
       }
}


what's happening though is that it's immediately being called 3 times and running simultaneously.  this was happening even when i previously had "concurrent = false" defined in the job.  in my log i'm seeing:

2011-02-17 05:00:00,100 [quartzScheduler_Worker-1] DEBUG batch.S3DataVerificationJob  - starting S3 Data Verification Job
2011-02-17 05:00:00,133 [quartzScheduler_Worker-1] DEBUG batch.S3DataVerificationJob  - starting S3 Data Verification Job
2011-02-17 05:00:00,123 [quartzScheduler_Worker-1] DEBUG batch.S3DataVerificationJob  - starting S3 Data Verification Job

i have no idea why this is happening, and haven't been able to turn up anything in my searches.  can anyone help shed some light on this?

much thanks!

Reply | Threaded
Open this post in threaded view
|

Re: Quartz job is executed multiple times simultaneously and immediately

talldave
ok, so this didn't work.  same result as before - executed 3 times.


class S3DataVerificationJob {
       
        // schedule monday-friday at 5am
        static triggers = {
                cron cronExpression: '0 0 5 ? * MON-FRI'
        }
       
        // don't let two instances of the job run simultaneously
        //def concurrent = false
        private static boolean isRunning = false

        // verification logic
        def s3DataVerificationService
       
        // execute task
    def execute()
        {
                try {
                        log.debug( "starting S3 Data Verification Job" )
                       
                        if ( ! isRunning ) {
                                isRunning = true
                                s3DataVerificationService.verifyS3Data()
                                log.debug( "S3 Data Verification Job complete" )
                        }
                        else {
                                log.debug( "job is already running, skipping execution" )
                        }
                }
                catch ( Exception e ) {
                        log.error( "error in executing S3DataVerificationJob: ${e}" )
                }
               
                isRunning = false;
    }
       
}
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

wwwclaes
In reply to this post by talldave
Could it be that you need name and/or startDelay parameters to make
a valid trigger?

I experienced similar behaviour when trying to startup a Quartz job manually
and failed to realize I needed an empty triggers statement to avoid immediate
execution of the job.

/Claes

> Date: Wed, 16 Feb 2011 23:04:05 -0800
> From: [hidden email]
> To: [hidden email]
> Subject: [grails-user] Quartz job is executed multiple times simultaneously and immediately
>
>
> hi all, have a quartz job i've set up as follows:
>
> class S3DataVerificationJob {
>
> // schedule monday-friday at 5am
> static triggers = {
> cron cronExpression: '0 0 5 ? * MON-FRI'
> }
> // verification logic
> def s3DataVerificationService
>
> // execute task
> def execute()
> {
> log.debug( "starting S3 Data Verification Job" )
> s3DataVerificationService.verifyS3Data()
> log.debug( "S3 Data Verification Job complete" )
> }
> }
>
>
> what's happening though is that it's immediately being called 3 times and
> running simultaneously. this was happening even when i previously had
> "concurrent = false" defined in the job. in my log i'm seeing:
>
> 2011-02-17 05:00:00,100 [quartzScheduler_Worker-1] DEBUG
> batch.S3DataVerificationJob - starting S3 Data Verification Job
> 2011-02-17 05:00:00,133 [quartzScheduler_Worker-1] DEBUG
> batch.S3DataVerificationJob - starting S3 Data Verification Job
> 2011-02-17 05:00:00,123 [quartzScheduler_Worker-1] DEBUG
> batch.S3DataVerificationJob - starting S3 Data Verification Job
>
> i have no idea why this is happening, and haven't been able to turn up
> anything in my searches. can anyone help shed some light on this?
>
> much thanks!
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Quartz-job-is-executed-multiple-times-simultaneously-and-immediately-tp3310263p3310263.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

talldave
thanks for the suggestion.  i tried adding a name and startDelay to the trigger - and the startDelay does what it's supposed to, but it still runs 3 times just after the startDelay.  :)

i've also made the service with the job logic transactional to no effect.

here's the updated code if anyone has any suggestions.  at this point i'm just about ready to turn off the scheduling and run it manually periodically, which totally defeats the purpose of attempting to use quartz.  :(


class S3DataVerificationJob {
       
        // schedule monday-friday at 5am
        static triggers = {
                cron name: 'dataVerification', startDelay: 60000, cronExpression: '0 0 5 ? * MON-FRI'
        }
       
        // verification logic
        def s3DataVerificationService
       
        // execute task
    def execute() {
                log.debug( "starting S3 Data Verification Job" )
                s3DataVerificationService.verifyS3Data()
                log.debug( "S3 Data Verification Job complete" )
    }
}



class S3DataVerificationService {

    static transactional = true
       
        def mailService
       
        private def resultsList = []
       
        private static boolean isRunning = false
       
    def verifyS3Data()
        {
                if ( ! isRunning ) {
                        isRunning = true
                       
                        try {
                                validateData() // not included here for brevity
                               
                                if ( resultsList.size() > 0 ) {
                                        mailResults() // emails results
                                }
                        }
                        catch ( Exception e ) {
                                log.error( "exception in S3DataVerificationService: ${e}" )
                        }
                       
                        isRunning = false
                        resultsList = []
                }
                else {
                        log.debug( "job is already running, skipping execution" )
                }
    }
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

BalaTR
Dave
You may want to try SimpleTrigger
SimpleTrigger(String name, String group, Date startTime, Date endTime, int repeatCount, long repeatInterval)

repeatCount could possibly help you.

from the doc:
http://www.quartz-scheduler.org/docs/api/1.8.0/org/quartz/SimpleTrigger.html
 int getRepeatCount()
      Get the the number of times the SimpleTrigger should repeat, after which it will be automatically deleted.

HTH
Bala Thiruppanambakkam
blog:http://springandgrailsmusings.blogspot.com/
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

Bill Stephens
Agreed,  here is my trigger

//delay 30 seconds, run every 30 minutes, forever
static triggers = {
    simple name: 'syncGTSTrigger', startDelay: 30000, repeatInterval: 1800000, repeatCount: -1
}

Bill S.

On Wed, Feb 23, 2011 at 5:18 PM, BalaTR <[hidden email]> wrote:

Dave
You may want to try SimpleTrigger
SimpleTrigger(String name, String group, Date startTime, Date endTime, int
repeatCount, long repeatInterval)

repeatCount could possibly help you.

from the doc:
http://www.quartz-scheduler.org/docs/api/1.8.0/org/quartz/SimpleTrigger.html
 int    getRepeatCount()
     Get the the number of times the SimpleTrigger should repeat, after
which it will be automatically deleted.

HTH
Bala Thiruppanambakkam
blog:http://springandgrailsmusings.blogspot.com/
--
View this message in context: http://grails.1312388.n4.nabble.com/Quartz-job-is-executed-multiple-times-simultaneously-and-immediately-tp3310263p3321799.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

Sergey Nebolsin
In reply to this post by talldave
Are you sure that you're not running in a clustered environment with 3 instances of your application?

If that's the case you need to additionally configure Quartz (see section "Clustering" in grails-quartz docs).

Cheers. 

On Wed, Feb 23, 2011 at 20:53, t.dave <[hidden email]> wrote:

thanks for the suggestion.  i tried adding a name and startDelay to the
trigger - and the startDelay does what it's supposed to, but it still runs 3
times just after the startDelay.  :)

i've also made the service with the job logic transactional to no effect.

here's the updated code if anyone has any suggestions.  at this point i'm
just about ready to turn off the scheduling and run it manually
periodically, which totally defeats the purpose of attempting to use quartz.
:(


class S3DataVerificationJob {

       // schedule monday-friday at 5am
       static triggers = {
               cron name: 'dataVerification', startDelay: 60000, cronExpression: '0 0 5 ?
* MON-FRI'
       }

       // verification logic
       def s3DataVerificationService

       // execute task
   def execute() {
               log.debug( "starting S3 Data Verification Job" )
               s3DataVerificationService.verifyS3Data()
               log.debug( "S3 Data Verification Job complete" )
   }
}



class S3DataVerificationService {

   static transactional = true

       def mailService

       private def resultsList = []

       private static boolean isRunning = false

   def verifyS3Data()
       {
               if ( ! isRunning ) {
                       isRunning = true

                       try {
                               validateData() // not included here for brevity

                               if ( resultsList.size() > 0 ) {
                                       mailResults() // emails results
                               }
                       }
                       catch ( Exception e ) {
                               log.error( "exception in S3DataVerificationService: ${e}" )
                       }

                       isRunning = false
                       resultsList = []
               }
               else {
                       log.debug( "job is already running, skipping execution" )
               }
   }
--
View this message in context: http://grails.1312388.n4.nabble.com/Quartz-job-is-executed-multiple-times-simultaneously-and-immediately-tp3310263p3321444.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
Sergey Nebolsin
CTO at Prophotos.ru, Bestphotographer.ru and Fotoshkola.net
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

talldave
thanks all for the responses.  i am not running in a clustered environment - i'm on an 800MB VPS (tomcat) hosted at Eapps.  as per the other two suggestions i'll try a simple trigger and set it to repeat every 24 hours and see if that solves the multiple execution problem.  i'd prefer that it runs consistently late at night, hence the use of cron trigger thus far.

if the simple trigger doesn't work i'll set up a quartz-specific configuration file and see if tweaking settings that way can solve the issue.

again, thanks all for the input!
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

talldave
as per the suggestions above, i've followed bill's example and changed to a simple trigger.

// delay 5 minutes, then repeat every 24 hours
        static triggers = {
                simple name: 'dataVerification', startDelay: 300000, repeatInterval: 86400000, repeatCount: -1
        }


the job is now only being executed once instead of 3 times.  so i don't know what's up with the cron triggers, but for now that's good enough and on to the next problem!

again, thanks all!

dave
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

talldave
and...i spoke too soon.  the simple trigger worked fine and the job only executed once at least a couple times earlier this evening.  i've since been banging my head against the searchable plugin as it will not deploy successfully to tomcat (which is a whole other issue).

i've now just uninstalled the searchable plugin and the quartz job is back to its old tricks of executing 3 times.  i can't say it's related as quartz was doing this before i ever installed searchable.

i think it's going to be manual execution of the job until i have the time to look under the covers.

grr...plugins are not my friends today.
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

Sergey Nebolsin
Please raise an issue for the Grails-Quartz component and attach the simple app which reproduces the problem.

I still think that there's something special in your environment, cause I cannot reproduce the problem.

Cheers.

On Fri, Feb 25, 2011 at 07:46, t.dave <[hidden email]> wrote:

and...i spoke too soon.  the simple trigger worked fine and the job only
executed once at least a couple times earlier this evening.  i've since been
banging my head against the searchable plugin as it will not deploy
successfully to tomcat (which is a whole other issue).

i've now just uninstalled the searchable plugin and the quartz job is back
to its old tricks of executing 3 times.  i can't say it's related as quartz
was doing this before i ever installed searchable.

i think it's going to be manual execution of the job until i have the time
to look under the covers.

grr...plugins are not my friends today.
--
View this message in context: http://grails.1312388.n4.nabble.com/Quartz-job-is-executed-multiple-times-simultaneously-and-immediately-tp3310263p3323892.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
Sergey Nebolsin
CTO at Prophotos.ru, Bestphotographer.ru and Fotoshkola.net
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

BalaTR
In reply to this post by talldave
Dave

You might have done this but...
Did you clear out the old trigger(in database along with its associated table entries) before you started testing the new one with SimpleTrigger?

Bala Thiruppanambakkam
blog:springandgrailsmusings.blogspot.com
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

Herrera
Hi,
   I have the same problem, the job is executed 3 times .

        cron name: 'dailyImport', startDelay: 10000, cronExpression: '0 0 7 * * ?'

How I do to fix this ?

Pedro Herrera
ps. I´m using grails 1.3.7 + tomcat 6 + plugin quartz 0.4.2


Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

Herrera
It´s works fine using grails prod run-war. But when I move the .war to tomcat server, this error occurs.

Pedro Herrera
Reply | Threaded
Open this post in threaded view
|

RE: Quartz job is executed multiple times simultaneously and immediately

talldave
well, while i'm sorry to hear you're having this trouble as well, i'm glad to see i'm not the only one.  :)

i'm thinking this must be something related to tomcat, as i only experience this in my production tomcat environment, not in dev.  i have not yet revisited this issue but planned to soon - so far the jobs i've set up with quartz aren't too affected by having multiple executions - resetting some counters back to zero and whatnot.

however, i will soon be creating new jobs that can't execute multiple times - sending out automatic emails and whatnot.  as such, my thought was to create a utility domain class that would simply track whether the job was executing or not.  unfortunately, using a static variable on the job to do the same thing didn't work.  this isn't ideal but since grails makes it so easy to create domain classes and store things in the DB, it should be very simple to execute.

btw, i mentioned this problem to someone a while back who told me that apparently quartz has issues like this, so the problem may be related to the underlying library and not the grails plugin.  but that's just a conjecture.

if you figure it out let me know, or if i get my utility class up and running i'll try and remember to post the solution here.