Created
May 21, 2015 19:28
-
-
Save Jared-Prime/2f4345427891a61bdf8a to your computer and use it in GitHub Desktop.
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
module SidekiqThreadSafetyDemo | |
class Threadsafe | |
include Sidekiq::Worker | |
include Sidetiq::Schedulable | |
sidekiq_options :queue => :default | |
recurrence{ secondly } | |
SAFETY = Mutex.new | |
@@count = 0 | |
def perform | |
SAFETY.synchronize do | |
logger.warn "threadsafe pre-count: #{@@count}" | |
logger.notice User.god.first_name | |
@@count += 1 | |
logger.warn "threadsafe post-count: #{@@count}" | |
end | |
end | |
end | |
class NonThreadsafe | |
include Sidekiq::Worker | |
include Sidetiq::Schedulable | |
sidekiq_options :queue => :default | |
recurrence{ secondly } | |
@@count = 0 | |
def perform | |
logger.warn "nonthreadsafe pre-count: #{@@count}" | |
logger.notice User.god.first_name | |
@@count += 1 | |
logger.warn "nonthreadsafe post-count: #{@@count}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment