Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zhengfc opened this issue Jul 6, 2018 · 5 comments
Open

Comments

@zhengfc
Copy link

zhengfc commented Jul 6, 2018

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

@lukas-krecan
Copy link
Owner

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.

@zhengfc
Copy link
Author

zhengfc commented Sep 20, 2018

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.

@ivaylo5ev
Copy link

ivaylo5ev commented Jan 24, 2020

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.

@zHaytam
Copy link

zHaytam commented Jul 7, 2020

@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.

@ivaylo5ev
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants