2017-09-29 22 views
0

我想有定期稱爲一天一次行動Ø程序,而不需要有在別人登錄的。Grails的,拍動作被重複調用,每天一次,每週等

這是可能的,如果它是: 我該怎麼做?

這是我的觸發:

package com.myproj.jobs 


class DailyCheck { 
    static triggers = { 
//  cron name: 'dailyCheck', cronExpression: "03 * * * * ?" 
      simple name: 'myJobSimple', repeatInterval: 6000 
    } 


def dailyCheckService 
def execute() { 
    println(">>>>>>>>> DAILY JOB EXECUTES <<<<<<<") 
    dailyCheckService.checkOffers() 
} 

}我的build.gradle的

部分:

dependencies { 
compile "org.springframework.boot:spring-boot-starter-logging" 
compile "org.springframework.boot:spring-boot-autoconfigure" 
compile "org.grails:grails-core" 
compile "org.springframework.boot:spring-boot-starter-actuator" 
compile "org.springframework.boot:spring-boot-starter-tomcat" 
compile "org.grails:grails-dependencies" 
compile "org.grails:grails-web-boot" 
compile "org.grails.plugins:cache" 
compile "org.grails.plugins:scaffolding" 
compile "org.grails.plugins:hibernate5" 
compile "org.hibernate:hibernate-core:5.1.2.Final" 
compile "org.hibernate:hibernate-ehcache:5.1.2.Final" 
console "org.grails:grails-console" 
compile 'org.grails.plugins:quartz:2.0.12' 
profile "org.grails.profiles:web" 
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.11.6" 
runtime "com.h2database:h2" 
testCompile "org.grails:grails-plugin-testing" 
testCompile "org.grails.plugins:geb" 
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1" 
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18" 
runtime 'net.sourceforge.jtds:jtds:1.3.1' 
compile "ca.redtoad:grails-phonenumbers:0.11" 
compile 'org.grails.plugins:spring-security-core:3.1.1' 
compile 'org.grails.plugins:spring-security-ui:3.0.0.M2' 
compile 'org.grails.plugins:database-migration:3.0.0' 
compile 'org.liquibase:liquibase-core:3.5.3' 
compile 'org.grails.plugins:rendering:2.0.3' 
runtime "org.springframework:spring-test:4.2.1.RELEASE" 
compile "org.grails.plugins:excel-export:2.1" 

}

+1

對於您正在使用的grails的任何版本,都有一個石英插件 – cfrick

+0

很好,我會檢查一下。我正在使用Grails-3.2.3。 – larand

回答

0

這個問題是通過添加一個名爲QuartzConfig.groovy的grails-app/conf目錄配置文件來解決具有以下內容:

quartz { 
    autoStartup = true 
    jdbcStore = false 
} 
environments { 
    test { 
    quartz { 
     autoStartup = false 
    } 
    } 
} 

並且Mike WI將補充說,在st上仍然沒有可見的日誌記錄藝術,所以它可能已被帶走了這個最新版本?

1

您可以使用quartz plugin例如

的build.gradle

dependencies { 
    compile 'org.grails.plugins:quartz:2.0.12' 
} 

/grails-app/jobs/MyJob.groovy

class MyJob{ 
    static triggers = { 
     // fire every day at 12:30 
     cron name: 'myJobCron', cronExpression: "0 30 12 * * ?" 
    } 

    def myService 

    def execute(context) { 
     myService.doStuff() 
    } 
} 
+0

真的那麼簡單嗎?我會花一段時間,直到我得到任何結果。謝謝! – larand

+0

好吧,它似乎永遠不會執行,因爲我測試我在開發模式下運行,我明白我需要配置插件,但沒有配置文件來編輯。我也嘗試過「grails install-quartz-config」,但是grails沒有找到這個命令。 – larand

+0

你不需要添加配置,除非你想對某些方面進行細粒度的控制,你把你的cron時間表更改爲什麼?您可以使用簡單的觸發器,例如這將每隔60秒觸發'簡單名稱:'myJobSimple',repeatInterval:6000000',將其添加到觸發器塊&註釋掉cron時間表 –