Project

gcslock

0.0
No commit activity in last 3 years
No release in over 3 years
Allows to use a Google Cloud Storage bucket as a distributed locking system
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

gcslock-ruby

This is inspired by the Golang version.

Google Cloud Storage setup

  1. Setup a new project at the Google APIs Console and enable the Cloud Storage API.
  2. Install the Google Cloud SDK tool and configure your project and your OAuth credentials.
  3. Create a bucket in which to store your lock file using the command gsutil mb gs://your-bucket-name.
  4. Enable object versioning in your bucket using the command gsutil versioning set on gs://your-bucket-name.

Using a mutex

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

Using a semaphore

In your Ruby code, require gcslock/semaphore and use it as follows:

require 'gcslock/semaphore'

number_of_permits = 10
s = GCSLock::Semaphore.new('your-bucket-name', 'my-file.lock', number_of_permits)
s.acquire
# Work that should be done when semaphore is acquired
s.release