This repository shows a simple example on how you can integrate JobRunr with spring.io. Other examples using spring.io can be found here and here.
In this example, we simulate an order fulfillment system. For this example, the fulfillment process starts after the customer completed the payment. This triggers the three following tasks:
- Send the order confirmation to the customer
- Notify the warehouse of the arrival of the order so work on the packaging can be swiftly done
- Initiate shipment by making a call to the carrier's booking API
Other tasks such as creating a sales report or resupplying the inventory are re-occurring and are best handled as RecurringJobs.
This example is focused on JobRunr side of things, we leave the implementation of object such as the Inventory, the Order, the Product, etc. as an exercise. Also the running of tasks is simulated by Thread.sleep(...) which implies explicit handling of
InterruptedException
, you probably won't need those in an actual application.
This project has 4 packages:
- org.jobrunr.examples.config: this package register the OrderFulfilmentTasksFilter
- org.jobrunr.examples.controllers: this package contains a simple
RestController
called OrderFulfillmentController, which declares an endpoint to trigger the order fulfillment workflow - org.jobrunr.examples.services: this package contains OrderFulfillmentService, a simple spring service with example order fulfillment methods.
- org.jobrunr.examples.tasks: this package contains OrderFulfillmentTasks which declares the Jobs for JobRunr to process using the handy annotations
- Note that the method annotated with
@Recurring
will be automatically picked up by JobRunr
- Note that the method annotated with
- clone the project and open it in your favorite IDE that supports gradle
- First, run the main method from the ExampleOrderFulfillmentApplication
- Open your favorite browser:
- Navigate to the JobRunr dashboard located at http://localhost:8000/dashboard.
- To trigger the order fulfillment workflow, open a new tab and go to http://localhost:8080/confirm-order.
- Visit the dashboard again and see the jobs being processed!
- Visit http://localhost:8000/jobs to see which states the jobs are in
- Visit http://localhost:8000/reccuring-jobs to see the recurring jobs. Have fun triggering them!