ShedLock icon indicating copy to clipboard operation
ShedLock copied to clipboard

Is it possible add a global @SingleUse for spring boot application?

Open zhengfc opened this issue 7 years ago • 5 comments

Hope add global definition for spring-boot application. For example, if I add annotation at spring boot launch class, will guard all task execute once in nodes:

@SpringBootAppliction  
@EnableScheduling  
@SingleUse  

Thanks for any reply

zhengfc avatar Jul 06 '18 01:07 zhengfc

Hi, thanks for feedback and sorry for the delay. If I understand you correctly, you want to add one annotation which would automatically put lock on all scheduled tasks? It is quite easy to implement but I am afraid that it's a bit dangerous. We need a name for each lock and the only way to generated it automatically is to use method signature - ClassName.methodName(). In my opinion it's quite fragile since you can rename the class or the method and when you deploy the change only to part of the cluster, the task will be executed twice. That's why I hesitate to add it.

lukas-krecan avatar Aug 19 '18 13:08 lukas-krecan

Hi, thanks for you reply. As you said, you use a method name as lock signature. Some time we deploy for change part of the cluster in AB test, I think job or task as AB test in application is not suitable. So, if you check some method have specific annotation you automatically disable global annotation. Of course, it's just my opinion.

zhengfc avatar Sep 20 '18 06:09 zhengfc

Or maybe just provide the lock name in the annotation? Like this:

@SingleUse(lockName = "MY_SINGLE_USE_LOCK")
...

Of course, users would need to know what to worry about, but IMHO an annotation parameter is more likely to survive than a method signature name.

stackh34p avatar Jan 24 '20 12:01 stackh34p

@ivaylo5ev This would mean only one task would run, which isn't the desired behavior no? @zhengfc Maybe as a fallback, check if the class has a Component annotation and a name set? That should be unique enough.

zHaytam avatar Jul 07 '20 11:07 zHaytam

@zHaytam , yes it would and this is NOT the desired behaviour indeed. I have misread / misunderstood the initial request, so ignore my comment above.

stackh34p avatar Jul 13 '20 15:07 stackh34p