gcslock-ruby
This is inspired by the Golang version.
Google Cloud Storage setup
- Setup a new project at the Google APIs Console and enable the Cloud Storage API.
- Install the Google Cloud SDK tool and configure your project and your OAuth credentials.
- Create a bucket in which to store your lock file using the command
gsutil mb gs://your-bucket-name
. - Enable object versioning in your bucket using the command
gsutil versioning set on gs://your-bucket-name
. - In your Ruby code, require
gcslock/mutex
and use it as follows:
require 'gcslock/mutex'
m = GCSLock::Mutex.new('your-bucket-name', 'my-file.lock')
m.synchronize do
// Protected and globally serialized computation happens here.
end