| Line 36... |
Line 36... |
| 36 |
*/
|
36 |
*/
|
| 37 |
@Around("@annotation(org.springframework.scheduling.annotation.Scheduled)")
|
37 |
@Around("@annotation(org.springframework.scheduling.annotation.Scheduled)")
|
| 38 |
public Object monitorCronJob(ProceedingJoinPoint joinPoint) throws Throwable {
|
38 |
public Object monitorCronJob(ProceedingJoinPoint joinPoint) throws Throwable {
|
| 39 |
String methodName = joinPoint.getSignature().toShortString();
|
39 |
String methodName = joinPoint.getSignature().toShortString();
|
| 40 |
log.info("Cron job {} started", methodName);
|
40 |
log.info("Cron job {} started", methodName);
|
| 41 |
System.out.println("Cron job " + methodName + " started");
|
- |
|
| 42 |
long startTime = System.currentTimeMillis();
|
41 |
long startTime = System.currentTimeMillis();
|
| 43 |
|
42 |
|
| 44 |
try {
|
43 |
try {
|
| 45 |
// Proceed with the scheduled method
|
44 |
// Proceed with the scheduled method
|
| 46 |
Object result = joinPoint.proceed();
|
45 |
Object result = joinPoint.proceed();
|
| 47 |
long elapsed = System.currentTimeMillis() - startTime;
|
46 |
long elapsed = System.currentTimeMillis() - startTime;
|
| 48 |
|
47 |
|
| 49 |
log.info("Cron job {} completed successfully in {} ms", methodName, elapsed);
|
48 |
log.info("Cron job {} completed successfully in {} ms", methodName, elapsed);
|
| 50 |
System.out.println("Cron job " + methodName + " completed successfully in " + elapsed + " ms");
|
- |
|
| 51 |
|
49 |
|
| 52 |
try {
|
50 |
try {
|
| 53 |
meterRegistry.counter("custom.cron.success.count", "method", methodName, "status", "success")
|
51 |
meterRegistry.counter("custom.cron.success.count", "method", methodName, "status", "success")
|
| 54 |
.increment();
|
52 |
.increment();
|
| 55 |
meterRegistry.timer("custom.cron.execution.time", "method", methodName, "status", "success")
|
53 |
meterRegistry.timer("custom.cron.execution.time", "method", methodName, "status", "success")
|
| Line 60... |
Line 58... |
| 60 |
|
58 |
|
| 61 |
return result;
|
59 |
return result;
|
| 62 |
} catch (Throwable ex) {
|
60 |
} catch (Throwable ex) {
|
| 63 |
long elapsed = System.currentTimeMillis() - startTime;
|
61 |
long elapsed = System.currentTimeMillis() - startTime;
|
| 64 |
log.error("Cron job {} failed in {} ms: {}", methodName, elapsed, ex.toString());
|
62 |
log.error("Cron job {} failed in {} ms: {}", methodName, elapsed, ex.toString());
|
| 65 |
System.out.println("Cron job " + methodName + " failed in " + elapsed + " ms");
|
- |
|
| 66 |
|
63 |
|
| 67 |
try {
|
64 |
try {
|
| 68 |
meterRegistry.counter("custom.cron.failure.count", "method", methodName, "status", "failure")
|
65 |
meterRegistry.counter("custom.cron.failure.count", "method", methodName, "status", "failure")
|
| 69 |
.increment();
|
66 |
.increment();
|
| 70 |
meterRegistry.timer("custom.cron.execution.time", "method", methodName, "status", "failure")
|
67 |
meterRegistry.timer("custom.cron.execution.time", "method", methodName, "status", "failure")
|