开发者

should I invoke Grails controller from Quartz job for REST API calls?

开发者 https://www.devze.com 2023-02-14 05:29 出处:网络
I\'ve seen a number of postings citing that quartz jobs should not invoke controllers.I\'m using Grails to use salesforce.com\'s new support for the REST API.The nightly job would use that API to upda

I've seen a number of postings citing that quartz jobs should not invoke controllers. I'm using Grails to use salesforce.com's new support for the REST API. The nightly job would use that API to update customer data from our proprietary DB to the salesforce environment. There is a session that is created using a login id.

So... I would like to use the jobs plug-in for grails to give me the cron-style way to invoke controllers that interact with services in order to send REST API calls via httpclient to update/upsert our objects in salesforce.com land.

It seems like this would be a legitimate reason for invoking controllers from the jobs area in Grails.

Would love any feedback or alternative approaches (within Grails) for handling this. th开发者_如何学Pythonx, David


Why have you invoke controllers from Quartz jobs ? This looks whery awkward. User grails services. Quartz plugin has dependency injection so it should be easy to invoke service methods.


Even if you invoke a controller from a quartz task, you won't be able to access the session because there will be no authenticated user. If you want to make some complex business logic put it in a service and then call it from your job. Declaring services in quartz jobs is exactly the same as the declaration in the controllers.


I feel the question is a valid one. I had a similar requirement. I used grails rest plugin. A grails controller action that exports some report data into excel and email it to emailing list on daily basis. So I created a method in controller:

def exportToExcel() {
        myService.exportToExcel(response)
    }

Then besides exportToExcel() implementation in myService.groovy, I created an additional method as under:

def runExportToExcelJob() { withHttp(uri: "http://localhost:9092/myProject/"){ return get(path: 'myController/exportToExcel') } }

And finally, in my grails quartz job, I invoked myService.runExportToExcelJob().

It works fine. But I too wonder, if there is another way of making a rest call from grails job. Any feedback is really appreciated.

0

精彩评论

暂无评论...
验证码 换一张
取 消