Execute a Quartz Job with a Trigger from a Controller

梦想的初衷 提交于 2019-12-10 14:28:02

问题


I can run a cron from a static trigger from within the job folder and it will execute, but when I try to fire a trigger from my controller it just plain fails...What am I missing?

ERROR CODE: No signature of method: static com.example.TaskReminderJob.triggerNow() is applicable for argument types: (java.util.LinkedHashMap) values: [[params:[name:Frank, email:frank@test.com]]]

Quartz Job in grails-app/jobs/example

  package com.example
  class TaskReminderJob {
     def reminderMailService 
     static triggers = { }

     def execute(context) {
         def email = context.mergedJobDataMap.get('email')
         def name = context.mergedJobDataMap.get('name')
         reminderMailService.remindMail1(name, email)  //send email via service       
     }
  }

CONTROLLER CALLING THE JOB

package example

class UserController {
    def quartzScheduler 
    ...
    //user is created
    ...                     
    TaskReminderJob.triggerNow([name:"frank",email:"frank@test.com"] )
} 

回答1:


Correct your package path and then you can trigger your job manually using triggerNow method. And if you need to pass any parameter to it you can pass it like this:

package com.example

class UserController {
     def someAction(){
        ...
        TaskReminderJob.triggerNow([id:params.id])
     }

Job

package com.example

class TaskReminderJob {
    static triggers = {}

    def execute(context) {
        def id = context.mergedJobDataMap.get('id')
        ...
    }
}


来源:https://stackoverflow.com/questions/18648836/execute-a-quartz-job-with-a-trigger-from-a-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!