From 6e74322ff128a8ebe6edda569119458474f67d8c Mon Sep 17 00:00:00 2001 From: Markus Doits Date: Thu, 7 Jan 2021 12:50:52 +0100 Subject: [PATCH 1/5] use monotonic time for retry timeout check --- lib/suo/client/base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/suo/client/base.rb b/lib/suo/client/base.rb index a886159..7fc87f7 100644 --- a/lib/suo/client/base.rb +++ b/lib/suo/client/base.rb @@ -132,10 +132,10 @@ module Suo end def retry_with_timeout - start = Time.now.to_f + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) retry_count.times do - elapsed = Time.now.to_f - start + elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start break if elapsed >= options[:acquisition_timeout] synchronize do From d57f6a15ac0c138d9eac370c9d0124a5db01e403 Mon Sep 17 00:00:00 2001 From: Matt Larraz Date: Wed, 20 Jan 2021 15:53:51 -0800 Subject: [PATCH 2/5] Switch to Github Actions and update supported Ruby versions --- .github/workflows/CI.yml | 38 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 9 --------- suo.gemspec | 4 ++-- 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/CI.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..e4de459 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: + - '2.5' + - '2.6' + - '2.7' + - '3.0' + - ruby-head + continue-on-error: ${{ matrix.ruby == 'ruby-head' }} + services: + memcached: + image: memcached + ports: + - 11211:11211 + redis: + image: redis + ports: + - 6379:6379 + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: | + bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4e2cd7e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: ruby -rvm: - - 2.2.6 - - 2.3.7 - - 2.4.4 - - 2.5.1 -services: - - memcached - - redis-server diff --git a/suo.gemspec b/suo.gemspec index 80c3b0d..cada028 100644 --- a/suo.gemspec +++ b/suo.gemspec @@ -19,14 +19,14 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.required_ruby_version = "~> 2.0" + spec.required_ruby_version = ">= 2.5" spec.add_dependency "dalli" spec.add_dependency "redis" spec.add_dependency "msgpack" spec.add_development_dependency "bundler" - spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rubocop", "~> 0.49.0" spec.add_development_dependency "minitest", "~> 5.5.0" spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4.7" From 3a37a7498280e7ac25ff55a67a4bdd148cb3bbf9 Mon Sep 17 00:00:00 2001 From: Matt Larraz Date: Thu, 19 Mar 2020 17:21:15 -0700 Subject: [PATCH 3/5] Support connection pooled Redis --- lib/suo/client/redis.rb | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/suo/client/redis.rb b/lib/suo/client/redis.rb index ee62e76..2a106c7 100644 --- a/lib/suo/client/redis.rb +++ b/lib/suo/client/redis.rb @@ -9,21 +9,31 @@ module Suo end def clear - @client.del(@key) + with { |r| r.del(@key) } end private + def with(&block) + if @client.respond_to?(:with) + @client.with(&block) + else + yield @client + end + end + def get - [@client.get(@key), nil] + [with { |r| r.get(@key) }, nil] end def set(newval, _, expire: false) - ret = @client.multi do |multi| - if expire - multi.setex(@key, @options[:ttl], newval) - else - multi.set(@key, newval) + ret = with do |r| + r.multi do |rr| + if expire + rr.setex(@key, @options[:ttl], newval) + else + rr.set(@key, newval) + end end end @@ -31,11 +41,9 @@ module Suo end def synchronize - @client.watch(@key) do - yield - end + with { |r| r.watch(@key) { yield } } ensure - @client.unwatch + with { |r| r.unwatch } end def initial_set(val = BLANK_STR) From 65cae9aa5842099c1ff8740b29157691af2d80d5 Mon Sep 17 00:00:00 2001 From: Nick Elser Date: Thu, 21 Jan 2021 10:32:06 -0800 Subject: [PATCH 4/5] update changelog & version --- CHANGELOG.md | 7 +++++++ lib/suo/version.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33edd76..df24509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.4.0 + +- Monotonic clock for locks, avoiding issues with DST (thanks @doits) +- Pooled connection support (thanks @mlarraz) +- Switch to Github actions for tests (thanks @mlarraz) +- Update supported Ruby versions (thanks @mlarraz & @pat) + ## 0.3.4 - Support for connection pooling when using memcached locks, via `with` blocks using Dalli (thanks to Lev). diff --git a/lib/suo/version.rb b/lib/suo/version.rb index 014d894..483521a 100644 --- a/lib/suo/version.rb +++ b/lib/suo/version.rb @@ -1,3 +1,3 @@ module Suo - VERSION = "0.3.4".freeze + VERSION = "0.4.0".freeze end From 7bb28cc0073bf7d6dc8b30f26b11a9b520678024 Mon Sep 17 00:00:00 2001 From: Nick Elser Date: Thu, 21 Jan 2021 10:38:29 -0800 Subject: [PATCH 5/5] update some badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a3923f..39a86b0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Suo [![Build Status](https://travis-ci.org/nickelser/suo.svg?branch=master)](https://travis-ci.org/nickelser/suo) [![Code Climate](https://codeclimate.com/github/nickelser/suo/badges/gpa.svg)](https://codeclimate.com/github/nickelser/suo) [![Test Coverage](https://codeclimate.com/github/nickelser/suo/badges/coverage.svg)](https://codeclimate.com/github/nickelser/suo) [![Gem Version](https://badge.fury.io/rb/suo.svg)](http://badge.fury.io/rb/suo) +# Suo [![Build Status](https://github.com/nickelser/suo/workflows/CI/badge.svg)](https://github.com/nickelser/suo/actions?query=workflow%3ACI) [![Code Climate](https://codeclimate.com/github/nickelser/suo/badges/gpa.svg)](https://codeclimate.com/github/nickelser/suo) [![Gem Version](https://badge.fury.io/rb/suo.svg)](http://badge.fury.io/rb/suo) :lock: Distributed semaphores using Memcached or Redis in Ruby.