source: trunk/grails-app/jobs/InventoryReindexJob.groovy @ 618

Last change on this file since 618 was 579, checked in by gav, 14 years ago

Add Quartz job to reindex searchable InventoryItem index every hour.

File size: 1.3 KB
Line 
1import org.codehaus.groovy.grails.commons.*
2
3/**
4* Provides a quartz job that reindex's the Lucene index for the Inventory domain class.
5* With concurrent=false the repeat interval starts after the previous job completes.
6* We need a hibernate session otherwise we get a LazyInitializationException, default is true but we specify it to be sure.
7*/
8class InventoryReindexJob {
9
10    def concurrent = false
11    def sessionRequired = true
12
13    static triggers = {
14        // Cron fields:
15        // 'Seconds Minutes Hours DOM Month DOW Year(Optional)'
16        // See: http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html
17        // Trigger every hour on the hour:
18        cron name: 'RebuildInventoryIndex', cronExpression: "0 0 * * * ?"
19    }
20
21    def execute() {
22
23        // Some information can be accessed if we run with "def execute(context) ".
24        // For more info see: http://quartz.sourceforge.net/javadoc/org/quartz/JobExecutionContext.html
25        // log.debug context.getTrigger()
26        // log.debug context.getPreviousFireTime()
27        // log.debug context.getFireTime()
28
29        // Reindex the Inventory domain class.
30        log.info "Rebuilding Lucene index, Inventory.reindex()."
31        InventoryItem.reindex()
32        log.info "Rebuilding Lucene index, complete."
33    }
34}
Note: See TracBrowser for help on using the repository browser.