lukas-krecan / ShedLock

Distributed lock for your scheduled tasks
Apache License 2.0
3.6k stars 510 forks source link

LockProvider for Mongo usingDbTime() #2116

Open jaquinod opened 1 month ago

jaquinod commented 1 month ago

Dears team,

I am using ShedLock with MongoDB. I had seen that it exists a feature to use db time for Postgres, MySQL, MariaDb, MS SQL, Oracle, DB2, HSQL and H2

=> Could you in the future add this feature for mongo please ? making usingDbTime() available :-)

Many thanks in advance,

Best Regards, Eddy from France

lukas-krecan commented 4 weeks ago

Hi, thanks for the proposal. The trouble is that AFAIK, Mongo does not support date arithmetics. In SQL, I can say lock_until = now() + 5 minutes, I don't think it's possible to do this in Mongo, or is it? Without that, I can't implement it.

jaquinod commented 3 weeks ago

Hi Lukas,

Thank you for your reply,

I can say that in mongo 5 for example it exists $dateAdd to increment a date

https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/

Hope it could help you,

Many thanks in advance to keep this feature for mongo in mind for the days you can have a solution :-)

ShedLock is a usefull tool for my need in all the cases and for many others users I think:-) "

Le jeu. 29 août 2024 à 20:45, Lukáš Křečan @.***> a écrit :

Hi, thanks for the proposal. The trouble is that AFAIK, Mongo does not support date arithmetics. In SQL, I can say lock_until = now() + 5 minutes, I don't think it's possible to do this in Mongo, or is it? Without that, I can't implement it.

— Reply to this email directly, view it on GitHub https://github.com/lukas-krecan/ShedLock/issues/2116#issuecomment-2318612170, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBFU74CUSDHOOSVFHSAPWDZT5T5HAVCNFSM6AAAAABNIJVPSGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJYGYYTEMJXGA . You are receiving this because you authored the thread.Message ID: @.***>

-- Bien Cordialement,

Eddy JAQUINOD

lukas-krecan commented 3 weeks ago

Cool, I will try it

lukas-krecan commented 3 weeks ago

Hi, I looked into that and there is one thing I don't know how to solve. Here, I need to write $lte(lockUntil, NOW) and I dont know how to send NOW from Java. In Mongo console, you can use Date(), but I don't think it's possible to use from Java. There is currentTimestamp function, but it can only be used to set value of a field. Any ideas how to do that? (I haven't used Mongo in years).

jaquinod commented 3 weeks ago

Hi Lukas,

First of all, thank you for trying to implement my request.

Usually, mongo has "$currentDate" for date coming from mongo's server : https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/

Perhaps, this stackoverflow's following links could help you : https://stackoverflow.com/questions/28986034/mongo-insert-currentdate-in-java-driver

Sometimes, I had seen that it could exists "$$NOW" as mongo system variable : https://www.mongodb.com/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.NOW

=> This link is about that variable : https://stackoverflow.com/questions/20620368/is-there-any-equivalent-of-now-in-mongodb

Many thanks in advance to you for taking time with me for trying to find a solution

Best Regards Eddy from France

Le mer. 4 sept. 2024 à 21:12, Lukáš Křečan @.***> a écrit :

Hi, I looked into that and there is one thing I don't know how to solve. Here https://github.com/lukas-krecan/ShedLock/pull/2129/files#diff-c61729a62e6580eea84ea3df5ac67683a3d7fd2540e9092a635d3377e7e3a050R96, I need to write $lte(lockUntil, NOW) and I dont know how to send NOW from Java. In Mongo console, you can use Date(), but I don't think it's possible to use from Java. There is currentTimestamp function, but it can only be used to set value of a field. Any ideas how to do that? (I haven't used Mongo in years).

— Reply to this email directly, view it on GitHub https://github.com/lukas-krecan/ShedLock/issues/2116#issuecomment-2329790456, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBFU74DWUP3EN44IRHUKHDZU5LRLAVCNFSM6AAAAABNIJVPSGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRZG44TANBVGY . You are receiving this because you authored the thread.Message ID: @.***>

-- Bien Cordialement,

Eddy JAQUINOD