Kilian Schüttler 2137f4f073 Merge branch 'hotfix' into 'main'
hotfix NPE

See merge request fforesight/lifecycle-commons!1
2024-08-27 14:41:10 +02:00
2024-07-03 13:10:12 +03:00
2024-08-27 14:39:20 +02:00
2024-07-03 13:10:12 +03:00
2024-07-03 13:10:12 +03:00
2024-07-03 13:21:39 +03:00
2024-07-03 13:10:12 +03:00
2024-07-10 17:50:14 +03:00
2024-07-03 14:09:22 +03:00

lifecycle-commons

Getting started

The lifecycle commons package is used to monitor the lifeycle of the app and keep track of ongoing tasks in order to allow them to finish in case of an external shutdown. This allows pods to scale down without the risk of ongoing tasks being intrerrupted. Also it does not allow new tasks to be started once the shutdown process was initiated.

In order to use this you need to setup in application yaml the base-package property which is used in order to check methods inside that package for ongoing tasks:

lifecycle:
    base-package: com.knecon.fforesight

You also need to enable aspectj in your application main class via the annotation @EnableAspectJAutoProxy

The code will scan all requests from methods that are inside the specified package and that are annotated with one of the annotations present in the LifecycleAspect class.

@Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener) || "
        + "@annotation(com.knecon.fforesight.lifecyclecommons.LifecycleMonitor) || "
        + "@annotation(org.springframework.web.bind.annotation.GetMapping) || "
        + "@annotation(org.springframework.web.bind.annotation.PostMapping) || "
        + "@annotation(org.springframework.web.bind.annotation.PutMapping) || "
        + "@annotation(org.springframework.web.bind.annotation.DeleteMapping) || "
        + "@annotation(org.springframework.web.bind.annotation.RequestMapping))")
public Object checkLifecycle(ProceedingJoinPoint joinPoint) throws Throwable {

}

So any method that has one of the annotations present there, if it's being executed it will be tracked by incrementing the amount of ongoing tasks. Once the method has finished executing it will decrement the ongoing tasks. If at any point a shutdown is initiated and the amount of ongoing tasks is not 0, the termination process will wait until all ongoing tasks are completed. It will also not allow new tasks to be started, throwing back an exception.

If you want to monitor and keep track of other methods you can add annotations in the @Around part.

The LifecycleMonitor annotation is provided with the library, all methods that are annotated with this annotations will be monitored during a shutdown to make sure it finishes execution.

Description
No description provided
Readme 53 KiB
Release 0.7.0 Latest
2024-08-27 15:25:14 +02:00
Languages
Java 99.8%
Kotlin 0.2%