Skip to content
Nick Barrett edited this page Sep 22, 2015 · 2 revisions

Using the ScheduleResource you can schedule a request to be posted to your application on a regular interval. You can also optionally specify a start time for the request.

Scheduling a request

The scheduler accepts 2 paths for scheduling your request

  • /schedule/{id}/{interval}
  • /schedule/{id}/{start}/{interval}
url portion explanation
{id} This is a unique identifier (must be a uuid format), supplied by you to allow you to easily identify this schedule after it has been created
{start} This is the time of day that the first request will be handled. The format is hhmm, for example 2230 for 10:30pm
{interval} How often, in seconds, will the request be handled

When scheduling a request, it is best to combine it with an AsynchronousJob so that you don't block the scheduler.

Here's an example of how to schedule a request at 10:00am, to run every 5 minutes:

application.handle(post("/schedules/schedule/77916239-0dfe-4217-9e2a-ceaa9e5bed42/1000/60/jobs/run/some/request").build())

Querying the scheduler

You can ask the scheduler for a list of what the current schedules are.

application.handle(post("/schedules/list").build())

The json response will look similar to:

{
"schedules":[{
"id":"77916239-0dfe-4217-9e2a-ceaa9e5bed42",
"status":"idle",
"start":null,
"seconds":60,
"request":{
"raw":"POST /jobs/run/some/request HTTP/1.1\r\nAccept: text/html",
"method":"POST",
"uri":"/jobs/run/crawler/crawl",
"entity":"id=77916239-0dfe-4217-9e2a-ceaa9e5bed42"
},
"response":{
"raw":"HTTP/1.1 202 Queued HttpJob\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\nDate: Mon, 29 Jul 2013 10:50:52 UTC\r\nContent-Length: 29\r\n\r\nYou HttpJob has been accepted",
"code":202,
"status":"Queued HttpJob",
"entity":"You HttpJob has been accepted"
},
"started":"Mon Jul 29 11:50:52 BST 2013",
"completed":"Mon Jul 29 11:50:52 BST 2013",
"duration":0
}],
"anyExists":true
}

Removing a schedule

You can remove a current schedule, so long as you have the id:

application.handle(post("/schedules/delete/77916239-0dfe-4217-9e2a-ceaa9e5bed42").build())

How do I get scheduling in my application?

To get scheduling added to your application, you can add the SchedulingModule. If you are going to schedule using AsynchronousJobs, also include the JobsModule

public static void addModules(Application application) {
application.add(new ScheduleModule());
application.add(new JobsModule());
}