Method: ICFS::CacheElastic#lock_take
- Defined in:
- lib/icfs/cache_elastic.rb
#lock_take(cid) ⇒ Object
Take a case lock
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/icfs/cache_elastic.rb', line 180 def lock_take(cid) json = '{"client":"%s"}' % @name url = '%s/_doc/%s/_create' % [@map[:lock], CGI.escape(cid)] head = {'Content-Type' => 'application/json'}.freeze # try to take tries = 5 while tries > 0 resp = @es.run_request(:put, url, json, head) return true if resp.success? tries = tries - 1 sleep(0.1) end # failed to take lock raise('Elasticsearch lock take failed: %s' % cid) end |