lib/race_block.rb in race_block-0.2.0 vs lib/race_block.rb in race_block-0.2.1
- old
+ new
@@ -49,10 +49,11 @@
def self.reset(key)
RaceBlock.client.del(RaceBlock.key(key))
end
def self.start(key, expire: config.expire, expiration_delay: config.expiration_delay, **args)
+ raise("A Redis client must be added to the RaceBlock configuration") unless configuration.redis
raise("A key must be provided to start a RaceBlock") if key.empty?
@key = RaceBlock.key(key)
# Set an expiration for the token if the key is defined but doesn't
@@ -60,10 +61,11 @@
# `-1` means the key is set but does not expire, `-2` means the key is
# not set
RaceBlock.client.expire(@key, 10) if RaceBlock.client.ttl(@key) == -1
# Token already exists
- return logger.debug("Token already exists") if RaceBlock.client.get(@key)
+ logger.debug("Token already exists") if RaceBlock.client.get(@key)
+ return
return unless set_token_and_wait(@key, **args)
RaceBlock.client.expire(@key, expire)
logger.debug("Running block")