mosquito-cr / mosquito

A background task runner for crystal applications supporting periodic (CRON) and manually queued jobs
MIT License
227 stars 24 forks source link

Rate limiter module for jobs #77

Closed robacarp closed 2 years ago

robacarp commented 2 years ago

This is a re-implementation of the throttling logic introduced in v0.4.0 via #20, but implemented as a decorator module.

The throttling configuration syntax is concise:

class RateLimitedJob < Mosquito::QueuedJob
  include Mosquito::RateLimiter

  throttle limit: 1, per: 10.seconds

  params blah : Int32

  def perform
    # etc...
  end
end

Highlights:

Ancillary improvements: