From e26662d9dca8f91148e618a201fc809fa1233f85 Mon Sep 17 00:00:00 2001 From: ac Date: Sat, 26 Jan 2019 12:48:13 +0900 Subject: [PATCH 1/2] add a setup example --- README.md | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e3bd5f9..89cd97f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -Sidekiq::Debounce -================= - [![Travis CI](http://img.shields.io/travis/hummingbird-me/sidekiq-debounce/master.svg)](https://travis-ci.org/hummingbird-me/sidekiq-debounce) - [![CodeClimate](http://img.shields.io/codeclimate/github/hummingbird-me/sidekiq-debounce.svg)](https://codeclimate.com/github/NuckChorris/sidekiq-debounce) - [![Coverage](http://img.shields.io/codeclimate/coverage/github/hummingbird-me/sidekiq-debounce.svg)](https://codeclimate.com/github/NuckChorris/sidekiq-debounce) - [![RubyGems](http://img.shields.io/gem/v/sidekiq-debounce.svg)](https://rubygems.org/gems/sidekiq-debounce) +# Sidekiq::Debounce + +[![Travis CI](http://img.shields.io/travis/hummingbird-me/sidekiq-debounce/master.svg)](https://travis-ci.org/hummingbird-me/sidekiq-debounce) +[![CodeClimate](http://img.shields.io/codeclimate/github/hummingbird-me/sidekiq-debounce.svg)](https://codeclimate.com/github/NuckChorris/sidekiq-debounce) +[![Coverage](http://img.shields.io/codeclimate/coverage/github/hummingbird-me/sidekiq-debounce.svg)](https://codeclimate.com/github/NuckChorris/sidekiq-debounce) +[![RubyGems](http://img.shields.io/gem/v/sidekiq-debounce.svg)](https://rubygems.org/gems/sidekiq-debounce) Sidekiq::Debounce is a client-side Sidekiq middleware which provides a way to easily rate-limit creation of Sidekiq jobs. @@ -37,6 +37,33 @@ Add `Sidekiq::Debounce` to your client middleware chain, and then add Use `#perform_in` instead of `#perform_async` to set the timeframe. +```rb +# rails example +# config/initializers/sidekiq.rb +require "sidekiq/debounce" +Sidekiq.configure_client do |config| + config.client_middleware do |chain| + chain.add Sidekiq::Debounce + end +end +``` + +```rb +class YourWorker + include Sidekiq::Worker + sidekiq_options debounce: true # add this option + + def perform(id) + ... + ... + end +end + +# YourWorker.perform_in 1.day, 42 +# YourWorker.perform_in 1.day, 42 +# will create only one schedule with 42 as a parameter +``` + ## Contributing 1. Fork it ( https://github.com/hummingbird-me/sidekiq-debounce/fork ) From 273b272a49683b1c33e467bbb959247415c68559 Mon Sep 17 00:00:00 2001 From: ac Date: Sat, 26 Jan 2019 13:18:16 +0900 Subject: [PATCH 2/2] change comments --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 89cd97f..d72667c 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ class YourWorker end # YourWorker.perform_in 1.day, 42 -# YourWorker.perform_in 1.day, 42 -# will create only one schedule with 42 as a parameter +# YourWorker.perform_in 2.days, 42 +# will create only one schedule with 42 as a parameter, and its schedule datetime will be 2 days later (not the initial 1 day) ``` ## Contributing