https://github.com/xaf/gcslock-ruby
Google Cloud Storage distributed locking for Ruby
https://github.com/xaf/gcslock-ruby
Last synced: about 6 hours ago
JSON representation
Google Cloud Storage distributed locking for Ruby
- Host: GitHub
- URL: https://github.com/xaf/gcslock-ruby
- Owner: XaF
- Created: 2020-05-19T21:13:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-02T22:24:41.000Z (over 5 years ago)
- Last Synced: 2024-10-02T21:48:49.465Z (almost 2 years ago)
- Language: Ruby
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gcslock-ruby
This is inspired by [the Golang version](https://github.com/marcacohen/gcslock).
## Google Cloud Storage setup
1. Setup a new project at the [Google APIs Console](https://console.developers.google.com) and enable the Cloud Storage API.
1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/downloads) tool and configure your project and your OAuth credentials.
1. Create a bucket in which to store your lock file using the command `gsutil mb gs://your-bucket-name`.
1. 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:
```ruby
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:
```ruby
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
```