【发布时间】: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