swarthy / redis-semaphore

Distributed mutex and semaphore based on Redis
MIT License
148 stars 28 forks source link

Explain `refreshInterval` #200

Closed mbrevda closed 6 months ago

mbrevda commented 8 months ago

Could you kindly elaborate on why refreshInterval is useful? It looks like we need to disable it (keep on losing locks when using identifier) and I'm wondering what we'll be missing without it.

Thanks!

swarthy commented 6 months ago

Hi! refreshInterval is useful when execution time of task processing varies greatly (e.g., from a few seconds to an hour). Without this feature in this case you would have to set lockTimeout = maximum expected time of task processing (an hour). As a result, if, for example, the application is restarted in the middle of this period, the lock would continue to hang for an hour.

With refreshInterval you can specify lockTimeout for example 1 minute and periodically update the lock, so in case of restarting the application you will have to wait not more than one minute, not an hour.

mbrevda commented 6 months ago

thanks!