Skip to content

Instantly share code, notes, and snippets.

@danishsatkut
Created August 7, 2023 05:14
Show Gist options
  • Save danishsatkut/6a11d06eae2f7b464d285002856ba9b5 to your computer and use it in GitHub Desktop.
Save danishsatkut/6a11d06eae2f7b464d285002856ba9b5 to your computer and use it in GitHub Desktop.
Concurrency issue and duplicate jobs due to sidekiq-throttled
# frozen_string_literal: true
class SampleJob
include Sidekiq::Job
include Sidekiq::Throttled::Job
sidekiq_throttle concurrency: { limit: 1 }
def perform(id)
puts "Processing ##{id}"
sleep(10)
puts "Done ##{id}"
end
end
2023-08-07T05:08:03.072Z pid=1261 tid=3kl INFO: Booted Rails 7.0.6 application in development environment
2023-08-07T05:08:03.072Z pid=1261 tid=3kl INFO: Running in ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-linux]
2023-08-07T05:08:03.072Z pid=1261 tid=3kl INFO: See LICENSE and the LGPL-3.0 for licensing details.
2023-08-07T05:08:03.072Z pid=1261 tid=3kl INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org
2023-08-07T05:08:03.072Z pid=1261 tid=3kl INFO: Sidekiq 7.1.2 connecting to Redis with options {:size=>10, :pool_name=>"internal", :url=>nil}
2023-08-07T05:08:03.075Z pid=1261 tid=3kl INFO: Sidekiq 7.1.2 connecting to Redis with options {:size=>5, :pool_name=>"default", :url=>nil}
2023-08-07T05:08:03.075Z pid=1261 tid=3kl INFO: Starting processing, hit Ctrl-C to stop
2023-08-07T05:08:03.081Z pid=1261 tid=hfp class=SampleJob jid=94ee383415d303ff8abd25b3 INFO: start
2023-08-07T05:08:03.081Z pid=1261 tid=hg1 class=SampleJob jid=aa3d2cbab857f1f04f225e3b INFO: start
2023-08-07T05:08:03.082Z pid=1261 tid=hfh class=SampleJob jid=4a85f131677229165f93a135 INFO: start
2023-08-07T05:08:03.082Z pid=1261 tid=hh5 class=SampleJob jid=1f389d7d0eb9b96da73ca4ce INFO: start
2023-08-07T05:08:03.082Z pid=1261 tid=he1 class=SampleJob jid=6ade76661a323a2c2ee29d02 INFO: start
Processing #0
Processing #1
Processing #3
Processing #2
Processing #4
Done #0
2023-08-07T05:08:13.125Z pid=1261 tid=hfp class=SampleJob jid=94ee383415d303ff8abd25b3 elapsed=10.043 INFO: done
2023-08-07T05:08:13.126Z pid=1261 tid=hfp class=SampleJob jid=75192b89c6ad5cd3d750a96e INFO: start
Processing #5
Done #1
2023-08-07T05:08:13.147Z pid=1261 tid=hg1 class=SampleJob jid=aa3d2cbab857f1f04f225e3b elapsed=10.065 INFO: done
Done #3
2023-08-07T05:08:13.168Z pid=1261 tid=hfh class=SampleJob jid=4a85f131677229165f93a135 elapsed=10.087 INFO: done
Done #2
Done #4
2023-08-07T05:08:13.170Z pid=1261 tid=hh5 class=SampleJob jid=1f389d7d0eb9b96da73ca4ce elapsed=10.088 INFO: done
2023-08-07T05:08:13.170Z pid=1261 tid=he1 class=SampleJob jid=6ade76661a323a2c2ee29d02 elapsed=10.088 INFO: done
Done #5
2023-08-07T05:08:23.129Z pid=1261 tid=hfp class=SampleJob jid=75192b89c6ad5cd3d750a96e elapsed=10.004 INFO: done
2023-08-07T05:08:23.130Z pid=1261 tid=hg1 class=SampleJob jid=b597c5ae6a0bf30d181c55a2 INFO: start
Processing #0
Done #0
2023-08-07T05:08:33.205Z pid=1261 tid=hg1 class=SampleJob jid=b597c5ae6a0bf30d181c55a2 elapsed=10.075 INFO: done
2023-08-07T05:08:33.206Z pid=1261 tid=hfh class=SampleJob jid=f7eab695ad559173bb9908ab INFO: start
Processing #2
Done #2
2023-08-07T05:08:43.267Z pid=1261 tid=hfh class=SampleJob jid=f7eab695ad559173bb9908ab elapsed=10.062 INFO: done
2023-08-07T05:08:43.268Z pid=1261 tid=he1 class=SampleJob jid=07f8af638cf30dc2fa0b6a52 INFO: start
Processing #6
Done #6
2023-08-07T05:08:53.346Z pid=1261 tid=he1 class=SampleJob jid=07f8af638cf30dc2fa0b6a52 elapsed=10.078 INFO: done
2023-08-07T05:08:53.346Z pid=1261 tid=hg1 class=SampleJob jid=df70509a0043ead45083a6a7 INFO: start
Processing #6
Done #6
2023-08-07T05:09:03.413Z pid=1261 tid=hg1 class=SampleJob jid=df70509a0043ead45083a6a7 elapsed=10.067 INFO: done
2023-08-07T05:09:03.414Z pid=1261 tid=hfh class=SampleJob jid=1ffa50af1616eefeb9d02821 INFO: start
Processing #8
Done #8
2023-08-07T05:09:13.511Z pid=1261 tid=hfh class=SampleJob jid=1ffa50af1616eefeb9d02821 elapsed=10.097 INFO: done
2023-08-07T05:09:13.511Z pid=1261 tid=hg1 class=SampleJob jid=b40c4da46b1fe6f39211997e INFO: start
Processing #8
Done #8
2023-08-07T05:09:23.590Z pid=1261 tid=hg1 class=SampleJob jid=b40c4da46b1fe6f39211997e elapsed=10.08 INFO: done
2023-08-07T05:09:23.590Z pid=1261 tid=he1 class=SampleJob jid=8d7725b4ff928c63f6f6b97b INFO: start
Processing #5
Done #5
2023-08-07T05:09:33.665Z pid=1261 tid=he1 class=SampleJob jid=8d7725b4ff928c63f6f6b97b elapsed=10.075 INFO: done
2023-08-07T05:09:33.665Z pid=1261 tid=hfh class=SampleJob jid=825efcfcf348794c2ad381cb INFO: start
Processing #7
Done #7
2023-08-07T05:09:43.741Z pid=1261 tid=hfh class=SampleJob jid=825efcfcf348794c2ad381cb elapsed=10.075 INFO: done
2023-08-07T05:09:43.741Z pid=1261 tid=he1 class=SampleJob jid=b958858099917561dbbc2380 INFO: start
Processing #7
Done #7
2023-08-07T05:09:53.823Z pid=1261 tid=he1 class=SampleJob jid=b958858099917561dbbc2380 elapsed=10.082 INFO: done
2023-08-07T05:09:53.823Z pid=1261 tid=hfp class=SampleJob jid=e927bccba681febe77ecb8b8 INFO: start
Processing #9
Done #9
2023-08-07T05:10:03.918Z pid=1261 tid=hfp class=SampleJob jid=e927bccba681febe77ecb8b8 elapsed=10.094 INFO: done
2023-08-07T05:10:03.918Z pid=1261 tid=he1 class=SampleJob jid=9e7e9a77d64f5c8d2efdf97a INFO: start
Processing #3
Done #3
2023-08-07T05:10:13.988Z pid=1261 tid=he1 class=SampleJob jid=9e7e9a77d64f5c8d2efdf97a elapsed=10.07 INFO: done
2023-08-07T05:10:13.989Z pid=1261 tid=hfp class=SampleJob jid=d61df12c0c624543bae0bd5c INFO: start
Processing #1
Done #1
2023-08-07T05:10:24.002Z pid=1261 tid=hfp class=SampleJob jid=d61df12c0c624543bae0bd5c elapsed=10.013 INFO: done
2023-08-07T05:10:24.002Z pid=1261 tid=hh5 class=SampleJob jid=e61759f45f1ae23f16ae5c8a INFO: start
Processing #9
Done #9
2023-08-07T05:10:34.008Z pid=1261 tid=hh5 class=SampleJob jid=e61759f45f1ae23f16ae5c8a elapsed=10.006 INFO: done
2023-08-07T05:10:34.008Z pid=1261 tid=hg1 class=SampleJob jid=ad478a317769d500f4b13462 INFO: start
Processing #4
Done #4
2023-08-07T05:10:44.012Z pid=1261 tid=hg1 class=SampleJob jid=ad478a317769d500f4b13462 elapsed=10.004 INFO: done
# frozen_string_literal: true
require 'sidekiq/throttled'
Sidekiq::Throttled.setup!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment