2016-03-30 6 views
1

の値を設定するには、GrailsのジョブグルーヴィーファイルにSQLを実行することはcronExpression値のプロパティを割り当てることが可能であり、私の例としてテーブルから呼び出されたものはcronのトリガー

class RecursiveNotificationJob { 
    def reminderService; 
    def grailsApplication 
    String cronValue = Parameter.executeQuery("select value from Parameter where name='RecursiveNotification'"); 

    static triggers = { 
     cron name: 'recursiveNotificationTrigger', cronExpression: cronValue 
    } 

    def execute() { 
     println new Date().toString() +" Recursive Notification Job is working"; 
     reminderService.execute(); 
    } 

} 

どちらも動作していないようです。どのようにこれが適切なやり方で行えるか、何らかのアイデアや提案を感謝していますか?ありがとう

答えて

0

gormが開始される前に、ジョブクラスがロードされるので、スタティックブロック内のデータベースからcron式をフェッチできません。私たちはcronExpressionをデータベースから読み込まなければならなかったのと同じような使い方をしました。ここで私たちはそれを解決した方法です。

ジョブレベルでトリガーを定義しないでください。ジョブがデフォルトでスケジュールされないことを意味します。

RecursiveNotificationJob { 
    def reminderService; 
    def grailsApplication 

    def execute() { 
     println new Date().toString() +" Recursive Notification Job is working"; 
     reminderService.execute(); 
    } 
} 

Bootstrap.groovyで手動でジョブをスケジュールします。

import org.quartz.CronScheduleBuilder 
import org.quartz.Trigger 
import org.quartz.TriggerBuilder 

class BootStrap { 

    def grailsApplication 

    def init = { servletContext -> 
     this.scheduleJob();   
    } 

    def destroy = { 
    } 

    def scheduleJob() { 
     def triggerName = "RecursiveNotificationTrigger", 
      triggerGroup = "RecursiveNotification", 
      cronExpression = Parameter.executeQuery("select value from Parameter where name='RecursiveNotification'"); 


     Trigger trigger = TriggerBuilder 
      .newTrigger() 
      .withIdentity(triggerName, triggerGroup) 
      .withSchedule(
       CronScheduleBuilder.cronSchedule(cronExpression)) 
      .build(); 


     RecursiveNotificationJob.schedule(trigger) 
    } 
} 
+0

groovy.lang.MissingPropertyExceptionとしてエラーが発生しました:いいえそのようなプロパティ:TriggerBuilder for class:BootStrap。 このトリガーが呼び出されたライブラリを知ることができますか? – Memoc

+0

あなたはそれらをインポートする必要があります!輸入したコードを更新しました。そして、私はあなたが石英バージョンであると仮定しています> 2.0 – JChap

+0

私はエラーが発生しました "ブートストラップの実行中のエラー:そのようなプロパティはありません:クラスの再帰的なジャンプ:BootStrap" ..私はそのジョブクラスをここにインポートしようとしました。 – Memoc

関連する問題