active_record_mutex 3.2.1 → 3.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 +4 -4
- data/CHANGES.md +25 -0
- data/README.md +67 -46
- data/Rakefile +5 -1
- data/active_record_mutex.gemspec +6 -6
- data/lib/active_record/database_mutex/version.rb +1 -1
- metadata +11 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf654fec02b6d69bd364a26520e1ee2308988193b2938ff514e61bb202661a42
|
|
4
|
+
data.tar.gz: f4cdcb9803f4db880ccda320bef2ca58c680be9365ca696069afd7c1781968c3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb44138a04d61609b26bd89dcc4ab663231768d4c9763b215c42161974705ed65a0bd2aa1fd911b2b0dabf2f5792ea842c93366d6b4432bbbf55fd317cf4bb7d
|
|
7
|
+
data.tar.gz: c0bb4dfdbd775a767690881bf3e2973caf70aa454c765d7ef4294b5853bdd05af09e7c9e712deece3d3b1d3b604a5aebe3e211765363eb19cf966015af0bc4ae
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-01-02 v3.3.0
|
|
4
|
+
|
|
5
|
+
- Updated `all_images` development dependency from version **0.6** to
|
|
6
|
+
**0.11.2** in `active_record_mutex.gemspec`
|
|
7
|
+
- Enabled MariaDB TLS peer verification disable option via environment variable
|
|
8
|
+
in `.all_images.yml`
|
|
9
|
+
- Added `yaml-dev` and `openssl-dev` packages to Alpine package installation in
|
|
10
|
+
`.all_images.yml`
|
|
11
|
+
- Updated Ruby gem system and installed `bundler` and `gem_hadar` using `gem
|
|
12
|
+
update --system` and `gem install`
|
|
13
|
+
- Replaced `bundle install --full-index` with `bundle update --all` and `bundle
|
|
14
|
+
install --jobs=$(getconf _NPROCESSORS_ONLN)`
|
|
15
|
+
- Added `ruby:4.0-alpine` image configuration to the test suite
|
|
16
|
+
- Updated `s.date` from **2024-10-16** to **1980-01-02**
|
|
17
|
+
- Updated `s.rubygems_version` from **3.5.18** to **4.0.2**
|
|
18
|
+
- Updated `gem_hadar` development dependency from version **~> 1.19** to **>=
|
|
19
|
+
2.16.3**
|
|
20
|
+
- Added `changelog` block in `Rakefile` to specify `CHANGES.md` as the
|
|
21
|
+
changelog filename
|
|
22
|
+
- Removed binary detection config in file discovery
|
|
23
|
+
- Updated Docker image for Ruby **3.4**
|
|
24
|
+
- Added support for Ruby **3.4**-alpine images
|
|
25
|
+
- Removed support for Ruby **3.2**-alpine images
|
|
26
|
+
- Added fenced codeblocks for syntax highlighter hints in README.md
|
|
27
|
+
|
|
3
28
|
## 2024-10-16 v3.2.1
|
|
4
29
|
|
|
5
30
|
* Refactor DatabaseMutex implementation:
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ActiveRecord
|
|
1
|
+
# ActiveRecord Database Mutex
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
4
|
|
|
@@ -10,11 +10,16 @@ ruby processes (also on different hosts) via the connected database.
|
|
|
10
10
|
|
|
11
11
|
You can use rubygems to fetch the gem and install it for you:
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
```bash
|
|
14
|
+
gem install active_record_mutex
|
|
15
|
+
```
|
|
14
16
|
|
|
15
17
|
You can also put this line into your Gemfile
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
```ruby
|
|
20
|
+
# Gemfile
|
|
21
|
+
gem 'active_record_mutex'
|
|
22
|
+
```
|
|
18
23
|
|
|
19
24
|
## Usage
|
|
20
25
|
|
|
@@ -22,25 +27,31 @@ You can also put this line into your Gemfile
|
|
|
22
27
|
|
|
23
28
|
To synchronize on a specific ActiveRecord instance you can do this:
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
```ruby
|
|
31
|
+
class Foo < ActiveRecord::Base
|
|
32
|
+
end
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
foo = Foo.find(666)
|
|
35
|
+
foo.mutex.synchronize do
|
|
36
|
+
# Critical section of code here
|
|
37
|
+
end
|
|
38
|
+
```
|
|
32
39
|
|
|
33
40
|
If you want more control over the mutex and/or give it a special name you can
|
|
34
41
|
create Mutex instance like this:
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
```ruby
|
|
44
|
+
my_mutex = ActiveRecord::DatabaseMutex.for('my_mutex')
|
|
45
|
+
``````
|
|
37
46
|
|
|
38
47
|
Now you can send all messages directly to the Mutex instance or use the custom
|
|
39
48
|
mutex instance to `synchronize` method calls or other operations:
|
|
40
49
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
```ruby
|
|
51
|
+
my_mutex.synchronize do
|
|
52
|
+
# Critical section of code here
|
|
53
|
+
end
|
|
54
|
+
```
|
|
44
55
|
|
|
45
56
|
### Low-Level Demonstration: Multiple Process Example
|
|
46
57
|
|
|
@@ -51,50 +62,54 @@ rather to illustrate the underlying behavior.
|
|
|
51
62
|
If two processes are connected to the same database, configured via e.g.
|
|
52
63
|
`DATABASE_URL=mysql2://root@127.0.0.1:3336/test` and this is process 1:
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
```ruby
|
|
66
|
+
# process1.rb
|
|
67
|
+
…
|
|
68
|
+
mutex = ActiveRecord::DatabaseMutex.for('my_mutex')
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
lock_result1 = mutex.lock(timeout: 5)
|
|
71
|
+
puts "Process 1: Lock acquired (first): #{lock_result1}"
|
|
60
72
|
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
puts "Process 1: Waiting for 10s"
|
|
74
|
+
sleep(10)
|
|
63
75
|
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
lock_result2 = mutex.lock(timeout: 5)
|
|
77
|
+
puts "Process 1: Lock acquired (second): #{lock_result2}"
|
|
66
78
|
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
mutex.unlock # first
|
|
80
|
+
mutex.unlock # second
|
|
69
81
|
|
|
70
|
-
|
|
82
|
+
puts "Process 1: Unlocked the mutex twice"
|
|
71
83
|
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
puts "Process 1: Waiting for 10s"
|
|
85
|
+
sleep(10)
|
|
74
86
|
|
|
75
|
-
|
|
87
|
+
puts "Process 1: Exiting"
|
|
88
|
+
```
|
|
76
89
|
|
|
77
90
|
and this process 2:
|
|
78
91
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
92
|
+
```ruby
|
|
93
|
+
# process2.rb
|
|
94
|
+
…
|
|
95
|
+
mutex = ActiveRecord::DatabaseMutex.for('my_mutex')
|
|
82
96
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
97
|
+
begin
|
|
98
|
+
lock_result3 = mutex.lock(timeout: 5)
|
|
99
|
+
puts "Process 2: Lock acquired (first): #{lock_result3}"
|
|
100
|
+
rescue ActiveRecord::DatabaseMutex::MutexLocked
|
|
101
|
+
puts "Process 2: Mutex locked by another process, waiting..."
|
|
102
|
+
end
|
|
89
103
|
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
puts "Process 2: Waiting for 10s"
|
|
105
|
+
sleep(10)
|
|
92
106
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
107
|
+
puts "Process 2: Trying to lock again"
|
|
108
|
+
lock_result4 = mutex.lock(timeout: 5)
|
|
109
|
+
puts "Process 2: Lock acquired (second): #{lock_result4}"
|
|
96
110
|
|
|
97
|
-
|
|
111
|
+
puts "Process 2: Exiting"
|
|
112
|
+
```
|
|
98
113
|
|
|
99
114
|
Running these processes in parallel will output the following:
|
|
100
115
|
|
|
@@ -120,15 +135,21 @@ files, `.envrc` (`direnv allow`) and `docker-compose.yml`
|
|
|
120
135
|
First start mysql in docker via `docker compose up -d` and configure your
|
|
121
136
|
environment via `direnv allow` as before and then run
|
|
122
137
|
|
|
123
|
-
|
|
138
|
+
```bash
|
|
139
|
+
rake test
|
|
140
|
+
```
|
|
124
141
|
|
|
125
142
|
or with coverage:
|
|
126
143
|
|
|
127
|
-
|
|
144
|
+
```bash
|
|
145
|
+
rake test START_SIMPLECOV=1
|
|
146
|
+
```
|
|
128
147
|
|
|
129
148
|
To test for different ruby versions in docker, run:
|
|
130
149
|
|
|
131
|
-
|
|
150
|
+
```bash
|
|
151
|
+
all_images
|
|
152
|
+
```
|
|
132
153
|
|
|
133
154
|
## Download
|
|
134
155
|
|
data/Rakefile
CHANGED
|
@@ -19,10 +19,14 @@ GemHadar do
|
|
|
19
19
|
readme 'README.md'
|
|
20
20
|
licenses << 'GPL-2'
|
|
21
21
|
|
|
22
|
+
changelog do
|
|
23
|
+
filename 'CHANGES.md'
|
|
24
|
+
end
|
|
25
|
+
|
|
22
26
|
dependency 'mysql2', '~> 0.3'
|
|
23
27
|
dependency 'activerecord', '>= 4.0'
|
|
24
28
|
dependency 'ostruct', '~> 0.6'
|
|
25
|
-
development_dependency 'all_images', '
|
|
29
|
+
development_dependency 'all_images', '>= 0.11.2'
|
|
26
30
|
development_dependency 'test-unit', '~> 3.0'
|
|
27
31
|
development_dependency 'debug'
|
|
28
32
|
development_dependency 'simplecov'
|
data/active_record_mutex.gemspec
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: active_record_mutex 3.
|
|
2
|
+
# stub: active_record_mutex 3.3.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "active_record_mutex".freeze
|
|
6
|
-
s.version = "3.
|
|
6
|
+
s.version = "3.3.0".freeze
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
|
11
|
-
s.date = "
|
|
11
|
+
s.date = "1980-01-02"
|
|
12
12
|
s.description = "Mutex that can be used to synchronise ruby processes via an ActiveRecord datababase connection. (Only Mysql is supported at the moment.)".freeze
|
|
13
13
|
s.email = "flori@ping.de".freeze
|
|
14
14
|
s.extra_rdoc_files = ["README.md".freeze, "lib/active_record/database_mutex.rb".freeze, "lib/active_record/database_mutex/implementation.rb".freeze, "lib/active_record/database_mutex/version.rb".freeze, "lib/active_record/mutex.rb".freeze, "lib/active_record_mutex.rb".freeze]
|
|
@@ -16,14 +16,14 @@ Gem::Specification.new do |s|
|
|
|
16
16
|
s.homepage = "http://github.com/flori/active_record_mutex".freeze
|
|
17
17
|
s.licenses = ["GPL-2".freeze]
|
|
18
18
|
s.rdoc_options = ["--title".freeze, "ActiveRecordMutex - Implementation of a Mutex for Active Record".freeze, "--main".freeze, "README.md".freeze]
|
|
19
|
-
s.rubygems_version = "
|
|
19
|
+
s.rubygems_version = "4.0.2".freeze
|
|
20
20
|
s.summary = "Implementation of a Mutex for Active Record".freeze
|
|
21
21
|
s.test_files = ["test/database_mutex_test.rb".freeze, "test/test_helper.rb".freeze]
|
|
22
22
|
|
|
23
23
|
s.specification_version = 4
|
|
24
24
|
|
|
25
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, ["
|
|
26
|
-
s.add_development_dependency(%q<all_images>.freeze, ["
|
|
25
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.16.3".freeze])
|
|
26
|
+
s.add_development_dependency(%q<all_images>.freeze, [">= 0.11.2".freeze])
|
|
27
27
|
s.add_development_dependency(%q<test-unit>.freeze, ["~> 3.0".freeze])
|
|
28
28
|
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
|
29
29
|
s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
|
metadata
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_record_mutex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: gem_hadar
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
18
|
+
version: 2.16.3
|
|
20
19
|
type: :development
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
25
|
+
version: 2.16.3
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: all_images
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - ">="
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
32
|
+
version: 0.11.2
|
|
34
33
|
type: :development
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- - "
|
|
37
|
+
- - ">="
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
39
|
+
version: 0.11.2
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
41
|
name: test-unit
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -156,7 +155,6 @@ homepage: http://github.com/flori/active_record_mutex
|
|
|
156
155
|
licenses:
|
|
157
156
|
- GPL-2
|
|
158
157
|
metadata: {}
|
|
159
|
-
post_install_message:
|
|
160
158
|
rdoc_options:
|
|
161
159
|
- "--title"
|
|
162
160
|
- ActiveRecordMutex - Implementation of a Mutex for Active Record
|
|
@@ -175,8 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
175
173
|
- !ruby/object:Gem::Version
|
|
176
174
|
version: '0'
|
|
177
175
|
requirements: []
|
|
178
|
-
rubygems_version:
|
|
179
|
-
signing_key:
|
|
176
|
+
rubygems_version: 4.0.2
|
|
180
177
|
specification_version: 4
|
|
181
178
|
summary: Implementation of a Mutex for Active Record
|
|
182
179
|
test_files:
|