You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A leaky bucket rate limited is best implemented at the queue layer, but mosquito doesn't yet have the notion of configurable queue classes. If it did, this might work:
require"./queue"moduleMosquito::LeakyBucketclassBucket < Mosquito::Queuedefmetadata : MetadataMetadata.new @config_keyenddefcan_enqueue? : Bool# todo max size needs configurable
size <15enddefwill_drip? : Bool# TODO drip interval needs configurable
last_drip = metadata["last_drip"]?
returntrueif last_drip.nil?
last_drip =Time.unix_ms last_drip.to_i
Time.utc - last_drip >10.seconds
enddefdrip!
metadata["last_drip"] =Time.utc.to_unix_ms.to_s
enddefdequeue : Task?
unless will_drip?
puts"not dripping"returnendLog.info { "time to drip!" }
drip!
superendendmoduleLimitermoduleClassMethodsdefqueueMosquito::LeakyBucket::Bucket.new queue_name
endendmacroincludedextendClassMethodsenddefrescheduleable? : Boolfalseend# def enqueue : Task# if self.class.queue.can_enqueue?# previous_def# else# raise "No room left in bucket"# end# endendend
The text was updated successfully, but these errors were encountered:
Re: #100
A leaky bucket rate limited is best implemented at the queue layer, but mosquito doesn't yet have the notion of configurable queue classes. If it did, this might work:
The text was updated successfully, but these errors were encountered: