-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We actually need it for the case that multiple requests on the same process are using the same DB connection. Closes #18
- Loading branch information
Showing
6 changed files
with
52 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# A memory lock prevents multiple requests with the same request | ||
# fingerprint from running concurrently | ||
class Idempo::MemoryLock | ||
def initialize | ||
@requests_in_flight_mutex = Mutex.new | ||
@in_progress = Set.new | ||
end | ||
|
||
def with(request_key) | ||
@requests_in_flight_mutex.synchronize do | ||
if @in_progress.include?(request_key) | ||
raise Idempo::ConcurrentRequest | ||
else | ||
@in_progress << request_key | ||
end | ||
end | ||
yield | ||
ensure | ||
@requests_in_flight_mutex.synchronize { @in_progress.delete(request_key) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Idempo | ||
VERSION = "1.1.0" | ||
VERSION = "1.2.0" | ||
end |