Reza
Reza

Reputation: 739

Quartz job in Grails

consider the following codes:

class MyJob {  
    def execute() {
        println "Hello at->"+new Date()
    }
}

when I run this code it starts running every minute without assigning any trigger. How could I disable this property? I want to start this job whenever I make my trigger.

Upvotes: 3

Views: 3501

Answers (3)

schmolly159
schmolly159

Reputation: 3881

If you want to disable the default trigger and not assign a trigger at startup then you just need an empty triggers closure in the class.

class MyJob {
    static triggers = { }

    ...
}

That will assign the closure's triggers, which are none, to the job instead of the default trigger.

Upvotes: 3

chrislatimer
chrislatimer

Reputation: 3560

If I understand what you want to do, you would first install the quartz config:

grails install-quartz-config

Then disable auto startup:

quartz {
    autoStartup = false
    jdbcStore = false
}

Then dynamically schedule the job inside your application:

// creates cron trigger;
MyJob.schedule(String cronExpression, Map params?)
//  creates simple trigger: repeats job repeatCount+1 times with delay of repeatInterval milliseconds;
MyJob.schedule(Long repeatInterval, Integer repeatCount?, Map params?) )

// schedules one job execution to the specific date;
MyJob.schedule(Date scheduleDate, Map params?)

//schedules job's execution with a custom trigger;
MyJob.schedule(Trigger trigger)

// force immediate execution of the job.
MyJob.triggerNow(Map params?)

Upvotes: 0

ibaralf
ibaralf

Reputation: 12528

It's a bit vague what you're trying to accomplish. If you want to execute this when you 'create' a trigger, then you actually don't need to put this in a cron job.

However if you want to activate this after a certain event. Then you would still create a trigger, but have some sort of check before execution. Ex.

class MyJob {
   static triggers = { .... create the schedule      

   def execute() {
     // instead of create a trigger, you create a temp file that would allow/prevent
     // the execution
     def runIt = new File(runFile.txt)  
     if (runIt.exists()) {
        println "Hello at->"+new Date()
     }
   }
}

Upvotes: 0

Related Questions