Last active
January 29, 2018 15:32
-
-
Save raymondberg/4e5639356ff2bb163766c5d0f2aae7ec to your computer and use it in GitHub Desktop.
Advisory Lock Sample - Try running in Rails Consoles in separate processes
This file contains hidden or 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
## Run alongside self | |
count=0 | |
while true | |
Rails.logger.tagged(Process.pid) do | |
Dispute.with_advisory_lock("hamster_dance") do | |
Rails.logger.info "Doing hamster dance #{count}!" | |
sleep 1 | |
count += 1 | |
Rails.logger.info "Finished dancing!" | |
end | |
end | |
end |
This file contains hidden or 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
## Run alongside basic.rb | |
count=0 | |
while true | |
Rails.logger.tagged(Process.pid) do | |
GatewayTransaction.with_advisory_lock("hamster_dance") do | |
Rails.logger.info "Doing hamster dance #{count}!" | |
sleep 1 | |
count += 1 | |
Rails.logger.info "Finished dancing!" | |
end | |
end | |
end |
This file contains hidden or 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
## Run alongside self | |
count=0 | |
while true | |
Rails.logger.tagged(Process.pid) do | |
id = SecureRandom.random_number(10) | |
Dispute.with_advisory_lock("hamster_dance_#{id}") do | |
Rails.logger.info "Doing hamster dance for id #{id}!" | |
sleep 1 | |
Rails.logger.info "Finished dancing!" | |
end | |
end | |
end |
This file contains hidden or 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
count=0 | |
while true | |
Rails.logger.tagged(Process.pid) do | |
Dispute.with_advisory_lock("hamster_dance") do | |
Rails.logger.info "Doing hamster dance #{count}!" | |
sleep 1 | |
count += 1 | |
Rails.logger.info "Finished dancing!" | |
end | |
sleep(SecureRandom.random_number) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment