Expose HTTP Controller
This section will guide you through how to expose an HTTP controller on your Persistent Scheduler application, so the Persistent Scheduler operations can be accessed externally.
Additionally, it will show you how to register a SchedulingHelper to handle a SchedulingCommand.
To connect to, and send requests to, your external Persistent Scheduler application using the client libraries, please see the Client Library page.
| This presumes you already have a Persistent Scheduler application running. If you need to set one up please follow Embedded Implementation. |
Step 1: Add dependency
Import the scheduler-http-controller to get the Spring HTTP Controller in your Persistent Scheduler application:
<dependency>
<groupId>com.iconsolutions.ipf.core.platform</groupId>
<artifactId>scheduler-http-controller</artifactId>
</dependency>
Step 2: Create a SchedulingHelper and define it as a Spring bean
This is the class that will receive a notification to execute your job at a specific time with the given SchedulingCommand. SchedulingCommand 's are sent in the HTTP requests via the Client Library.
public static class MySchedulingHelper implements SchedulingHelper {
@Override
public CompletionStage<Void> execute(String id, SchedulingCommand command) {
//do some really important work here that can possibly take a long time...or not?
log.info("Look I'm being scheduled! The ID was: {}", id);
return CompletableFuture.completedFuture(null);
}
@Override
public boolean supports(SchedulingCommand command) {
return command instanceof MyCommand;
}
}
You will also need to define it as a bean:
@Bean
public SchedulingHelper mySchedulingHelper() {
return new MySchedulingHelper();
}
In the example above MyCommand is the implementation of SchedulingCommand that we define in Scheduling Your First Job (via HTTP Client Library). It is up to you to define the implementation of SchedulingCommand.
|
Step 3: Schedule your first job
Your application is now ready to receive its first HTTP request!
To send requests using the client library please follow the instructions on the Client Library page.
To send HTTP requests using your own client implementation please reference the Persistent Scheduler OpenAPI Specification page.