{"action":"created","issue":{"url":"https://api.github.com/repos/kenn/redis-mutex/issues/22","labels_url":"https://api.github.com/repos/kenn/redis-mutex/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/kenn/redis-mutex/issues/22/comments","events_url":"https://api.github.com/repos/kenn/redis-mutex/issues/22/events","html_url":"https://github.com/kenn/redis-mutex/issues/22","id":120296220,"number":22,"title":"Incremental lock","user":{"login":"alex88","id":436888,"avatar_url":"https://avatars.githubusercontent.com/u/436888?v=3","gravatar_id":"","url":"https://api.github.com/users/alex88","html_url":"https://github.com/alex88","followers_url":"https://api.github.com/users/alex88/followers","following_url":"https://api.github.com/users/alex88/following{/other_user}","gists_url":"https://api.github.com/users/alex88/gists{/gist_id}","starred_url":"https://api.github.com/users/alex88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex88/subscriptions","organizations_url":"https://api.github.com/users/alex88/orgs","repos_url":"https://api.github.com/users/alex88/repos","events_url":"https://api.github.com/users/alex88/events{/privacy}","received_events_url":"https://api.github.com/users/alex88/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-03T23:28:34Z","updated_at":"2015-12-04T08:05:10Z","closed_at":"2015-12-04T06:47:10Z","body":"Hi there,\r\n\r\nI've actually this code:\r\n\r\n```ruby\r\nmutex = RedisMutex.new lock_key(feed, user), block: 300, sleep: 0.5, expire: 300\r\nif mutex.locked?\r\n  Rails.logger.info 'Another feed is in processing, waiting for that and returning'\r\n  # Another feed is running, just wait for the lock to expire and end\r\n  mutex.unlock if mutex.lock\r\n  Rails.logger.info 'Other feed finished, returning'\r\nelse\r\n  # Not locked, aquire the lock and process the feed\r\n  Rails.logger.info 'No feed are processing, acquiring lock'\r\n  mutex.with_lock do\r\n    Rails.logger.info 'feed lock acquired, processing feed'\r\n    teams = get_teams(feed)\r\n    teams.each { |team| sync_team(team, feed, user) }\r\n    Rails.logger.info 'feed finished, releasing lock'\r\n  end\r\nend\r\n```\r\n\r\nrunning in a Sidekiq job in Heroku, this works fine, except when due a scale down the job is being SIGKILLed since the `teams.each` loop isn't exited in 10 seconds (heroku default KILL timeout).\r\n\r\nIs there a way, inside the `with_lock` thing, to increase the expire time of the lock? Something like:\r\n\r\n```ruby\r\nmutex.with_lock do\r\n  Rails.logger.info 'feed lock acquired, processing feed'\r\n  teams = get_teams(feed)\r\n  teams.each do |team|\r\n    sync_team(team, feed, user)\r\n    mutex.lock_until(now + 10 .seconds)\r\n  end\r\n  Rails.logger.info 'feed finished, releasing lock'\r\nend\r\n```\r\n\r\nthis lets me lower down the expire time to 10 seconds and incrementally increase the expire time so that if the process is killed the lock is still active only for at max 10 seconds, not the remaining time to 300 seconds. "},"comment":{"url":"https://api.github.com/repos/kenn/redis-mutex/issues/comments/161904274","html_url":"https://github.com/kenn/redis-mutex/issues/22#issuecomment-161904274","issue_url":"https://api.github.com/repos/kenn/redis-mutex/issues/22","id":161904274,"user":{"login":"alex88","id":436888,"avatar_url":"https://avatars.githubusercontent.com/u/436888?v=3","gravatar_id":"","url":"https://api.github.com/users/alex88","html_url":"https://github.com/alex88","followers_url":"https://api.github.com/users/alex88/followers","following_url":"https://api.github.com/users/alex88/following{/other_user}","gists_url":"https://api.github.com/users/alex88/gists{/gist_id}","starred_url":"https://api.github.com/users/alex88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex88/subscriptions","organizations_url":"https://api.github.com/users/alex88/orgs","repos_url":"https://api.github.com/users/alex88/repos","events_url":"https://api.github.com/users/alex88/events{/privacy}","received_events_url":"https://api.github.com/users/alex88/received_events","type":"User","site_admin":false},"created_at":"2015-12-04T08:05:10Z","updated_at":"2015-12-04T08:05:10Z","body":"I don't want to prevent the process to be SIGKILLed or anything like that, I want, if possible, to be able to set a low default lock expire time and increase it while in the loop, something like \"hey, I'm still running, keep the lock open for another minute\" and so on.\r\n\r\nIf it gets killed and for some reason it doesn't release the lock, other workers has just to wait 1 minute or less"}}