sequel-pg_advisory_locking 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1771c5e28c6e7a8b55584ec1fc5353658b122c00
4
+ data.tar.gz: 9fa671605e1aceb40e6a87ba6616feda99c78cb8
5
+ SHA512:
6
+ metadata.gz: 2cde2f0a6f2e4a82454f1eb19af9f76a656cd453150ddc309cf734e73333dc0da3678d7d8403807a5edb8a84c74f725aac1df42aac36b0f8141bc1c1fb62681c
7
+ data.tar.gz: 3a9f5723ae1f09233eaae56eee0abfa70d536fe9e02ef795097a580f1fcbc35928f7dbc561a951bb9c929109b57e5f05c8160c165b2397abc0eaad1e9f8c3a8a
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /Gemfile.lock
2
+ *.swp
3
+ *.gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ === 1.0.0 (2015-05-11)
2
+
3
+ * Initial Public Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cae-logger.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Chris Elsworth
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # sequel-pg_advisory_locking
2
+
3
+ sequel-pg_advisory_locking is a Sequel extension that adds support for [PostgreSQL's advisory locks](http://www.postgresql.org/docs/9.4/static/explicit-locking.html#ADVISORY-LOCKS).
4
+
5
+
6
+ ## Usage
7
+
8
+ This adds two methods to `Sequel::Database`.
9
+
10
+ Both methods require an integer key, which is passed directly to PostgreSQL's advisory locking functions.
11
+
12
+ `with_advisory_lock` will block and yield when it obtains the lock (pg_advisory_lock). It returns the value of the block.
13
+
14
+ DB.with_advisory_lock(1) do
15
+ has_exclusive_lock()
16
+ end
17
+
18
+
19
  DB.with_advisory_lock(1, exclusive: false) do
20
+ has_shared_lock()
1
21
  end
@@ -0,0 +1,37 @@
1
+ require 'sequel'
2
+
3
+ module Sequel
4
+ module Postgres
5
+ module PgAdvisoryLocking
6
+
7
+ def with_advisory_lock(id, opts = {}, &block)
8
+ exclusive = opts.fetch(:exclusive, true)
9
+ lockfn = exclusive ? :pg_advisory_lock : :pg_advisory_lock_shared
10
+ unlockfn = exclusive ? :pg_advisory_unlock : :pg_advisory_unlock_shared
11
+ yield_with_advisory_lock(id, lockfn, unlockfn, &block)
12
+ end
13
+
14
+ def try_advisory_lock(id, opts = {}, &block)
15
+ exclusive = opts.fetch(:exclusive, true)
16
+ lockfn = exclusive ? :pg_try_advisory_lock : :pg_try_advisory_lock_shared
17
+ unlockfn = exclusive ? :pg_advisory_unlock : :pg_advisory_unlock_shared
18
+ yield_with_advisory_lock(id, lockfn, unlockfn, &block)
19
+ end
20
+
21
+ private
22
+
23
+ def yield_with_advisory_lock(id, lockfn, unlockfn, &block)
24
+ if get(Sequel.function(lockfn, id))
25
+ begin
26
+ yield
27
+ ensure
28
+ get(Sequel.function(unlockfn, id))
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ Database.register_extension(:pg_advisory_locking, Postgres::PgAdvisoryLocking)
37
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sequel-pg_advisory_locking"
7
+ spec.version = '1.0.0'
8
+ spec.authors = ["Chris Elsworth"]
9
+ spec.email = ["chris@cae.me.uk"]
10
+ spec.summary = "Adds PostgreSQL advisory locking support to Sequel"
11
+ spec.homepage = "https://github.com/celsworth/sequel-pg_advisory_locking"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency 'sequel', '~> 0'
20
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-pg_advisory_locking
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Elsworth
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - chris@cae.me.uk
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - lib/sequel/extensions/pg_advisory_locking.rb
40
+ - sequel-pg_advisory_locking.gemspec
41
+ homepage: https://github.com/celsworth/sequel-pg_advisory_locking
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.4.5
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Adds PostgreSQL advisory locking support to Sequel
65
+ test_files: []
66
+ has_rdoc: