sidekiq-bulk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4467f6dfbb08aded4d1920854812a0e841415af
4
+ data.tar.gz: 540bcd05a47d04fff7fbf2def5000d69a5c0f80c
5
+ SHA512:
6
+ metadata.gz: ee2fe544d0d934e5fe7b5cdd9bc9dccfea9e6825f13ed4fa5f210cb1e70dcde9a8fe390222276841f1c89c3b081c5e406b27d64b499cc5793cb9c6bd2dc92360
7
+ data.tar.gz: 6c5c5b6ed37b46bde6e7b29ee797611934d10687fe201b43f5ade1d26fb66e4cc19de3d106742864ddcf7a0a979d52d2f00ec9d16d7b62b3768be23d4f98b9d0
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format ReRunFriendlyFormatter
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1
7
+ - 2.2
8
+ - ruby-head
9
+ gemfile:
10
+ - gemfiles/sidekiq_2_x.gemfile
11
+ - gemfiles/sidekiq_3_x.gemfile
12
+ - gemfiles/sidekiq_edge.gemfile
13
+ script:
14
+ - bundle exec rspec
15
+ matrix:
16
+ allow_failures:
17
+ - rvm: ruby-head
18
+ - gemfile: gemfiles/sidekiq_edge.gemfile
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise "sidekiq-2-x" do
2
+ gem "sidekiq", "~> 2.0"
3
+ end
4
+
5
+ appraise "sidekiq-3-x" do
6
+ gem "sidekiq", "~> 3.0"
7
+ end
8
+
9
+ appraise "sidekiq-edge" do
10
+ gem "sidekiq", github: "mperham/sidekiq"
11
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org/"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (MIT License)
2
+
3
+ Copyright (c) 2015 Adam Prescott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # sidekiq-bulk
2
+
3
+ [![Build Status](https://travis-ci.org/aprescott/sidekiq-bulk.svg?branch=master)](https://travis-ci.org/aprescott/sidekiq-bulk)
4
+
5
+ Give your workers more to do!
6
+
7
+ Augments Sidekiq job classes with a `push_bulk` method for easier bulk pushing.
8
+
9
+ Sidekiq comes with `Sidekiq::Client.push_bulk` which can be faster than `perform_async` if you have lots and lots of jobs to enqueue.
10
+
11
+ This gem provides a wrapper around it so that instead of
12
+
13
+ ```ruby
14
+ Sidekiq::Client.push_bulk("class" => FooJob, "args" => [[1], [2], [3])
15
+ ```
16
+
17
+ You can write
18
+
19
+ ```ruby
20
+ FooJob.push_bulk([1, 2, 3])
21
+ ```
22
+
23
+ More stuff is supported!
24
+
25
+ ### Installing
26
+
27
+ With Bundler:
28
+
29
+ ```ruby
30
+ # in Gemfile
31
+ gem "sidekiq-bulk"
32
+ ```
33
+
34
+ Either `require "sidekiq-bulk"` or `require "sidekiq/bulk"`.
35
+
36
+ ### To use
37
+
38
+ To enqueue an array of single elements:
39
+
40
+ ```ruby
41
+ FooJob.push_bulk([1, 2, 3]) # enqueues 3 jobs for FooJob, each with 1 argument
42
+ ```
43
+
44
+ To enqueue jobs with more than one argument:
45
+
46
+ ```ruby
47
+ FooJob.push_bulk(all_users) do |user|
48
+ [user.id, "foobar"]
49
+ end
50
+
51
+ # enqueues one job for each element of `all_users`, where each job
52
+ # has two arguments: the user ID and the string "foobar".
53
+ #
54
+ # equivalent to, but faster than:
55
+
56
+ all_users.each do |user|
57
+ FooJob.perform_async(user.id, "foobar")
58
+ end
59
+ ```
60
+
61
+ ### License
62
+
63
+ Copyright (c) 2015 Adam Prescott, licensed under the MIT license. See LICENSE.
64
+
65
+ ### Development
66
+
67
+ Issues (bugs, questions, etc.) should be opened with [the GitHub project](https://github.com/aprescott/sidekiq-bulk).
68
+
69
+ To contribute changes:
70
+
71
+ 1. Visit the [GitHub repository for `sidekiq-bulk`](https://github.com/aprescott/sidekiq-bulk).
72
+ 2. [Fork the repository](https://help.github.com/articles/fork-a-repo).
73
+ 3. Make new feature branch: `git checkout -b master new-feature` (do not add on top of `master`!)
74
+ 4. Implement the feature, along with tests.
75
+ 5. [Send a pull request](https://help.github.com/articles/fork-a-repo).
76
+
77
+ Make sure to `bundle install`.
78
+
79
+ Tests live in `spec/`. Run them with `bundle exec rspec`.
80
+
81
+ To run tests against various Sidekiq versions, use `appraisal rspec`, after `appraisal bundle` if necessary. (See the [Appraisal](https://github.com/thoughtbot/appraisal) project and the `Appraisals` file for more details.)
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gemspec :path => "../"
6
+
7
+ gem "sidekiq", "~> 2.0"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gemspec :path => "../"
6
+
7
+ gem "sidekiq", "~> 3.0"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gemspec :path => "../"
6
+
7
+ gem "sidekiq", github: "mperham/sidekiq"
@@ -0,0 +1 @@
1
+ require "sidekiq/bulk"
@@ -0,0 +1,15 @@
1
+ puts Sidekiq::VERSION
2
+
3
+ module SidekiqBulk
4
+ def push_bulk(items, &block)
5
+ if block
6
+ args = items.map(&block)
7
+ else
8
+ args = items.map { |el| [el] }
9
+ end
10
+
11
+ Sidekiq::Client.push_bulk("class" => self, "args" => args)
12
+ end
13
+ end
14
+
15
+ Sidekiq::Worker::ClassMethods.include SidekiqBulk
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "sidekiq-bulk"
3
+ s.version = "0.0.1"
4
+ s.authors = ["Adam Prescott"]
5
+ s.email = ["adam@aprescott.com"]
6
+ s.homepage = "https://github.com/aprescott/sidekiq-bulk"
7
+ s.summary = "Give your workers more to do!"
8
+ s.description = "Augments Sidekiq job classes with a push_bulk method for easier bulk pushing."
9
+ s.files = Dir["{lib/**/*,spec/**/*,gemfiles/*.gemfile}"] + %w[sidekiq-bulk.gemspec .rspec .travis.yml LICENSE Gemfile Appraisals README.md]
10
+ s.require_path = "lib"
11
+ s.test_files = Dir["spec/*"]
12
+ s.required_ruby_version = ">= 2.0.0"
13
+ s.licenses = ["MIT"]
14
+
15
+ s.add_dependency("sidekiq")
16
+ s.add_development_dependency("rspec", ">= 3.3")
17
+ s.add_development_dependency("rspec-sidekiq")
18
+ s.add_development_dependency("pry-byebug")
19
+ s.add_development_dependency("appraisal")
20
+ end
data/spec/examples.txt ADDED
@@ -0,0 +1,8 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------- | ------ | --------------- |
3
+ ./spec/sidekiq_bulk_spec.rb[1:1] | passed | 0.00109 seconds |
4
+ ./spec/sidekiq_bulk_spec.rb[1:2] | passed | 0.0005 seconds |
5
+ ./spec/sidekiq_bulk_spec.rb[1:3] | passed | 0.01235 seconds |
6
+ ./spec/sidekiq_bulk_spec.rb[1:4] | passed | 0.00035 seconds |
7
+ ./spec/sidekiq_bulk_spec.rb[1:5] | passed | 0.00376 seconds |
8
+ ./spec/sidekiq_bulk_spec.rb[1:6:1] | passed | 0.00211 seconds |
@@ -0,0 +1,31 @@
1
+ require "rspec/core/formatters/progress_formatter"
2
+
3
+ class ReRunFriendlyFormatter < RSpec::Core::Formatters::ProgressFormatter
4
+ RSpec::Core::Formatters.register self, :dump_summary
5
+
6
+ def dump_summary(summary)
7
+ super
8
+
9
+ failed_files = summary.failed_examples.map { |e| RSpec::Core::Metadata::relative_path(e.file_path) }.uniq
10
+
11
+ return if summary.failed_examples.empty? || failed_files.length > 10
12
+
13
+ output.puts
14
+ output.puts "Rerun all failed examples:"
15
+ output.puts
16
+
17
+ output.puts failure_colored("rspec #{summary.failed_examples.map { |e| RSpec::Core::Metadata::relative_path(e.location) }.uniq.join(" ")}")
18
+
19
+ output.puts
20
+ output.puts "Rerun all files containing failures:"
21
+ output.puts
22
+
23
+ output.puts failure_colored("rspec #{failed_files.uniq.join(" ")}")
24
+ end
25
+
26
+ private
27
+
28
+ def failure_colored(str)
29
+ RSpec::Core::Formatters::ConsoleCodes.wrap(str, :failure)
30
+ end
31
+ end
@@ -0,0 +1,50 @@
1
+ RSpec.describe SidekiqBulk do
2
+ class FooJob
3
+ include Sidekiq::Worker
4
+
5
+ def perform(x, *args)
6
+ raise x.to_s
7
+ end
8
+ end
9
+
10
+ class BarJob < FooJob
11
+ end
12
+
13
+ it "provides a push_bulk method on job classes" do
14
+ expect(FooJob).to respond_to(:push_bulk)
15
+ end
16
+
17
+ it "enqueues the job" do
18
+ FooJob.push_bulk([1, 2, 3]) { |el| [el, "some-value"] }
19
+
20
+ expect(FooJob.jobs.length).to eq(3)
21
+ expect(FooJob).to have_enqueued_job(1, "some-value")
22
+ expect(FooJob).to have_enqueued_job(2, "some-value")
23
+ expect(FooJob).to have_enqueued_job(3, "some-value")
24
+ end
25
+
26
+ it "goes through the Sidekiq::Client interface" do
27
+ expect(Sidekiq::Client).to receive(:push_bulk).with("class" => FooJob, "args" => [[1], [2], [3]])
28
+
29
+ FooJob.push_bulk([1, 2, 3])
30
+ end
31
+
32
+ it "uses the correct class name for subclasses" do
33
+ expect(Sidekiq::Client).to receive(:push_bulk).with("class" => BarJob, "args" => [[1], [2], [3]])
34
+
35
+ BarJob.push_bulk([1, 2, 3])
36
+ end
37
+
38
+ it "defaults to the identity function with no block given" do
39
+ FooJob.push_bulk([1, 2, 3])
40
+
41
+ expect(FooJob.jobs.length).to eq(3)
42
+ expect(FooJob).to have_enqueued_job(1)
43
+ expect(FooJob).to have_enqueued_job(2)
44
+ expect(FooJob).to have_enqueued_job(3)
45
+ end
46
+
47
+ describe "inline test", sidekiq: :inline do
48
+ specify { expect { FooJob.push_bulk([1, 2, 3]) }.to raise_error(RuntimeError, "1") }
49
+ end
50
+ end
@@ -0,0 +1,99 @@
1
+ require "sidekiq"
2
+ require "sidekiq/bulk"
3
+ require "sidekiq/testing"
4
+ require "rspec"
5
+ require "rspec-sidekiq"
6
+ require "pry-byebug"
7
+
8
+ RSpec.configure do |config|
9
+ # rspec-expectations config goes here. You can use an alternate
10
+ # assertion/expectation library such as wrong or the stdlib/minitest
11
+ # assertions if you prefer.
12
+ config.expect_with :rspec do |expectations|
13
+ # This option will default to `true` in RSpec 4. It makes the `description`
14
+ # and `failure_message` of custom matchers include text for helper methods
15
+ # defined using `chain`, e.g.:
16
+ # be_bigger_than(2).and_smaller_than(4).description
17
+ # # => "be bigger than 2 and smaller than 4"
18
+ # ...rather than:
19
+ # # => "be bigger than 2"
20
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
21
+ end
22
+
23
+ # rspec-mocks config goes here. You can use an alternate test double
24
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
25
+ config.mock_with :rspec do |mocks|
26
+ # Prevents you from mocking or stubbing a method that does not exist on
27
+ # a real object. This is generally recommended, and will default to
28
+ # `true` in RSpec 4.
29
+ mocks.verify_partial_doubles = true
30
+ end
31
+
32
+ # These two settings work together to allow you to limit a spec run
33
+ # to individual examples or groups you care about by tagging them with
34
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
35
+ # get run.
36
+ config.filter_run :focus
37
+ config.run_all_when_everything_filtered = true
38
+
39
+ # Allows RSpec to persist some state between runs in order to support
40
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
41
+ # you configure your source control system to ignore this file.
42
+ config.example_status_persistence_file_path = "spec/examples.txt"
43
+
44
+ # Limits the available syntax to the non-monkey patched syntax that is
45
+ # recommended. For more details, see:
46
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
47
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
48
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
49
+ config.disable_monkey_patching!
50
+
51
+ # This setting enables warnings. It's recommended, but in some cases may
52
+ # be too noisy due to issues in dependencies.
53
+ config.warnings = false
54
+
55
+ # Run specs in random order to surface order dependencies. If you find an
56
+ # order dependency and want to debug it, you can fix the order by providing
57
+ # the seed, which is printed after each run.
58
+ # --seed 1234
59
+ config.order = :random
60
+
61
+ # Seed global randomization in this process using the `--seed` CLI option.
62
+ # Setting this allows you to use `--seed` to deterministically reproduce
63
+ # test failures related to randomization by passing the same `--seed` value
64
+ # as the one that triggered the failure.
65
+ Kernel.srand config.seed
66
+ end
67
+
68
+ # sidekiq test configuration
69
+ RSpec.configure do |config|
70
+ config.before(:each) do |example_method|
71
+ # Clears out the jobs for tests using the fake testing
72
+ Sidekiq::Worker.clear_all
73
+ end
74
+
75
+ # use an around to allow each test to specify
76
+ # its own around block and override the testing
77
+ # context.
78
+ config.before(:each) do |example_method|
79
+ # Clears out the jobs for tests using the fake testing
80
+ Sidekiq::Worker.clear_all
81
+ end
82
+
83
+ # use an around to allow each test to specify
84
+ # its own around block and override the testing
85
+ # context.
86
+ config.around(:each) do |example|
87
+ # acceptance tests run the jobs immediately.
88
+ if example.metadata[:type] == :feature || example.metadata[:sidekiq] == :inline
89
+ Sidekiq::Testing.inline!(&example)
90
+ else
91
+ Sidekiq::Testing.fake!(&example)
92
+ end
93
+ end
94
+ end
95
+
96
+ # rspec-sidekiq
97
+ RSpec::Sidekiq.configure do |config|
98
+ config.warn_when_jobs_not_processed_by_sidekiq = false
99
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-bulk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Prescott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-sidekiq
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: appraisal
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Augments Sidekiq job classes with a push_bulk method for easier bulk
84
+ pushing.
85
+ email:
86
+ - adam@aprescott.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Appraisals
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - gemfiles/sidekiq_2_x.gemfile
98
+ - gemfiles/sidekiq_3_x.gemfile
99
+ - gemfiles/sidekiq_edge.gemfile
100
+ - lib/sidekiq-bulk.rb
101
+ - lib/sidekiq/bulk.rb
102
+ - sidekiq-bulk.gemspec
103
+ - spec/examples.txt
104
+ - spec/re_run_friendly_formatter.rb
105
+ - spec/sidekiq_bulk_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/aprescott/sidekiq-bulk
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.0.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.8
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Give your workers more to do!
131
+ test_files:
132
+ - spec/examples.txt
133
+ - spec/re_run_friendly_formatter.rb
134
+ - spec/sidekiq_bulk_spec.rb
135
+ - spec/spec_helper.rb