diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8104243..fc0ec5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,26 +18,34 @@ jobs: --health-retries 5 ports: # Maps port 6379 on service container to the host - - '6379:6379' + - "6379:6379" strategy: fail-fast: false matrix: - ruby-version: ['2.7', '3.0', '3.1', '3.2'] - gemfile: ['Gemfile', 'Gemfile.redis3', 'Gemfile.redis4'] + ruby-version: + - "3.0" + - "3.1" + - "3.2" + - "3.3" + resque-version: + - "~> 1.23" + redis-version: + - "~> 3.3" + - "~> 4.8" env: - # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }} + REDIS_VERSION: "${{ matrix.redis-version }}" + RESQUE: "${{ matrix.resque-version }}" + # The hostname used to communicate with the Redis service container + REDIS_TEST_HOST: localhost + # The default Redis port + REDIS_TEST_PORT: 6379 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Run tests - env: - # The hostname used to communicate with the Redis service container - REDIS_TEST_HOST: localhost - # The default Redis port - REDIS_TEST_PORT: 6379 run: bundle exec rake + diff --git a/.gitignore b/.gitignore index abc9a7d..46ff542 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ coverage/ .bundle/ dump.rdb stdout +.vscode diff --git a/Gemfile b/Gemfile index 851fabc..1239d56 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,27 @@ source 'https://rubygems.org' + +case resque_version = ENV.fetch('RESQUE', 'latest') +when 'master' + gem 'resque', git: 'https://github.com/resque/resque' +when /^git:/, /^https:/ + gem 'resque', git: resque_version +when 'latest' + gem 'resque' +else + versions = resque_version.split(',') + gem 'resque', *versions +end + +case redis_version = ENV.fetch('REDIS_VERSION', 'latest') +when 'master' + gem 'redis', git: 'https://github.com/redis/redis-rb' +when /^git:/, /^https:/ + gem 'redis', git: redis_version +when 'latest' + gem 'redis' +else + versions = redis_version.split(',') + gem 'redis', *versions +end + gemspec diff --git a/Gemfile.redis3 b/Gemfile.redis3 deleted file mode 100644 index 7283c0a..0000000 --- a/Gemfile.redis3 +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' -gemspec - -gem 'redis', '~> 3.3' -gem 'redis-namespace', '~> 1.5.3' diff --git a/Gemfile.redis4 b/Gemfile.redis4 deleted file mode 100644 index b19db31..0000000 --- a/Gemfile.redis4 +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' -gemspec - -gem 'redis', '~> 4.8' -gem 'redis-namespace', '~> 1.9' diff --git a/README.md b/README.md index 7c1775c..070d352 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Resque Lock Timeout -A [Resque][rq] plugin. Requires Resque ~> 1.23. +A [Resque][rq] plugin. Requires Resque ~> 1.23, redis-rb >= 3.3, < 5. + +This is a fork of [resque-lock-timeout][resque-lock-timeout] with testing and other fixes applied. + +---------- resque-lock-timeout adds locking, with optional timeout/deadlock handling to resque jobs. @@ -56,7 +60,7 @@ end The locking algorithm used can be found in the [Redis SETNX][redis-setnx] documentation. -Simply set the lock timeout in seconds, e.g. +Set the lock timeout in seconds, e.g. ```ruby class UpdateNetworkGraph @@ -76,9 +80,9 @@ end ### Job Identifier/Lock Key -By default the key uses this format: `lock::`. +By default, the key uses this format: `lock::`. -The default identifier is just your job arguments joined with a dash `-`. +The default identifier is your job arguments joined with a dash `-`. If you have a lot of arguments or really long ones, you should consider overriding `identifier` to define a more precise or loose custom identifier: @@ -123,7 +127,7 @@ That would use the key `lock:updates`. ### Redis Connection Used for Locking -By default all locks are stored via Resque's redis connection. If you wish to change this you may override `lock_redis`. +By default, all locks are stored via Resque's redis connection. If you wish to change this you may override `lock_redis`. ```ruby class UpdateNetworkGraph @@ -165,7 +169,7 @@ end - `enqueued?` - checks if the loner lock is currently held. - `loner_locked?` - checks if the job is either enqueued (if a loner) or locked (any job). - `refresh_lock!` - Refresh the lock, useful for jobs that are taking longer - then usual but your okay with them holding on to the lock a little longer. + then usual but you're okay with them holding on to the lock a little longer. ### Callbacks @@ -221,3 +225,4 @@ Forked from [a little tinkering from Luke Antins](https://github.com/lantins/res [redis-setnx]: http://redis.io/commands/setnx [resque-lock]: http://github.com/defunkt/resque-lock [resque-lock-retry]: http://github.com/rcarver/resque-lock-retry +[resque-lock-timeout]: https://github.com/lantins/resque-lock-timeout diff --git a/resque-lock-timeout.gemspec b/resque-lock-timeout.gemspec index 51d41f8..5d50089 100644 --- a/resque-lock-timeout.gemspec +++ b/resque-lock-timeout.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| - s.name = "resque-lock-timeout" - s.version = "0.5.0" + s.name = "ibotta-resque-lock-timeout" + s.version = "0.5.1" s.date = Time.now.strftime("%Y-%m-%d") s.summary = "A Resque plugin adding locking, with optional timeout/deadlock handling to resque jobs." s.license = "MIT" @@ -14,19 +14,21 @@ Gem::Specification.new do |s| s.add_dependency("resque", "~> 1.23") s.add_dependency("redis", ">= 3.3", "< 5") + s.add_development_dependency("rake") s.add_development_dependency("minitest") s.add_development_dependency("yard") s.add_development_dependency("simplecov") + s.add_development_dependency("debug") - s.description = <= 7 end