【问题标题】:Grails Quartz dynamic scheduling Import issueGrails Quartz 动态调度导入问题
【发布时间】:2014-11-01 09:16:34
【问题描述】:

我想使用 Grails 石英插件的动态调度功能。

我正在运行 grails 2.3.5 和石英插件 (quartz:1.0.2)。

我能够将石英信息保存到我的 mysql 数据库中,并且能够运行正常的石英作业。

问题在于动态调度任务。我没有让这个工作。

这是我的设置和我想要做的:

我在"grails-app/tao/marketing/MarketingJob" 有一个简单的工作,看起来像这样:

package tao.marketing
import org.quartz.JobExecutionContext; 
import org.quartz.JobExecutionException; 

class MarketingJob {

static triggers ={}

def execute(JobExecutionContext context) {
     try{
        def today = new Date()
        println today
    }
    catch (Throwable e) {
       throw new JobExecutionException(e.getMessage(), e);
    }
  }
}

我现在尝试从服务动态调度。

package tao

import grails.transaction.Transactional
import tao.marketing.CampaignSchedule
import tao.Person
import jobs.tao.marketing.*



class ScheduleService {

def scheduleMarketingForPerson(CampaignSchedule campaignSchedule, Person person) {
    log.info("Schedule new Marketing for: "+person.last_name)
        campaignSchedule.scheduleActions.each {
            Date today = new Date();
            Date scheduleDate = today+it.afterXdays
            log.info("ScheduleAction: "+it.id+": "+scheduleDate)
            MarketingJob.schedule(scheduleDate, ["scheduleActions.id":it.id,     "person.apiKey":person.apiKey])
        }
    }
}

在我的 IDE (STS) 中找不到MarketingJob

 MarketingJob.schedule(scheduleDate, ["scheduleActions.id":it.id,     "person.apiKey":person.apiKey])

如何正确导入标记作业? 我是否正确理解动态调度功能?

【问题讨论】:

  • 我刚刚从控制器测试了我的代码。在那里它没有任何问题。问题实际上是为什么我不能从 grails 服务中访问 MarketingJob (grails-app/jobs/..)。有什么诀窍?
  • 你在grails-app/tao/marketing/MarketingJob有工作吗?不应该在grails-app/jobs/tao/marketing/MarketingJob吗?

标签: grails quartz-scheduler grails-plugin jobs


【解决方案1】:

可能是您的工作在“package tao.marketing”中,而您的导入是“import jobs.tao.marketing.*”?我的意思是,导入以“工作”开头

【讨论】:

    【解决方案2】:

    我遇到的问题是,在我的 STS IDE 中,我没有将作业目录标记为代码目录。感谢您的所有 cmets。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-02
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 2015-09-01
      • 2015-02-08
      • 2011-08-22
      相关资源
      最近更新 更多