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

SpEL referencing method parameter not working #1284

Closed
spekdrum opened this issue Dec 16, 2022 · 7 comments
Closed

SpEL referencing method parameter not working #1284

spekdrum opened this issue Dec 16, 2022 · 7 comments

Comments

@spekdrum
Copy link

spekdrum commented Dec 16, 2022

Since 0.17.0 version ShedLock supports SpEL, but this is not working:

@SchedulerLock(name = "{#hotelCode}", lockAtMostFor = "60s")
public void printMessage(final String hotelCode, final String message) {
...
}

This is what we get in Redis:
imagen

Also tried withoud curly braces "{ }"

@lukas-krecan
Copy link
Owner

Thanks for reporting. I will look into that.

@lukas-krecan
Copy link
Owner

Hi, this is surprisingly hard to implement. Have you seen any annotation other than @Cacheable supporting this?

@ipalbeniz
Copy link

I found an example in this article, maybe it will help you understand how it could be done: https://www.springcloud.io/post/2022-03/spel-aop-log/

@lukas-krecan
Copy link
Owner

Hi, I try to focus the library for the original purpose - scheduled task lock. I am afraid your use-case is out of the scope. That being said, you can use this approach which should solve your use-case.

@spekdrum
Copy link
Author

spekdrum commented Dec 20, 2022

Hi Lukas, I understand your point. IMHO the @SchedulerLock annotation is one of the key points of this library. It would be great to comply with this SpEL use case giving a wider support. The need to partition your locks can be a common requirement for big projects, for example, partition a lock per hotel for a method instead of locking for the entire hotel chain. I know this can be done programatically, as you pointed at the documentation, but if this could be done just using an annotation and SpEL it would be great.

@lukas-krecan
Copy link
Owner

Hi, please correct me if I am wrong, but I do not think there is any SpEL spec of how to resolve method parameters. The only place I could find is the Cacheable annotation and the code seems to be really specific for the use-case of Caching.

Moreover, your use-case is clearly not scheduling but generic locking.

That being said, if you want to, you can submit a PR. If it does not bring too much complexity to the project, I will be happy to merge it. Otherwise, please implement it just for your project, Spring AOP is not that hard.

Repository owner deleted a comment from Yannis-01 Dec 21, 2022
lukas-krecan added a commit that referenced this issue Jan 6, 2023
#1284 Added SpEL support to @SchedulerLock name attribute
@lukas-krecan
Copy link
Owner

Released as 5.1.0

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

3 participants