sidekiq-postpone 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7fdf4493b88792bf5b591d993db17eccb48ab7fe
4
+ data.tar.gz: da2de1a6c1b362a77107bd04bf5f38940f84bfaa
5
+ SHA512:
6
+ metadata.gz: 2eb7a5a4c6bda21a99c6b59cea1ecd3e07e8b1c86dc22ffcd11c09b74cbacfc5c1c603b3d0b6cef544a3541c6dd88b125556117b84f5508f19a21415b8242a83
7
+ data.tar.gz: 9830d0b2f83c0f3606d00d0ce7b7fa43c20179c5c4b41f5871f6b3f267b5ea22d852b573cfcdcbc10b1bdc30288a055313264069b7762fd9316d9af2216feedb
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /gemfiles/*.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,26 @@
1
+ language: ruby
2
+ sudo: false
3
+ services:
4
+ - redis-server
5
+ rvm:
6
+ - 2.1
7
+ - 2.2
8
+ - 2.3.0
9
+ gemfile:
10
+ - Gemfile
11
+ - gemfiles/sidekiq_3.0.gemfile
12
+ - gemfiles/sidekiq_3.1.gemfile
13
+ - gemfiles/sidekiq_3.2.gemfile
14
+ - gemfiles/sidekiq_3.3.gemfile
15
+ - gemfiles/sidekiq_3.4.gemfile
16
+ - gemfiles/sidekiq_3.5.gemfile
17
+ - gemfiles/sidekiq_4.0.gemfile
18
+ - gemfiles/sidekiq_4.1.0.gemfile
19
+ - gemfiles/sidekiq_4.1.1.gemfile
20
+ - gemfiles/sidekiq_4.1.2.gemfile
21
+ - gemfiles/sidekiq_4.1.3.gemfile
22
+
23
+ before_install: gem install bundler -v 1.12
24
+ script:
25
+ - bundle exec rake spec
26
+ - bundle exec rake spec:sidekiq_testing_integration
@@ -0,0 +1,43 @@
1
+ appraise 'sidekiq-3.0' do
2
+ gem 'sidekiq', '~> 3.0.0'
3
+ end
4
+
5
+ appraise 'sidekiq-3.1' do
6
+ gem 'sidekiq', '~> 3.1.0'
7
+ end
8
+
9
+ appraise 'sidekiq-3.2' do
10
+ gem 'sidekiq', '~> 3.2.0'
11
+ end
12
+
13
+ appraise 'sidekiq-3.3' do
14
+ gem 'sidekiq', '~> 3.3.0'
15
+ end
16
+
17
+ appraise 'sidekiq-3.4' do
18
+ gem 'sidekiq', '~> 3.4.0'
19
+ end
20
+
21
+ appraise 'sidekiq-3.5' do
22
+ gem 'sidekiq', '~> 3.5.0'
23
+ end
24
+
25
+ appraise 'sidekiq-4.0' do
26
+ gem 'sidekiq', '~> 4.0.0'
27
+ end
28
+
29
+ appraise 'sidekiq-4.1.0' do
30
+ gem 'sidekiq', '4.1.0'
31
+ end
32
+
33
+ appraise 'sidekiq-4.1.1' do
34
+ gem 'sidekiq', '4.1.1'
35
+ end
36
+
37
+ appraise 'sidekiq-4.1.2' do
38
+ gem 'sidekiq', '4.1.2'
39
+ end
40
+
41
+ appraise 'sidekiq-4.1.3' do
42
+ gem 'sidekiq', '4.1.3'
43
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sidekiq-postpone.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Vladimir Kochnev
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,47 @@
1
+ [![Build Status](https://travis-ci.org/marshall-lee/sidekiq-postpone.svg?branch=master)](https://travis-ci.org/marshall-lee/sidekiq-postpone)
2
+
3
+ # sidekiq-postpone
4
+
5
+ Bulk-pushes tasks to Redis when you need it to.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sidekiq-postpone'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sidekiq-postpone
22
+
23
+ ## Usage
24
+
25
+ Typical use-case is with database transactions:
26
+
27
+ ```ruby
28
+ Sidekiq::Postpone.wrap do
29
+ ActiveRecord::Base.transaction do
30
+ # ...
31
+ post = Post.create(params)
32
+ ImageProcess.perform_async(post.image)
33
+ end
34
+ end
35
+ # In fact, ImageProcess job will be pushed to the queue only after `wrap { ... }` block finishes.
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marshall-lee/sidekiq-postpone.
47
+
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |rspec|
5
+ rspec.exclude_pattern = 'spec/sidekiq-postpone_testing_integration_spec.rb'
6
+ end
7
+
8
+ namespace :spec do
9
+ RSpec::Core::RakeTask.new(:sidekiq_testing_integration) do |rspec|
10
+ rspec.pattern = 'spec/sidekiq-postpone_testing_integration_spec.rb'
11
+ end
12
+ end
13
+
14
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'appraisal' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("appraisal", "appraisal")
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'bundler' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("bundler", "bundler")
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sidekiq/postpone"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 3.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 3.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 3.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 3.3.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 3.4.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 3.5.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 4.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "4.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "4.1.1"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "4.1.2"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "4.1.3"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+ require "sidekiq/postpone/version"
5
+ require "sidekiq/postpone/core_ext"
6
+
7
+ class Sidekiq::Postpone
8
+ def initialize(*client_args)
9
+ @client_args = client_args
10
+ setup_queues
11
+ setup_schedule
12
+ end
13
+
14
+ def wrap
15
+ start
16
+ yield
17
+ stop
18
+ flush
19
+ ensure
20
+ stop
21
+ end
22
+
23
+ def self.wrap(&block)
24
+ new.wrap(&block)
25
+ end
26
+
27
+ def push(payloads)
28
+ if payloads.first['at']
29
+ @schedule.concat(payloads)
30
+ else
31
+ q = payloads.first['queue']
32
+ @queues[q].concat(payloads)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def flush
39
+ client = Sidekiq::Client.new(*@client_args)
40
+ raw_push = client.method(:raw_push)
41
+ @queues.each_value(&raw_push)
42
+ raw_push.(@schedule) unless @schedule.empty?
43
+ end
44
+
45
+ def start
46
+ if Thread.current[:sidekiq_postpone]
47
+ raise 'Nested Sidekiq::Postpone is not supported'
48
+ end
49
+
50
+ Thread.current[:sidekiq_postpone] = self
51
+ end
52
+
53
+ def stop
54
+ Thread.current[:sidekiq_postpone] = nil
55
+ end
56
+
57
+ def setup_queues
58
+ @queues = Hash.new do |hash, key|
59
+ hash[key] = []
60
+ end
61
+ end
62
+
63
+ def setup_schedule
64
+ @schedule = []
65
+ end
66
+ end
@@ -0,0 +1,14 @@
1
+ class Sidekiq::Postpone
2
+ module CoreExt
3
+ def raw_push(payloads)
4
+ postpone = Thread.current[:sidekiq_postpone]
5
+ if postpone
6
+ postpone.push(payloads)
7
+ else
8
+ super
9
+ end
10
+ end
11
+ end
12
+
13
+ Sidekiq::Client.prepend CoreExt
14
+ end
@@ -0,0 +1,5 @@
1
+ module Sidekiq
2
+ class Postpone
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sidekiq/postpone/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidekiq-postpone"
8
+ spec.version = Sidekiq::Postpone::VERSION
9
+ spec.authors = ["Vladimir Kochnev"]
10
+ spec.email = ["hashtable@yandex.ru"]
11
+
12
+ spec.summary = %q{Bulk-pushes jobs to Sidekiq when you need it to.}
13
+ spec.homepage = "https://github.com/marshall-lee/sidekiq-postpone"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "sidekiq", ">= 3"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "appraisal", "~> 2.1.0"
26
+ spec.add_development_dependency "redis-namespace", "~> 1.5.2"
27
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-postpone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Kochnev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-01 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: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.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: 2.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: redis-namespace
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.5.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.5.2
97
+ description:
98
+ email:
99
+ - hashtable@yandex.ru
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Appraisals
108
+ - Gemfile
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - bin/appraisal
113
+ - bin/bundler
114
+ - bin/console
115
+ - bin/rake
116
+ - bin/rspec
117
+ - bin/setup
118
+ - gemfiles/sidekiq_3.0.gemfile
119
+ - gemfiles/sidekiq_3.1.gemfile
120
+ - gemfiles/sidekiq_3.2.gemfile
121
+ - gemfiles/sidekiq_3.3.gemfile
122
+ - gemfiles/sidekiq_3.4.gemfile
123
+ - gemfiles/sidekiq_3.5.gemfile
124
+ - gemfiles/sidekiq_4.0.gemfile
125
+ - gemfiles/sidekiq_4.1.0.gemfile
126
+ - gemfiles/sidekiq_4.1.1.gemfile
127
+ - gemfiles/sidekiq_4.1.2.gemfile
128
+ - gemfiles/sidekiq_4.1.3.gemfile
129
+ - lib/sidekiq/postpone.rb
130
+ - lib/sidekiq/postpone/core_ext.rb
131
+ - lib/sidekiq/postpone/version.rb
132
+ - sidekiq-postpone.gemspec
133
+ homepage: https://github.com/marshall-lee/sidekiq-postpone
134
+ licenses: []
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.5.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Bulk-pushes jobs to Sidekiq when you need it to.
156
+ test_files: []