Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuously poll a REST service in Grails

Tags:

rest

grails

I am creating a web app in Grails and I would like to continuously (every 5 minutes or so) poll a REST service using GET, which retrieves a series of messages (or possibly none, it depends) and once it is donde, my application should save the retrieved data as an object and store it in my database. The problem is that I have no idea how I should implement it (with a cron job using Quartz?)

like image 378
Rodrigo Rivera Avatar asked Jan 23 '23 10:01

Rodrigo Rivera


1 Answers

A cron job using quartz would be really easy to implement. The quartz plugin is very easy to use (just install it and then "grails create-job Foo"). Inside the task, you can use a cron expression (or a number of other ways) that will cause the job to get executed based on the schedule.

Depending on a few things, the GET expression is also very easy to write. Depending on the service you're trying to hit it could be as easy as:

def result = new URL("http://google.com").text
// parse result depending on what it is
like image 106
Ted Naleid Avatar answered Jan 30 '23 15:01

Ted Naleid