lazy_resque 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +193 -0
- data/Guardfile +111 -0
- data/README.md +45 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lazy_resque.gemspec +29 -0
- data/lib/lazy_resque.rb +8 -0
- data/lib/lazy_resque/controller_enqueue.rb +21 -0
- data/lib/lazy_resque/lazy_enqueue.rb +17 -0
- data/lib/lazy_resque/resque_extensions.rb +22 -0
- data/lib/lazy_resque/store.rb +17 -0
- data/lib/lazy_resque/version.rb +5 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 932955e116273e9815105f8a31183ff6663ee69f
|
4
|
+
data.tar.gz: 32cdfc108e4184e3b17ebb3f3668c698f943843c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 908d279cadc2a913d07b4ba50c7852a3333910035604c3130e55641ac1aea48ba1a6eefa45df12315eef39668189d47b3d6a694af14e33c2a0fb9a476b659e50
|
7
|
+
data.tar.gz: 744b9cb891525c0a9edee361aa1beee98219048a093d32550a243e1f4dc980ad01d2a62db0c391c5a5172bddcf5f35fa34cb8eba6436d238122a6a7b1d199c2f
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in lazy_resque.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'activesupport'
|
10
|
+
gem 'guard-livereload', require: false
|
11
|
+
gem 'guard-rspec'
|
12
|
+
gem 'pry-byebug'
|
13
|
+
gem 'rb-fsevent', require: false
|
14
|
+
gem 'rb-readline'
|
15
|
+
gem 'reek'
|
16
|
+
gem 'request_store_rails'
|
17
|
+
gem 'resque'
|
18
|
+
gem 'rspec'
|
19
|
+
gem 'rubocop'
|
20
|
+
gem 'rubocop-rspec'
|
21
|
+
end
|
22
|
+
|
23
|
+
group :development do
|
24
|
+
gem 'spring'
|
25
|
+
gem 'spring-watcher-listen'
|
26
|
+
end
|
27
|
+
|
28
|
+
group :test do
|
29
|
+
gem 'simplecov'
|
30
|
+
gem 'spring-commands-rspec'
|
31
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lazy_resque (0.0.1)
|
5
|
+
activesupport (>= 5.0.0)
|
6
|
+
request_store_rails (>= 1.0.3)
|
7
|
+
resque
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (5.1.6)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 0.7, < 2)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
ast (2.4.0)
|
18
|
+
axiom-types (0.1.1)
|
19
|
+
descendants_tracker (~> 0.0.4)
|
20
|
+
ice_nine (~> 0.11.0)
|
21
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
22
|
+
byebug (10.0.2)
|
23
|
+
codeclimate-engine-rb (0.4.1)
|
24
|
+
virtus (~> 1.0)
|
25
|
+
coderay (1.1.2)
|
26
|
+
coercible (1.0.0)
|
27
|
+
descendants_tracker (~> 0.0.1)
|
28
|
+
concurrent-ruby (1.0.5)
|
29
|
+
descendants_tracker (0.0.4)
|
30
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
31
|
+
diff-lcs (1.3)
|
32
|
+
docile (1.3.0)
|
33
|
+
em-websocket (0.5.1)
|
34
|
+
eventmachine (>= 0.12.9)
|
35
|
+
http_parser.rb (~> 0.6.0)
|
36
|
+
equalizer (0.0.11)
|
37
|
+
eventmachine (1.2.5)
|
38
|
+
ffi (1.9.23)
|
39
|
+
formatador (0.2.5)
|
40
|
+
guard (2.14.2)
|
41
|
+
formatador (>= 0.2.4)
|
42
|
+
listen (>= 2.7, < 4.0)
|
43
|
+
lumberjack (>= 1.0.12, < 2.0)
|
44
|
+
nenv (~> 0.1)
|
45
|
+
notiffany (~> 0.0)
|
46
|
+
pry (>= 0.9.12)
|
47
|
+
shellany (~> 0.0)
|
48
|
+
thor (>= 0.18.1)
|
49
|
+
guard-compat (1.2.1)
|
50
|
+
guard-livereload (2.5.2)
|
51
|
+
em-websocket (~> 0.5)
|
52
|
+
guard (~> 2.8)
|
53
|
+
guard-compat (~> 1.0)
|
54
|
+
multi_json (~> 1.8)
|
55
|
+
guard-rspec (4.7.3)
|
56
|
+
guard (~> 2.1)
|
57
|
+
guard-compat (~> 1.1)
|
58
|
+
rspec (>= 2.99.0, < 4.0)
|
59
|
+
http_parser.rb (0.6.0)
|
60
|
+
i18n (1.0.0)
|
61
|
+
concurrent-ruby (~> 1.0)
|
62
|
+
ice_nine (0.11.2)
|
63
|
+
json (2.1.0)
|
64
|
+
listen (3.1.5)
|
65
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
66
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
67
|
+
ruby_dep (~> 1.2)
|
68
|
+
lumberjack (1.0.13)
|
69
|
+
method_source (0.9.0)
|
70
|
+
minitest (5.11.3)
|
71
|
+
mono_logger (1.1.0)
|
72
|
+
multi_json (1.13.1)
|
73
|
+
mustermann (1.0.1)
|
74
|
+
nenv (0.3.0)
|
75
|
+
notiffany (0.1.1)
|
76
|
+
nenv (~> 0.1)
|
77
|
+
shellany (~> 0.0)
|
78
|
+
parallel (1.12.1)
|
79
|
+
parser (2.5.0.5)
|
80
|
+
ast (~> 2.4.0)
|
81
|
+
powerpack (0.1.1)
|
82
|
+
pry (0.11.3)
|
83
|
+
coderay (~> 1.1.0)
|
84
|
+
method_source (~> 0.9.0)
|
85
|
+
pry-byebug (3.6.0)
|
86
|
+
byebug (~> 10.0)
|
87
|
+
pry (~> 0.10)
|
88
|
+
rack (2.0.4)
|
89
|
+
rack-protection (2.0.0)
|
90
|
+
rack
|
91
|
+
rainbow (3.0.0)
|
92
|
+
rake (12.3.1)
|
93
|
+
rb-fsevent (0.10.3)
|
94
|
+
rb-inotify (0.9.10)
|
95
|
+
ffi (>= 0.5.0, < 2)
|
96
|
+
rb-readline (0.5.5)
|
97
|
+
redis (3.3.5)
|
98
|
+
redis-namespace (1.5.3)
|
99
|
+
redis (~> 3.0, >= 3.0.4)
|
100
|
+
reek (4.8.0)
|
101
|
+
codeclimate-engine-rb (~> 0.4.0)
|
102
|
+
parser (>= 2.5.0.0, < 2.6)
|
103
|
+
rainbow (~> 3.0)
|
104
|
+
request_store_rails (1.0.3)
|
105
|
+
concurrent-ruby (~> 1.0)
|
106
|
+
resque (1.27.4)
|
107
|
+
mono_logger (~> 1.0)
|
108
|
+
multi_json (~> 1.0)
|
109
|
+
redis-namespace (~> 1.3)
|
110
|
+
sinatra (>= 0.9.2)
|
111
|
+
vegas (~> 0.1.2)
|
112
|
+
rspec (3.7.0)
|
113
|
+
rspec-core (~> 3.7.0)
|
114
|
+
rspec-expectations (~> 3.7.0)
|
115
|
+
rspec-mocks (~> 3.7.0)
|
116
|
+
rspec-core (3.7.1)
|
117
|
+
rspec-support (~> 3.7.0)
|
118
|
+
rspec-expectations (3.7.0)
|
119
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
120
|
+
rspec-support (~> 3.7.0)
|
121
|
+
rspec-mocks (3.7.0)
|
122
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
123
|
+
rspec-support (~> 3.7.0)
|
124
|
+
rspec-support (3.7.1)
|
125
|
+
rubocop (0.54.0)
|
126
|
+
parallel (~> 1.10)
|
127
|
+
parser (>= 2.5)
|
128
|
+
powerpack (~> 0.1)
|
129
|
+
rainbow (>= 2.2.2, < 4.0)
|
130
|
+
ruby-progressbar (~> 1.7)
|
131
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
132
|
+
rubocop-rspec (1.25.0)
|
133
|
+
rubocop (>= 0.53.0)
|
134
|
+
ruby-progressbar (1.9.0)
|
135
|
+
ruby_dep (1.5.0)
|
136
|
+
shellany (0.0.1)
|
137
|
+
simplecov (0.16.1)
|
138
|
+
docile (~> 1.1)
|
139
|
+
json (>= 1.8, < 3)
|
140
|
+
simplecov-html (~> 0.10.0)
|
141
|
+
simplecov-html (0.10.2)
|
142
|
+
sinatra (2.0.0)
|
143
|
+
mustermann (~> 1.0)
|
144
|
+
rack (~> 2.0)
|
145
|
+
rack-protection (= 2.0.0)
|
146
|
+
tilt (~> 2.0)
|
147
|
+
spring (2.0.2)
|
148
|
+
activesupport (>= 4.2)
|
149
|
+
spring-commands-rspec (1.0.4)
|
150
|
+
spring (>= 0.9.1)
|
151
|
+
spring-watcher-listen (2.0.1)
|
152
|
+
listen (>= 2.7, < 4.0)
|
153
|
+
spring (>= 1.2, < 3.0)
|
154
|
+
thor (0.20.0)
|
155
|
+
thread_safe (0.3.6)
|
156
|
+
tilt (2.0.8)
|
157
|
+
tzinfo (1.2.5)
|
158
|
+
thread_safe (~> 0.1)
|
159
|
+
unicode-display_width (1.3.0)
|
160
|
+
vegas (0.1.11)
|
161
|
+
rack (>= 1.0.0)
|
162
|
+
virtus (1.0.5)
|
163
|
+
axiom-types (~> 0.1)
|
164
|
+
coercible (~> 1.0)
|
165
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
166
|
+
equalizer (~> 0.0, >= 0.0.9)
|
167
|
+
|
168
|
+
PLATFORMS
|
169
|
+
ruby
|
170
|
+
|
171
|
+
DEPENDENCIES
|
172
|
+
activesupport
|
173
|
+
bundler (>= 1.13)
|
174
|
+
guard-livereload
|
175
|
+
guard-rspec
|
176
|
+
lazy_resque!
|
177
|
+
pry-byebug
|
178
|
+
rake (>= 10.0)
|
179
|
+
rb-fsevent
|
180
|
+
rb-readline
|
181
|
+
reek
|
182
|
+
request_store_rails
|
183
|
+
resque
|
184
|
+
rspec
|
185
|
+
rubocop
|
186
|
+
rubocop-rspec
|
187
|
+
simplecov
|
188
|
+
spring
|
189
|
+
spring-commands-rspec
|
190
|
+
spring-watcher-listen
|
191
|
+
|
192
|
+
BUNDLED WITH
|
193
|
+
1.16.1
|
data/Guardfile
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A sample Guardfile
|
4
|
+
# More info at https://github.com/guard/guard#readme
|
5
|
+
|
6
|
+
## Uncomment and set this to only include directories you want to watch
|
7
|
+
# directories %w(app lib config test spec features) \
|
8
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
9
|
+
|
10
|
+
## Note: if you are using the `directories` clause above and you are not
|
11
|
+
## watching the project directory ('.'), then you will want to move
|
12
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
13
|
+
#
|
14
|
+
# $ mkdir config
|
15
|
+
# $ mv Guardfile config/
|
16
|
+
# $ ln -s config/Guardfile .
|
17
|
+
#
|
18
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
19
|
+
|
20
|
+
guard 'livereload' do
|
21
|
+
extensions = {
|
22
|
+
css: :css,
|
23
|
+
scss: :css,
|
24
|
+
sass: :css,
|
25
|
+
js: :js,
|
26
|
+
coffee: :js,
|
27
|
+
html: :html,
|
28
|
+
png: :png,
|
29
|
+
gif: :gif,
|
30
|
+
jpg: :jpg,
|
31
|
+
jpeg: :jpeg,
|
32
|
+
# less: :less, # uncomment if you want LESS stylesheets done in browser
|
33
|
+
}
|
34
|
+
|
35
|
+
rails_view_exts = %w[erb haml slim]
|
36
|
+
|
37
|
+
# file types LiveReload may optimize refresh for
|
38
|
+
compiled_exts = extensions.values.uniq
|
39
|
+
watch(%r{public/.+\.(#{compiled_exts * '|'})})
|
40
|
+
|
41
|
+
extensions.each do |ext, type|
|
42
|
+
watch(%r{
|
43
|
+
(?:app|vendor)
|
44
|
+
(?:/assets/\w+/(?<path>[^.]+) # path+base without extension
|
45
|
+
(?<ext>\.#{ext})) # matching extension (must be first encountered)
|
46
|
+
(?:\.\w+|$) # other extensions
|
47
|
+
}x) do |m|
|
48
|
+
path = m[1]
|
49
|
+
"/assets/#{path}.#{type}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# file needing a full reload of the page anyway
|
54
|
+
watch(%r{app/views/.+\.(#{rails_view_exts * '|'})$})
|
55
|
+
watch(%r{app/helpers/.+\.rb})
|
56
|
+
watch(%r{config/locales/.+\.yml})
|
57
|
+
end
|
58
|
+
|
59
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
60
|
+
# rspec may be run, below are examples of the most common uses.
|
61
|
+
# * bundler: 'bundle exec rspec'
|
62
|
+
# * bundler binstubs: 'bin/rspec'
|
63
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
64
|
+
# installed the spring binstubs per the docs)
|
65
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
66
|
+
# * 'just' rspec: 'rspec'
|
67
|
+
|
68
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
69
|
+
require 'guard/rspec/dsl'
|
70
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
71
|
+
|
72
|
+
# Feel free to open issues for suggestions and improvements
|
73
|
+
|
74
|
+
# RSpec files
|
75
|
+
rspec = dsl.rspec
|
76
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
77
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
78
|
+
watch(rspec.spec_files)
|
79
|
+
|
80
|
+
# Ruby files
|
81
|
+
ruby = dsl.ruby
|
82
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
83
|
+
|
84
|
+
# Rails files
|
85
|
+
rails = dsl.rails(view_extensions: %w[erb haml slim])
|
86
|
+
dsl.watch_spec_files_for(rails.app_files)
|
87
|
+
dsl.watch_spec_files_for(rails.views)
|
88
|
+
|
89
|
+
watch(rails.controllers) do |m|
|
90
|
+
[
|
91
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
92
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
93
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
94
|
+
]
|
95
|
+
end
|
96
|
+
|
97
|
+
# Rails config changes
|
98
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
99
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
100
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
101
|
+
|
102
|
+
# Capybara features specs
|
103
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
104
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
105
|
+
|
106
|
+
# Turnip features and steps
|
107
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
108
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
109
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
|
110
|
+
end
|
111
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
![lazyresque](https://user-images.githubusercontent.com/2643026/41417090-4bbacb40-6fe4-11e8-809e-3951e3dcd3a5.jpg)
|
2
|
+
|
3
|
+
# Lazy Resque
|
4
|
+
|
5
|
+
Move Resque enqueues out of the Rails request cycle to help decrease time to first byte.
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
From gem:
|
10
|
+
```
|
11
|
+
gem 'lazy_resque'
|
12
|
+
```
|
13
|
+
|
14
|
+
From source:
|
15
|
+
```
|
16
|
+
gem 'lazy_resque', git: 'git@github.com:samuelgiles/lazy_resque.git'
|
17
|
+
```
|
18
|
+
|
19
|
+
## Use
|
20
|
+
|
21
|
+
Trigger the actual enqueue of the jobs after the request in an `after_action` block, this can be done
|
22
|
+
by including `LazyResque::ControllerEnqueue` which will automatically add the `after_action` for you.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class ApplicationController < ActionController::Base
|
26
|
+
include LazyResque::ControllerEnqueue
|
27
|
+
|
28
|
+
def index
|
29
|
+
Resque.lazy_enqueue(MyResqueJob, 1234, 'some_job_data')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
## Why?
|
35
|
+
|
36
|
+
Though moving a long running task to a Resque job is beneficial the actual enqueuing process isn't free:
|
37
|
+
|
38
|
+
- Any `before_enqueue` hooks are run
|
39
|
+
- A new job instance is initialized and validated
|
40
|
+
- Arguments are dumped/encoded into JSON
|
41
|
+
- Redis `rpush` takes places requiring communication with the Redis server
|
42
|
+
|
43
|
+
This is fine for 1-2 enqueues in a request cycle but can add up to a measurable amount of time if your enqueuing several jobs.
|
44
|
+
|
45
|
+
You don't lose anything by moving the actual enqueuing outside the request cycle and it saves precious milliseconds.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'lazy_resque'
|
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
|
data/bin/setup
ADDED
data/lazy_resque.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'lazy_resque/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'lazy_resque'
|
10
|
+
spec.version = LazyResque::VERSION
|
11
|
+
spec.authors = ['Bellroy Tech Team']
|
12
|
+
spec.email = ['tech@bellroy.com']
|
13
|
+
|
14
|
+
spec.summary = 'Lazy Resque'
|
15
|
+
spec.description = 'Moves Resque enqueues out of the request cycle in a Rails application.'
|
16
|
+
spec.homepage = 'https://github.com/samuelgiles/lazy_resque'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '>= 1.13'
|
24
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
26
|
+
spec.add_runtime_dependency 'activesupport', '>= 5.0.0'
|
27
|
+
spec.add_runtime_dependency 'request_store_rails', '>= 1.0.3'
|
28
|
+
spec.add_runtime_dependency 'resque'
|
29
|
+
end
|
data/lib/lazy_resque.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'resque'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
module LazyResque
|
7
|
+
# A controller concern that appends an after_action to ensure the
|
8
|
+
# lazily enqueued Resque enqueues during the request cycle are actually
|
9
|
+
# enqueued at the end of the request.
|
10
|
+
module ControllerEnqueue
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
append_after_action :process_lazy_enqueues
|
15
|
+
end
|
16
|
+
|
17
|
+
def process_lazy_enqueues
|
18
|
+
Resque.process_lazy_enqueues
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'resque'
|
4
|
+
|
5
|
+
module LazyResque
|
6
|
+
# Wrap up the original klass/args ready to be placed into Store.enqueues
|
7
|
+
class LazyEnqueue
|
8
|
+
def initialize(klass, *args)
|
9
|
+
@klass = klass
|
10
|
+
@args = args
|
11
|
+
end
|
12
|
+
|
13
|
+
def enqueue
|
14
|
+
Resque.enqueue(@klass, *@args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lazy_resque/store'
|
4
|
+
require 'lazy_resque/lazy_enqueue'
|
5
|
+
|
6
|
+
module LazyResque
|
7
|
+
# Extensions to append to the main Resque module to add
|
8
|
+
# Resque.lazy_enqueue and Resque.process_lazy_enqueues
|
9
|
+
module ResqueExtensions
|
10
|
+
def lazy_enqueue(klass, *args)
|
11
|
+
LazyResque::Store.queue_up(LazyResque::LazyEnqueue.new(klass, *args))
|
12
|
+
end
|
13
|
+
|
14
|
+
def process_lazy_enqueues
|
15
|
+
current_queue = LazyResque::Store.queue
|
16
|
+
return if current_queue.empty?
|
17
|
+
Thread.new(current_queue) do |jobs_to_be_enqueued|
|
18
|
+
jobs_to_be_enqueued.each(&:enqueue)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'request_store_rails'
|
4
|
+
|
5
|
+
module LazyResque
|
6
|
+
# Per thread store that uses RequestLocals to store all the enqueues
|
7
|
+
# we want to run
|
8
|
+
module Store
|
9
|
+
def self.queue
|
10
|
+
RequestLocals.fetch(:lazy_resque_queue) { [] } || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.queue_up(lazy_enqueue)
|
14
|
+
RequestLocals.store[:lazy_resque_queue] = queue.concat([lazy_enqueue])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lazy_resque
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bellroy Tech Team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: request_store_rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.0.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.0.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: resque
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Moves Resque enqueues out of the request cycle in a Rails application.
|
98
|
+
email:
|
99
|
+
- tech@bellroy.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- CHANGELOG.md
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- Guardfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lazy_resque.gemspec
|
113
|
+
- lib/lazy_resque.rb
|
114
|
+
- lib/lazy_resque/controller_enqueue.rb
|
115
|
+
- lib/lazy_resque/lazy_enqueue.rb
|
116
|
+
- lib/lazy_resque/resque_extensions.rb
|
117
|
+
- lib/lazy_resque/store.rb
|
118
|
+
- lib/lazy_resque/version.rb
|
119
|
+
homepage: https://github.com/samuelgiles/lazy_resque
|
120
|
+
licenses: []
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.6.11
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Lazy Resque
|
142
|
+
test_files: []
|