Giter Site home page Giter Site logo

dtaniwaki / sidekiq-merger Goto Github PK

View Code? Open in Web Editor NEW
50.0 3.0 5.0 826 KB

Merge Sidekiq jobs

Home Page: https://sidekiq-merger.dtaniwaki.com

License: MIT License

Ruby 89.39% HTML 10.15% Dockerfile 0.46%
sidekiq ruby rails batch sidekiq-grouping bulk-notification

sidekiq-merger's Introduction

sidekiq-merger

Gem Version Dependency Status Build Status Coverage Status Code Climate

Docker

Merge sidekiq jobs occurring before the execution times. Inspired by sidekiq-grouping.

Demo

Use Case

Cancel Task

Cancel Task

Bulk Notification

Bulk Notification

Installation

Add this line to your application's Gemfile:

gem 'sidekiq-merger'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sidekiq-merger

Usage

Add merger option into your workers.

class SomeWorker
  include Sidekiq::Worker

  sidekiq_options merger: { key: -> (args) { args[0] } }

  def perform(*merged_args)
    merged_args.each do |args|
      # Do something
    end
  end
end

Then, enqueue jobs by perform_in or perform_at.

SomeWorker.perform_in 100, 4
SomeWorker.perform_in 100, 3
SomeWorker.perform_in 100, 5
# Passed 100 seconds from the first enqueue.
SomeWorker.perform_in 100, 6
SomeWorker.perform_in 100, 1

SomeWorker will be executed in 100 seconds with args of [4], [3], [5], then with args of [6], [1].

perform_async works without merging args.

SomeWorker.perform_async 4
SomeWorker.perform_async 3
SomeWorker.perform_async 5

In this case, SomeWorker will be executed 3 times with args of [4], [3] and [5].

Quick Check

Run docker containers to check the behavior of this gem.

$ docker-compose up

Then, open http://localhost:3000/. You can push jobs from the UI and see what happens in the sidekiq console.

Options

key (optional, default: nil)

Defines merge key so different arguments can be merged.

Format: String or Proc

e.g. sidekiq_options merger: { key: -> (args) { args[0..1] } }

unique (optional, default: false)

Prevents enqueue of jobs with identical arguments.

Format: Boolean

e.g. true

batch_size (optional, default: nil)

Allow to specify how many jobs max to provide as arguments per aggregation

Format: Int

e.g. 50

Web UI

Web UI

Add this line to your config/routes.rb to activate web UI:

require "sidekiq/merger/web"

Test

$ bundle exec appraisal rspec

The test coverage is available at ./coverage/index.html.

Lint

$ bundle exec appraisal rubocop

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2017 dtaniwaki. See LICENSE for details.

sidekiq-merger's People

Contributors

charlypoly avatar dholdren avatar dtaniwaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sidekiq-merger's Issues

Execution failed with error wrong number of arguments (4 for 0)

gem 'sidekiq-merger', github: "dtaniwaki/sidekiq-merger"
gem 'sidekiq', '4.2.9'

Execution failed with error wrong number of arguments (4 for 0)

Problem in https://github.com/dtaniwaki/sidekiq-merger/blob/master/lib/sidekiq/merger/middleware.rb#L19

sidekiq_1  | /home/web/bundle/bundler/gems/sidekiq-merger-419f4e971a91/lib/sidekiq/merger/merge.rb:76:in `flush'
sidekiq_1  | /home/web/bundle/bundler/gems/sidekiq-merger-419f4e971a91/lib/sidekiq/merger/flusher.rb:12:in `each'
sidekiq_1  | /home/web/bundle/bundler/gems/sidekiq-merger-419f4e971a91/lib/sidekiq/merger/flusher.rb:12:in `flush'
sidekiq_1  | /home/web/bundle/bundler/gems/sidekiq-merger-419f4e971a91/lib/sidekiq/merger.rb:21:in `block in create_task'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/safe_task_executor.rb:24:in `call'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `block in synchronize'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `synchronize'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `synchronize'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/safe_task_executor.rb:19:in `execute'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/timer_task.rb:309:in `execute_task'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/safe_task_executor.rb:24:in `call'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `block in synchronize'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `synchronize'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `synchronize'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/safe_task_executor.rb:19:in `execute'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/ivar.rb:170:in `safe_execute'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/scheduled_task.rb:285:in `process_task'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/timer_set.rb:168:in `block (2 levels) in process_tasks'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `call'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'
sidekiq_1  | /home/web/bundle/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'

Skidekiq 6 support

Hello

The latest version of the gem does not support Sidekiq 6. Can the support for Sidekiq 6 be added?

Merge failing jobs in retry?

Does this middleware merge all failing jobs of a certain type/key into one retry? That would be immensely useful when it comes to networking deliveries.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.