locker 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3af785ef3147f838f184baa9f7843efd53b8e825
4
- data.tar.gz: 43c060bb7b1440a18c3c651dc5d348d072bf58cb
3
+ metadata.gz: 8ddf2a9f70dca510ad4dc728ce283dde0102e9a2
4
+ data.tar.gz: 5c7d2bfa20e1642815fed9ffab42d2f7ed9b982f
5
5
  SHA512:
6
- metadata.gz: 44ebab072cb5ce6790ca98770f87ab47e31acdcf1f6c0f2d2a72682f3e7d87724532e7ba6ec2df8db520098cd28ed0fa61639fd4ce6e6161149d677dbaf78dac
7
- data.tar.gz: f5268918d45c633d082f225bef6c69e5391d19e2e9b0a70163159ca5ed18172886203fe304c85ced60c9386ea7ee60fab4a7a9d275b989a41e68c46facf88b71
6
+ metadata.gz: b4ffe8ab76a4396b98292862e87837b82dd969aae85e55b02f3eab4cc0af582a95758dbc229dd027d38fd654539c1062ae7c868ab9fd791262585ee37459c836
7
+ data.tar.gz: e2185e9144a35d2fcf6206d4fbf546cc73f0443e0531a78f2310b1d8aea6eaee64a9422c271187d11315e69cee1228c4b6ed05a87310d4aa64e0e98095ee6e17
data/.gitignore CHANGED
@@ -1,6 +1,8 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ Gemfile_rails_3.lock
5
+ Gemfile_rails_4.lock
4
6
  pkg/*
5
7
  /spec/database.yml
6
8
  .rvmrc
@@ -3,8 +3,13 @@ gemfile:
3
3
  - Gemfile_rails_3
4
4
  - Gemfile_rails_4
5
5
  rvm:
6
- - ruby-2.1.8
7
- - ruby-2.2.4
8
- - ruby-2.3.0
9
- - jruby-9.0.4.0
6
+ - ruby-2.1.10
7
+ - ruby-2.2.7
8
+ - ruby-2.3.4
9
+ - ruby-2.4.1
10
+ - jruby-9.1.9.0
10
11
  script: bundle exec rspec
12
+ matrix:
13
+ exclude:
14
+ - rvm: ruby-2.4.1
15
+ gemfile: Gemfile_rails_3
data/Gemfile CHANGED
@@ -5,6 +5,8 @@ gem "activerecord", ">=3.2", "<5"
5
5
  group :development, :test do
6
6
  platform :ruby do
7
7
  gem "pg"
8
+ gem "pry", "~> 0.10.4"
9
+ gem "pry-byebug", "~> 3.4.2"
8
10
  end
9
11
 
10
12
  platform :jruby do
@@ -5,6 +5,8 @@ gem "activerecord", ">=3.2", "<4"
5
5
  group :development, :test do
6
6
  platform :ruby do
7
7
  gem "pg"
8
+ gem "pry", "~> 0.10.4"
9
+ gem "pry-byebug", "~> 3.4.2"
8
10
  end
9
11
 
10
12
  platform :jruby do
@@ -5,6 +5,8 @@ gem "activerecord", ">=4", "<5"
5
5
  group :development, :test do
6
6
  platform :ruby do
7
7
  gem "pg"
8
+ gem "pry", "~> 0.10.4"
9
+ gem "pry-byebug", "~> 3.4.2"
8
10
  end
9
11
 
10
12
  platform :jruby do
@@ -26,6 +26,11 @@ class Locker
26
26
  ensure_key_exists
27
27
  end
28
28
 
29
+ def self.prune(before)
30
+ m = model || ::Lock
31
+ m.where(["locked_until < ?", before]).delete_all
32
+ end
33
+
29
34
  def self.run(key, options={}, &block)
30
35
  locker = new(key, options)
31
36
  locker.run(&block)
@@ -1,3 +1,3 @@
1
1
  class Locker
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -19,4 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "activerecord", ">=3.2", "<5"
20
20
  s.add_development_dependency "pg", "~> 0"
21
21
  s.add_development_dependency "rspec", "~> 3.2"
22
+ s.add_development_dependency "pry", "~> 0.10.4"
23
+ s.add_development_dependency "pry-byebug", "~> 3.4.2"
22
24
  end
@@ -144,4 +144,19 @@ describe Locker do
144
144
  end
145
145
  end
146
146
 
147
+ describe "pruning" do
148
+ it "deletes old locks" do
149
+ l1 = Lock.create!(:key => "key1", :locked_until => 2.minutes.ago)
150
+ l2 = Lock.create!(:key => "key2", :locked_until => 4.minutes.ago)
151
+ l3 = Lock.create!(:key => "key3", :locked_until => 6.minutes.ago)
152
+ l4 = Lock.create!(:key => "key4", :locked_until => 8.minutes.ago)
153
+
154
+ Locker.prune(5.minutes.ago)
155
+
156
+ expect( Lock.where(:key => "key1").first ).to_not be_nil
157
+ expect( Lock.where(:key => "key2").first ).to_not be_nil
158
+ expect( Lock.where(:key => "key3").first ).to be_nil
159
+ expect( Lock.where(:key => "key3").first ).to be_nil
160
+ end
161
+ end
147
162
  end
@@ -5,6 +5,13 @@ require 'rubygems'
5
5
  require 'bundler/setup'
6
6
  require 'active_record'
7
7
 
8
+ begin
9
+ require 'pry'
10
+ require 'pry-byebug'
11
+ rescue LoadError
12
+ # jruby won't have these
13
+ end
14
+
8
15
  require 'locker'
9
16
 
10
17
  ActiveRecord::Base.time_zone_aware_attributes = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Sutton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-08 00:00:00.000000000 Z
12
+ date: 2017-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -59,6 +59,34 @@ dependencies:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.4
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.4
76
+ - !ruby/object:Gem::Dependency
77
+ name: pry-byebug
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.4.2
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.4.2
62
90
  description: Locker is a locking mechanism for limiting the concurrency of ruby code
63
91
  using the database. It presently only works with PostgreSQL.
64
92
  email: