2017-09-29 21 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时间表 –