Skip to content

Instantly share code, notes, and snippets.

@machty
Created July 1, 2019 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machty/c43646c0e2157a4c7c4f098ce8270dac to your computer and use it in GitHub Desktop.
Save machty/c43646c0e2157a4c7c4f098ce8270dac to your computer and use it in GitHub Desktop.
class CheckoutBeaconRefreshLocationWorkerFake
include Sidekiq::Worker
sidekiq_options lock: :until_and_while_executing
def perform(id)
$tick ||= 0
$tick += 1
puts "STARTING #{$tick}"
sleep 5
puts "DONE #{$tick}"
end
end
6:46:19 PM worker.1 | CheckoutBeaconRefreshLocationWorkerFake JID-d62a2a531e984bdc9d949180 INFO: start
6:46:19 PM worker.1 | STARTING 1
6:46:20 PM worker.1 | CheckoutBeaconRefreshLocationWorkerFake JID-1b8e1c31ce5d37d00c017fc4 INFO: start
6:46:20 PM worker.1 | CheckoutBeaconRefreshLocationWorkerFake JID-1b8e1c31ce5d37d00c017fc4 INFO: done: 0.019 sec
6:46:20 PM worker.1 | CheckoutBeaconRefreshLocationWorkerFake JID-bf07b3d391f496857efce83f INFO: start
6:46:20 PM worker.1 | CheckoutBeaconRefreshLocationWorkerFake JID-bf07b3d391f496857efce83f INFO: done: 0.018 sec
6:46:24 PM worker.1 | DONE 1
6:46:24 PM worker.1 | CheckoutBeaconRefreshLocationWorkerFake JID-d62a2a531e984bdc9d949180 INFO: done: 5.025 sec
# All of these commands where issued right after each other, in less than a second's time
[1] pry(main)> CheckoutBeaconRefreshLocationWorkerFake.perform_async(1)
=> "d62a2a531e984bdc9d949180"
[2] pry(main)> CheckoutBeaconRefreshLocationWorkerFake.perform_async(1)
=> "1b8e1c31ce5d37d00c017fc4"
[3] pry(main)> CheckoutBeaconRefreshLocationWorkerFake.perform_async(1)
=> "bf07b3d391f496857efce83f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment