activejob-lockable 0.1.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 664f6c1cc3b4fcaa153c34c1a3dd734c66a45dbbcfa751d79c23a24f2e5bcc58
4
- data.tar.gz: e1a97f5959d30c1357d77a2fe628e63a367215c08ee1c6e3bf57b33eb1faf4cd
3
+ metadata.gz: 17228343c0631b12e161a5107bcafca105666f2ae6427a390fa1abca3fbf6ecd
4
+ data.tar.gz: 0e6f680d5345f613ec56eee6c679762d5e8d1d8d7527b74bdd110b9cbfdeb0d5
5
5
  SHA512:
6
- metadata.gz: 45c4f6b76f35093fbf81926898794ccac7444b8aef051b16e7b6113956f65ef02a0fae3b3d1d8282758a226de4a6a712ddae4e3c426d5e6a488ffefb4e07955f
7
- data.tar.gz: 5343ddb76f4e63fe321604d2f73df42d98d89d030922489878db6b6e6c9af5e30d7dc1f0e5a650679e05e46b2f453e0a8ad2cbb73bc95561472efc601ba4a077
6
+ metadata.gz: 19975324abaee6a55dacb7b2f36ae3d822e54d5736085af01219f8190cd48993b999f0bdeb998a8691d203a45b44cef4b8dc02ac7b2244cc247ec96d959c4528
7
+ data.tar.gz: 40568b070ef7b83a7de563095c4dcded599b3efd3f6b531037a47540a0a9007087ef2d1281f915ce8c82cc4f17e88bffb7293397dded56c8b9cb29e1270e1f39
@@ -0,0 +1,35 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ paths:
8
+ - lib/activejob/lockable/version.rb
9
+
10
+ jobs:
11
+ build:
12
+ name: Build and publish
13
+ runs-on: ubuntu-latest
14
+ environment: master
15
+ permissions:
16
+ contents: read
17
+ packages: write
18
+
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - name: Set up Ruby 3.2
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: 3.2.2
25
+
26
+ - name: Publish to RubyGems
27
+ run: |
28
+ mkdir -p $HOME/.gem
29
+ touch $HOME/.gem/credentials
30
+ chmod 0600 $HOME/.gem/credentials
31
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
32
+ gem build *.gemspec
33
+ gem push *.gem
34
+ env:
35
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,27 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: ["master"]
6
+ pull_request:
7
+ branches: ["master"]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ ruby-version: ['3.0', '3.1', '3.2']
18
+
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
26
+ - name: Run tests
27
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # ActiveJob::Lockable [![Build Status](https://travis-ci.org/qonto/activejob-lockable.svg?branch=master)](https://travis-ci.org/qonto/activejob-lockable)
1
+ ![Gem Version](https://badge.fury.io/rb/activejob-lockable.svg) ![CI Status](https://github.com/qonto/activejob-lockable/actions/workflows/tests.yml/badge.svg)
2
+
3
+ # ActiveJob::Lockable
2
4
 
3
5
  Gem to make to make jobs lockable. Useful when a job is called N times, but only a single execution is needed.
4
6
 
@@ -17,7 +19,7 @@ And then execute:
17
19
  Or install it yourself as:
18
20
 
19
21
  $ gem install activejob-lockable
20
-
22
+
21
23
  ## Configuration
22
24
 
23
25
  Create an initializer with redis connection:
@@ -102,3 +104,7 @@ Bug reports and pull requests are welcome on GitHub at [qonto/activejob-lockable
102
104
  ## License
103
105
 
104
106
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
107
+
108
+ ## Releasing
109
+
110
+ To publish a new version to rubygems, update the version in `lib/activejob/lockable/version.rb`, and merge.
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'activejob'
24
24
  spec.add_dependency 'activesupport'
25
25
 
26
- spec.add_development_dependency 'bundler', '~> 1.15'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
- spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
29
  spec.add_development_dependency 'fakeredis'
30
30
  spec.add_development_dependency 'pry'
31
31
  end
@@ -16,31 +16,25 @@ module ActiveJob
16
16
 
17
17
  def enqueue(options = {})
18
18
  @options = options
19
- if locked?
20
- logger.info "Job is locked, expires in #{locked_ttl} second(s)"
21
- send(on_locked_action) if on_locked_action && respond_to?(on_locked_action)
22
- else
23
- lock!
24
- super(options)
25
- end
19
+ return trigger_on_locked_action unless lock!
20
+
21
+ super(options)
26
22
  end
27
23
 
28
24
  def lock!
29
- return if lock_period.to_i <= 0
25
+ return true if lock_period.to_i <= 0
30
26
  logger.info "Acquiring lock #{lock_extra_info}"
31
- begin
32
- # `:ex => Fixnum`: Set the specified expire time, in seconds.
33
- # `:nx => true`: Only set the key if it does not already exist.
34
- lock_acquired = ActiveJob::Lockable::RedisStore.set(
35
- lock_key,
36
- self.job_id,
37
- { ex: lock_period.to_i, nx: true }
38
- )
39
- raise "Could not acquire lock #{lock_extra_info}" unless lock_acquired
40
- rescue StandardError => e
41
- logger.info "EXCEPTION acquiring lock #{lock_extra_info}"
42
- raise
43
- end
27
+ # `:ex => Fixnum`: Set the specified expire time, in seconds.
28
+ # `:nx => true`: Only set the key if it does not already exist.
29
+ # Returns boolean, lock acquired or not
30
+ ActiveJob::Lockable::RedisStore.set(
31
+ lock_key,
32
+ self.job_id,
33
+ { ex: lock_period.to_i, nx: true }
34
+ )
35
+ rescue StandardError => e
36
+ logger.info "EXCEPTION acquiring lock #{lock_extra_info}"
37
+ raise
44
38
  end
45
39
 
46
40
  def unlock!
@@ -55,7 +49,7 @@ module ActiveJob
55
49
  end
56
50
 
57
51
  def locked?
58
- ActiveJob::Lockable::RedisStore.exists?(lock_key)
52
+ ActiveJob::Lockable::RedisStore.exists?(lock_key) != 0
59
53
  end
60
54
 
61
55
  def locked_ttl
@@ -70,6 +64,11 @@ module ActiveJob
70
64
  options[:lock].to_i
71
65
  end
72
66
 
67
+ def trigger_on_locked_action
68
+ logger.info "Job is locked, expires in #{locked_ttl} second(s)"
69
+ public_send(on_locked_action) if on_locked_action && respond_to?(on_locked_action)
70
+ end
71
+
73
72
  def lock_extra_info
74
73
  "[key #{lock_key}] [seconds #{lock_period.to_i}] [job_id #{self.job_id}] [class_name: #{self.class}]"
75
74
  end
@@ -3,7 +3,7 @@ module ActiveJob
3
3
  class RedisStore
4
4
  class << self
5
5
  def set(cache_key, cache_value, options = {})
6
- ActiveJob::Lockable.redis.set(cache_key, cache_value, options)
6
+ ActiveJob::Lockable.redis.set(cache_key, cache_value, **options)
7
7
  end
8
8
 
9
9
  def exists?(cache_key)
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module Lockable
3
- VERSION = '0.1.5'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-lockable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmytro Zakharov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2023-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -42,44 +42,44 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.15'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.15'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: fakeredis
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -115,9 +115,10 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/rubygems.yml"
119
+ - ".github/workflows/tests.yml"
118
120
  - ".gitignore"
119
121
  - ".rspec"
120
- - ".travis.yml"
121
122
  - Gemfile
122
123
  - LICENSE.txt
123
124
  - README.md
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  - !ruby/object:Gem::Version
149
150
  version: '0'
150
151
  requirements: []
151
- rubygems_version: 3.0.3
152
+ rubygems_version: 3.4.10
152
153
  signing_key:
153
154
  specification_version: 4
154
155
  summary: Prevents jobs from enqueuing with unique arguments for a certain period of
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.2
5
- deploy:
6
- skip_cleanup: true
7
- provider: rubygems
8
- api_key:
9
- secure: aD0lrk/+PZnWSJVdDRHFB6kzea1dmJl1nlWXMsyr0s5FlXPGuF1O01LEJIxQSNhl2AiA/yQBbT/ldcEsYyzYvRJWlkXbzzfTNa3pl0MYM3U7lDfAA9oJn2Xis/jiW7pI+vEehIA+6V5rr/V1KBNrxxveWQhcpfiQi7p6efF/XBugCqNhVW8G/NLN2S2Zi5ITFekAHoubYh1h0stFqnt9pxKLlm3eTBjs77DsMtLZtoy5KIMptRCOxTSOGteqFy/saeDWEPTWJWaKZ6zJ4bCQG15WJIJ+J+zcCO3kTD+hZUGkOgsy/lYuwOPu845f16kstPVBkqbcxbCdrQaI5sgwwdGNLF14yzwFS8c309ZC9Wnx6QsfPdQjV6Ol4ZTufVqi3EMEmvJQ78gX2T3J8E/6Cer4Ay2vrny5SyzekFSbGcMPr++iGk4JVn/jgEulAxMvDJoqdrJhETCKAcPlk1EesPUPP5JuXuW6HfDXNEYvv7Bzo2xVuaUsNvSMLsbZai7E2PchkBYApIKg9A6hFkt7ymiAIszMiSDuIj90aBtKpOIoMw6TyRp/x0qXJkPw2UOO22YJHeJanEjKtc2jk3r65FPCRKna3GcHXBXGAcJTKP2fJdBcRKtB7Y/SjRq84uDZJxwNKRBfyCittpMuu20uln+ylQzE9hnM28O7dOUfNBs=
10
- gem: activejob-lockable
11
- on:
12
- tags: true
13
- repo: qonto/activejob-lockable