https://github.com/kevcodez/spring-boot-track-scheduled-tasks
Keep track of scheduled tasks and their timings and exceptions in a Spring Boot 2 project
https://github.com/kevcodez/spring-boot-track-scheduled-tasks
java kotlin scheduler spring spring-aop spring-boot spring-scheduling
Last synced: about 1 month ago
JSON representation
Keep track of scheduled tasks and their timings and exceptions in a Spring Boot 2 project
- Host: GitHub
- URL: https://github.com/kevcodez/spring-boot-track-scheduled-tasks
- Owner: kevcodez
- License: mit
- Created: 2018-05-15T23:33:19.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-19T18:21:40.000Z (almost 7 years ago)
- Last Synced: 2025-03-29T17:23:35.500Z (2 months ago)
- Topics: java, kotlin, scheduler, spring, spring-aop, spring-boot, spring-scheduling
- Language: Kotlin
- Size: 92.8 KB
- Stars: 13
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# General
This project demonstrates the tracking of scheduled jobs using Spring AOP.
The tracking is fairly simple. The `ScheduledJobTrackingAspect` invokes every method with an `Scheduled` annotation and writes the start and end of the method into the `ScheduledJobTracker`.
A UUID is assigned to the job upon start, since a single job can run multiple times at once.The data is available via `ScheduledJobController`.
This is just a project demonstrating the tracking. I am considering to build a library that can be included in any spring boot project to enable tracking of scheduled tasks.
## Sample scheduled job
The demo has a very simple scheduled job, that prints *foo* every 5 seconds.
```kotlin
package com.example.demoimport org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component@Component
class ScheduledJob {@Scheduled(fixedRate = 5000)
fun println() = println("foo")}
```## Access data via REST
`GET /scheduled-jobs/`
```json
[
{
"className": "com.example.demo.ScheduledJob",
"methodName": "println",
"fixedRate": 5000,
"runs": [
{
"uuid": "c5ca5c73-f1f6-4ced-a911-de0e43a78d78",
"startedAt": "2018-05-15T23:38:11.177Z",
"endedAt": "2018-05-15T23:38:11.182Z",
"exception": null,
"duration": "PT0.005S"
},
{
"uuid": "2dd54fc3-8753-41c1-91d2-a7ec33fda0e8",
"startedAt": "2018-05-15T23:38:16.169Z",
"endedAt": "2018-05-15T23:38:16.169Z",
"exception": null,
"duration": "PT0S"
},
{
"uuid": "6be5d3ad-924e-4aa6-aef8-a4b837b3e67f",
"startedAt": "2018-05-15T23:38:21.170Z",
"endedAt": "2018-05-15T23:38:21.170Z",
"exception": null,
"duration": "PT0S"
},
{
"uuid": "72dc2d85-d2f1-4875-9381-3d26f6c6512c",
"startedAt": "2018-05-15T23:38:26.169Z",
"endedAt": "2018-05-15T23:38:26.169Z",
"exception": null,
"duration": "PT0S"
},
{
"uuid": "e4f635ee-625b-4618-84ee-0cb0c2aa210e",
"startedAt": "2018-05-15T23:38:31.169Z",
"endedAt": "2018-05-15T23:38:31.169Z",
"exception": null,
"duration": "PT0S"
}
],
"status": "Idle",
"averageDurationInMs": 1,
"lastDurationInMs": 0,
"lastRunStarted": "2018-05-15T23:38:31.169Z",
"lastRunEnded": "2018-05-15T23:38:31.169Z"
}
]
```