race_block 0.2.2 → 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 +4 -4
- data/.deepsource.toml +9 -0
- data/.rubocop_todo.yml +1 -1
- data/README.md +11 -1
- data/lib/race_block/version.rb +1 -1
- data/lib/race_block.rb +9 -14
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6891e1559d3458e5ce722b5d5c384fc9820fd0c7ea6fddf9a24a51e515fa6e96
|
|
4
|
+
data.tar.gz: 956a5414c1a69d3c55f5d7e8ccf6ce885f766544736dc92a26b8d4f1ce967ccb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0f263d2351ec39423095fe1a4885fb6b0f80b1fd6a4792ff8ee5174af67fc16562c65ba0a8350cb82f2ec9e07121b409e2e40e3f3dd44ca076f3cb77e6fb8b01
|
|
7
|
+
data.tar.gz: 53c25dfa16723901211c7bae027497a20f009404cfe96ac8bcae6f837f1e6a23c99d3c3dda0d5b67173bb4b8d8f771861da5096f80ba0e4e80e122148e2fbeba
|
data/.deepsource.toml
ADDED
data/.rubocop_todo.yml
CHANGED
data/README.md
CHANGED
|
@@ -62,7 +62,7 @@ RaceBlock.config.redis = Redis.new
|
|
|
62
62
|
Any code that you want to be "thread-safe" and ensure is only executing in one location should be placed in a `RaceBlock` with a unique identifying key that will be checked across all instances.
|
|
63
63
|
|
|
64
64
|
```ruby
|
|
65
|
-
RaceBlock.start('unique_key',
|
|
65
|
+
RaceBlock.start('unique_key', **kwargs) do
|
|
66
66
|
# Insert code that should only be executed once at a time here...
|
|
67
67
|
end
|
|
68
68
|
```
|
|
@@ -97,6 +97,16 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
97
97
|
|
|
98
98
|
Bug reports and pull requests are welcome on GitHub at https://github.com/joeyparis/race_block. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/joeyparis/race_block/blob/master/CODE_OF_CONDUCT.md).
|
|
99
99
|
|
|
100
|
+
I am also interested in porting this project to multiple languages and would love help in the languages I am less familiar with.
|
|
101
|
+
|
|
102
|
+
- [x] Ruby
|
|
103
|
+
- [ ] JavaScript
|
|
104
|
+
- [ ] Python
|
|
105
|
+
- [ ] Go
|
|
106
|
+
- [ ] LolCode
|
|
107
|
+
- [ ] ..?
|
|
108
|
+
|
|
109
|
+
|
|
100
110
|
## License
|
|
101
111
|
|
|
102
112
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/race_block/version.rb
CHANGED
data/lib/race_block.rb
CHANGED
|
@@ -50,35 +50,30 @@ module RaceBlock
|
|
|
50
50
|
RaceBlock.client.del(RaceBlock.key(key))
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def self.start(
|
|
54
|
-
raise("A
|
|
55
|
-
raise("A key must be provided to start a RaceBlock") if key.empty?
|
|
53
|
+
def self.start(base_key, expire: config.expire, expiration_delay: config.expiration_delay, **args)
|
|
54
|
+
raise("A key must be provided to start a RaceBlock") if base_key.empty?
|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
key = RaceBlock.key(base_key)
|
|
58
57
|
|
|
59
58
|
# Set an expiration for the token if the key is defined but doesn't
|
|
60
59
|
# have an expiration set (happens sometimes if a thread dies early).
|
|
61
60
|
# `-1` means the key is set but does not expire, `-2` means the key is
|
|
62
61
|
# not set
|
|
63
|
-
RaceBlock.client.expire(
|
|
62
|
+
RaceBlock.client.expire(key, 10) if RaceBlock.client.ttl(key) == -1
|
|
64
63
|
|
|
65
64
|
# Token already exists
|
|
66
|
-
|
|
67
|
-
if RaceBlock.client.get(@key)
|
|
68
|
-
logger.debug("Token already exists")
|
|
69
|
-
return
|
|
70
|
-
end
|
|
65
|
+
return logger.debug("Token already exists") if RaceBlock.client.get(key)
|
|
71
66
|
|
|
72
|
-
return unless set_token_and_wait(
|
|
67
|
+
return unless set_token_and_wait(key, **args)
|
|
73
68
|
|
|
74
|
-
RaceBlock.client.expire(
|
|
69
|
+
RaceBlock.client.expire(key, expire)
|
|
75
70
|
logger.debug("Running block")
|
|
76
71
|
|
|
77
72
|
r = yield
|
|
78
73
|
|
|
79
74
|
# I have lots of internal debates on whether I should full
|
|
80
75
|
# delete the key here or still let it sit for a few seconds
|
|
81
|
-
RaceBlock.client.expire(
|
|
76
|
+
RaceBlock.client.expire(key, expiration_delay)
|
|
82
77
|
|
|
83
78
|
r
|
|
84
79
|
end
|
|
@@ -101,7 +96,7 @@ module RaceBlock
|
|
|
101
96
|
# moment, and I also believe this is what is keep the EmailQueue
|
|
102
97
|
# stable which seems to have no duplicate sending problems.
|
|
103
98
|
|
|
104
|
-
return true if RaceBlock.client.get(
|
|
99
|
+
return true if RaceBlock.client.get(key) == token
|
|
105
100
|
|
|
106
101
|
# Token out of sync
|
|
107
102
|
logger.debug("Token out of sync")
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: race_block
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joey Paris
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-02-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -94,7 +94,7 @@ dependencies:
|
|
|
94
94
|
- - '='
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: 0.2.0
|
|
97
|
-
description:
|
|
97
|
+
description:
|
|
98
98
|
email:
|
|
99
99
|
- joey@leadjig.com
|
|
100
100
|
executables: []
|
|
@@ -102,6 +102,7 @@ extensions: []
|
|
|
102
102
|
extra_rdoc_files: []
|
|
103
103
|
files:
|
|
104
104
|
- ".actrc"
|
|
105
|
+
- ".deepsource.toml"
|
|
105
106
|
- ".github/workflows/main.yml"
|
|
106
107
|
- ".gitignore"
|
|
107
108
|
- ".rspec"
|
|
@@ -123,7 +124,7 @@ licenses:
|
|
|
123
124
|
metadata:
|
|
124
125
|
homepage_uri: https://rubygems.org/gems/race_block
|
|
125
126
|
source_code_uri: https://github.com/joeyparis/race_block
|
|
126
|
-
post_install_message:
|
|
127
|
+
post_install_message:
|
|
127
128
|
rdoc_options: []
|
|
128
129
|
require_paths:
|
|
129
130
|
- lib
|
|
@@ -138,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
138
139
|
- !ruby/object:Gem::Version
|
|
139
140
|
version: '0'
|
|
140
141
|
requirements: []
|
|
141
|
-
rubygems_version: 3.
|
|
142
|
-
signing_key:
|
|
142
|
+
rubygems_version: 3.2.3
|
|
143
|
+
signing_key:
|
|
143
144
|
specification_version: 4
|
|
144
145
|
summary: A Ruby code block wrapper to help prevent race conditions across multiple
|
|
145
146
|
threads and even separate servers.
|