rails-queue-it 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +116 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.editorconfig +24 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.rubocop.yml +503 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +277 -0
- data/Guardfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +202 -0
- data/Rakefile +10 -0
- data/app/assets/config/queue_it_manifest.js +1 -0
- data/app/assets/images/queue_it/.keep +0 -0
- data/app/assets/stylesheets/queue_it/application.css +15 -0
- data/app/controllers/queue_it/application_controller.rb +5 -0
- data/app/helpers/queue_it/application_helper.rb +4 -0
- data/app/jobs/queue_it/application_job.rb +4 -0
- data/app/mailers/queue_it/application_mailer.rb +6 -0
- data/app/models/concerns/queue_it/queable.rb +89 -0
- data/app/models/queue_it/application_record.rb +5 -0
- data/app/models/queue_it/node.rb +68 -0
- data/app/models/queue_it/queue.rb +111 -0
- data/app/views/layouts/queue_it/application.html.erb +15 -0
- data/bin/rails +25 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20210723140008_create_queue_it_queues.rb +10 -0
- data/db/migrate/20210723140434_create_queue_it_nodes.rb +12 -0
- data/lib/generators/queue_it/install/USAGE +5 -0
- data/lib/generators/queue_it/install/install_generator.rb +19 -0
- data/lib/generators/queue_it/install/templates/initializer.rb +2 -0
- data/lib/queue_it.rb +25 -0
- data/lib/queue_it/engine.rb +15 -0
- data/lib/queue_it/example_class.rb +7 -0
- data/lib/queue_it/version.rb +3 -0
- data/lib/tasks/auto_annotate_models.rake +67 -0
- data/lib/tasks/queue_it_tasks.rake +4 -0
- data/queue_it.gemspec +38 -0
- data/spec/concerns/queue_it/queable_spec.rb +492 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/javascript/packs/application.js +15 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/task.rb +3 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +30 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +27 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +81 -0
- data/spec/dummy/config/environments/production.rb +112 -0
- data/spec/dummy/config/environments/test.rb +49 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +12 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +38 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/migrate/20210723142357_create_users.rb +9 -0
- data/spec/dummy/db/migrate/20210723172002_create_tasks.rb +9 -0
- data/spec/dummy/db/schema.rb +52 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/models/task_spec.rb +7 -0
- data/spec/dummy/spec/models/user_spec.rb +7 -0
- data/spec/factories/queue_it/nodes.rb +18 -0
- data/spec/factories/queue_it/queues.rb +26 -0
- data/spec/factories/tasks.rb +11 -0
- data/spec/factories/users.rb +5 -0
- data/spec/fixtures/files/image.png +0 -0
- data/spec/fixtures/files/video.mp4 +0 -0
- data/spec/models/queue_it/node_spec.rb +43 -0
- data/spec/models/queue_it/queue_spec.rb +116 -0
- data/spec/queue_it_spec.rb +16 -0
- data/spec/rails_helper.rb +52 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/test_helpers.rb +5 -0
- metadata +441 -0
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
|
+
|
4
|
+
# Declare your gem's dependencies in queue_it.gemspec.
|
5
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
6
|
+
# development dependencies will be added by default to the :development group.
|
7
|
+
gemspec
|
8
|
+
|
9
|
+
# Declare any dependencies that are still in development here instead of in
|
10
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
11
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
12
|
+
# your gem to rubygems.org.
|
13
|
+
|
14
|
+
# To use a debugger
|
15
|
+
# gem 'byebug', group: [:development, :test]
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,277 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails-queue-it (0.1.0)
|
5
|
+
rails (>= 6.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (6.1.4)
|
11
|
+
actionpack (= 6.1.4)
|
12
|
+
activesupport (= 6.1.4)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (6.1.4)
|
16
|
+
actionpack (= 6.1.4)
|
17
|
+
activejob (= 6.1.4)
|
18
|
+
activerecord (= 6.1.4)
|
19
|
+
activestorage (= 6.1.4)
|
20
|
+
activesupport (= 6.1.4)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
actionmailer (6.1.4)
|
23
|
+
actionpack (= 6.1.4)
|
24
|
+
actionview (= 6.1.4)
|
25
|
+
activejob (= 6.1.4)
|
26
|
+
activesupport (= 6.1.4)
|
27
|
+
mail (~> 2.5, >= 2.5.4)
|
28
|
+
rails-dom-testing (~> 2.0)
|
29
|
+
actionpack (6.1.4)
|
30
|
+
actionview (= 6.1.4)
|
31
|
+
activesupport (= 6.1.4)
|
32
|
+
rack (~> 2.0, >= 2.0.9)
|
33
|
+
rack-test (>= 0.6.3)
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
+
actiontext (6.1.4)
|
37
|
+
actionpack (= 6.1.4)
|
38
|
+
activerecord (= 6.1.4)
|
39
|
+
activestorage (= 6.1.4)
|
40
|
+
activesupport (= 6.1.4)
|
41
|
+
nokogiri (>= 1.8.5)
|
42
|
+
actionview (6.1.4)
|
43
|
+
activesupport (= 6.1.4)
|
44
|
+
builder (~> 3.1)
|
45
|
+
erubi (~> 1.4)
|
46
|
+
rails-dom-testing (~> 2.0)
|
47
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
+
activejob (6.1.4)
|
49
|
+
activesupport (= 6.1.4)
|
50
|
+
globalid (>= 0.3.6)
|
51
|
+
activemodel (6.1.4)
|
52
|
+
activesupport (= 6.1.4)
|
53
|
+
activerecord (6.1.4)
|
54
|
+
activemodel (= 6.1.4)
|
55
|
+
activesupport (= 6.1.4)
|
56
|
+
activestorage (6.1.4)
|
57
|
+
actionpack (= 6.1.4)
|
58
|
+
activejob (= 6.1.4)
|
59
|
+
activerecord (= 6.1.4)
|
60
|
+
activesupport (= 6.1.4)
|
61
|
+
marcel (~> 1.0.0)
|
62
|
+
mini_mime (>= 1.1.0)
|
63
|
+
activesupport (6.1.4)
|
64
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
65
|
+
i18n (>= 1.6, < 2)
|
66
|
+
minitest (>= 5.1)
|
67
|
+
tzinfo (~> 2.0)
|
68
|
+
zeitwerk (~> 2.3)
|
69
|
+
annotate (3.1.1)
|
70
|
+
activerecord (>= 3.2, < 7.0)
|
71
|
+
rake (>= 10.4, < 14.0)
|
72
|
+
ast (2.4.2)
|
73
|
+
builder (3.2.4)
|
74
|
+
coderay (1.1.3)
|
75
|
+
concurrent-ruby (1.1.9)
|
76
|
+
coveralls (0.8.23)
|
77
|
+
json (>= 1.8, < 3)
|
78
|
+
simplecov (~> 0.16.1)
|
79
|
+
term-ansicolor (~> 1.3)
|
80
|
+
thor (>= 0.19.4, < 2.0)
|
81
|
+
tins (~> 1.6)
|
82
|
+
crass (1.0.6)
|
83
|
+
diff-lcs (1.4.4)
|
84
|
+
docile (1.4.0)
|
85
|
+
erubi (1.10.0)
|
86
|
+
factory_bot (6.2.0)
|
87
|
+
activesupport (>= 5.0.0)
|
88
|
+
factory_bot_rails (6.2.0)
|
89
|
+
factory_bot (~> 6.2.0)
|
90
|
+
railties (>= 5.0.0)
|
91
|
+
faker (2.18.0)
|
92
|
+
i18n (>= 1.6, < 2)
|
93
|
+
ffi (1.15.3)
|
94
|
+
formatador (0.3.0)
|
95
|
+
globalid (0.5.2)
|
96
|
+
activesupport (>= 5.0)
|
97
|
+
guard (2.18.0)
|
98
|
+
formatador (>= 0.2.4)
|
99
|
+
listen (>= 2.7, < 4.0)
|
100
|
+
lumberjack (>= 1.0.12, < 2.0)
|
101
|
+
nenv (~> 0.1)
|
102
|
+
notiffany (~> 0.0)
|
103
|
+
pry (>= 0.13.0)
|
104
|
+
shellany (~> 0.0)
|
105
|
+
thor (>= 0.18.1)
|
106
|
+
guard-compat (1.2.1)
|
107
|
+
guard-rspec (4.7.3)
|
108
|
+
guard (~> 2.1)
|
109
|
+
guard-compat (~> 1.1)
|
110
|
+
rspec (>= 2.99.0, < 4.0)
|
111
|
+
i18n (1.8.10)
|
112
|
+
concurrent-ruby (~> 1.0)
|
113
|
+
json (2.5.1)
|
114
|
+
listen (3.6.0)
|
115
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
116
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
117
|
+
loofah (2.10.0)
|
118
|
+
crass (~> 1.0.2)
|
119
|
+
nokogiri (>= 1.5.9)
|
120
|
+
lumberjack (1.2.8)
|
121
|
+
mail (2.7.1)
|
122
|
+
mini_mime (>= 0.1.1)
|
123
|
+
marcel (1.0.1)
|
124
|
+
method_source (1.0.0)
|
125
|
+
mini_mime (1.1.0)
|
126
|
+
minitest (5.14.4)
|
127
|
+
nenv (0.3.0)
|
128
|
+
nio4r (2.5.8)
|
129
|
+
nokogiri (1.11.7-arm64-darwin)
|
130
|
+
racc (~> 1.4)
|
131
|
+
nokogiri (1.11.7-x86_64-darwin)
|
132
|
+
racc (~> 1.4)
|
133
|
+
nokogiri (1.11.7-x86_64-linux)
|
134
|
+
racc (~> 1.4)
|
135
|
+
notiffany (0.1.3)
|
136
|
+
nenv (~> 0.1)
|
137
|
+
shellany (~> 0.0)
|
138
|
+
parallel (1.20.1)
|
139
|
+
parser (3.0.2.0)
|
140
|
+
ast (~> 2.4.1)
|
141
|
+
pg (1.2.3)
|
142
|
+
pry (0.14.1)
|
143
|
+
coderay (~> 1.1)
|
144
|
+
method_source (~> 1.0)
|
145
|
+
pry-rails (0.3.9)
|
146
|
+
pry (>= 0.10.4)
|
147
|
+
racc (1.5.2)
|
148
|
+
rack (2.2.3)
|
149
|
+
rack-test (1.1.0)
|
150
|
+
rack (>= 1.0, < 3)
|
151
|
+
rails (6.1.4)
|
152
|
+
actioncable (= 6.1.4)
|
153
|
+
actionmailbox (= 6.1.4)
|
154
|
+
actionmailer (= 6.1.4)
|
155
|
+
actionpack (= 6.1.4)
|
156
|
+
actiontext (= 6.1.4)
|
157
|
+
actionview (= 6.1.4)
|
158
|
+
activejob (= 6.1.4)
|
159
|
+
activemodel (= 6.1.4)
|
160
|
+
activerecord (= 6.1.4)
|
161
|
+
activestorage (= 6.1.4)
|
162
|
+
activesupport (= 6.1.4)
|
163
|
+
bundler (>= 1.15.0)
|
164
|
+
railties (= 6.1.4)
|
165
|
+
sprockets-rails (>= 2.0.0)
|
166
|
+
rails-dom-testing (2.0.3)
|
167
|
+
activesupport (>= 4.2.0)
|
168
|
+
nokogiri (>= 1.6)
|
169
|
+
rails-html-sanitizer (1.3.0)
|
170
|
+
loofah (~> 2.3)
|
171
|
+
railties (6.1.4)
|
172
|
+
actionpack (= 6.1.4)
|
173
|
+
activesupport (= 6.1.4)
|
174
|
+
method_source
|
175
|
+
rake (>= 0.13)
|
176
|
+
thor (~> 1.0)
|
177
|
+
rainbow (3.0.0)
|
178
|
+
rake (13.0.6)
|
179
|
+
rb-fsevent (0.11.0)
|
180
|
+
rb-inotify (0.10.1)
|
181
|
+
ffi (~> 1.0)
|
182
|
+
regexp_parser (2.1.1)
|
183
|
+
rexml (3.2.5)
|
184
|
+
rspec (3.10.0)
|
185
|
+
rspec-core (~> 3.10.0)
|
186
|
+
rspec-expectations (~> 3.10.0)
|
187
|
+
rspec-mocks (~> 3.10.0)
|
188
|
+
rspec-core (3.10.1)
|
189
|
+
rspec-support (~> 3.10.0)
|
190
|
+
rspec-expectations (3.10.1)
|
191
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
192
|
+
rspec-support (~> 3.10.0)
|
193
|
+
rspec-mocks (3.10.2)
|
194
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
195
|
+
rspec-support (~> 3.10.0)
|
196
|
+
rspec-rails (5.0.1)
|
197
|
+
actionpack (>= 5.2)
|
198
|
+
activesupport (>= 5.2)
|
199
|
+
railties (>= 5.2)
|
200
|
+
rspec-core (~> 3.10)
|
201
|
+
rspec-expectations (~> 3.10)
|
202
|
+
rspec-mocks (~> 3.10)
|
203
|
+
rspec-support (~> 3.10)
|
204
|
+
rspec-support (3.10.2)
|
205
|
+
rspec_junit_formatter (0.4.1)
|
206
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
207
|
+
rubocop (1.18.4)
|
208
|
+
parallel (~> 1.10)
|
209
|
+
parser (>= 3.0.0.0)
|
210
|
+
rainbow (>= 2.2.2, < 4.0)
|
211
|
+
regexp_parser (>= 1.8, < 3.0)
|
212
|
+
rexml
|
213
|
+
rubocop-ast (>= 1.8.0, < 2.0)
|
214
|
+
ruby-progressbar (~> 1.7)
|
215
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
216
|
+
rubocop-ast (1.8.0)
|
217
|
+
parser (>= 3.0.1.1)
|
218
|
+
rubocop-rails (2.11.3)
|
219
|
+
activesupport (>= 4.2.0)
|
220
|
+
rack (>= 1.1)
|
221
|
+
rubocop (>= 1.7.0, < 2.0)
|
222
|
+
ruby-progressbar (1.11.0)
|
223
|
+
shellany (0.0.1)
|
224
|
+
shoulda-matchers (5.0.0)
|
225
|
+
activesupport (>= 5.2.0)
|
226
|
+
simplecov (0.16.1)
|
227
|
+
docile (~> 1.1)
|
228
|
+
json (>= 1.8, < 3)
|
229
|
+
simplecov-html (~> 0.10.0)
|
230
|
+
simplecov-html (0.10.2)
|
231
|
+
sprockets (4.0.2)
|
232
|
+
concurrent-ruby (~> 1.0)
|
233
|
+
rack (> 1, < 3)
|
234
|
+
sprockets-rails (3.2.2)
|
235
|
+
actionpack (>= 4.0)
|
236
|
+
activesupport (>= 4.0)
|
237
|
+
sprockets (>= 3.0.0)
|
238
|
+
sqlite3 (1.4.2)
|
239
|
+
sync (0.5.0)
|
240
|
+
term-ansicolor (1.7.1)
|
241
|
+
tins (~> 1.0)
|
242
|
+
thor (1.1.0)
|
243
|
+
tins (1.29.1)
|
244
|
+
sync
|
245
|
+
tzinfo (2.0.4)
|
246
|
+
concurrent-ruby (~> 1.0)
|
247
|
+
unicode-display_width (2.0.0)
|
248
|
+
websocket-driver (0.7.5)
|
249
|
+
websocket-extensions (>= 0.1.0)
|
250
|
+
websocket-extensions (0.1.5)
|
251
|
+
zeitwerk (2.4.2)
|
252
|
+
|
253
|
+
PLATFORMS
|
254
|
+
arm64-darwin-20
|
255
|
+
x86_64-darwin-20
|
256
|
+
x86_64-linux
|
257
|
+
|
258
|
+
DEPENDENCIES
|
259
|
+
annotate (~> 3.0)
|
260
|
+
bundler (~> 2.2.15)
|
261
|
+
coveralls
|
262
|
+
factory_bot_rails
|
263
|
+
faker
|
264
|
+
guard-rspec
|
265
|
+
pg
|
266
|
+
pry
|
267
|
+
pry-rails
|
268
|
+
rails-queue-it!
|
269
|
+
rspec-rails
|
270
|
+
rspec_junit_formatter
|
271
|
+
rubocop (~> 1.9)
|
272
|
+
rubocop-rails
|
273
|
+
shoulda-matchers
|
274
|
+
sqlite3
|
275
|
+
|
276
|
+
BUNDLED WITH
|
277
|
+
2.2.24
|
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
spec_dic = "spec"
|
3
|
+
# RSpec files
|
4
|
+
watch("spec/spec_helper.rb") { spec_dic }
|
5
|
+
watch("spec/rails_helper.rb") { spec_dic }
|
6
|
+
watch(%r{^spec/support/(.+)\.rb$}) { spec_dic }
|
7
|
+
watch(%r{^spec/.+_spec\.rb$})
|
8
|
+
# Engine files
|
9
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright 2021 Platanus
|
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,202 @@
|
|
1
|
+
# Queue It
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/queue-it.svg)](https://badge.fury.io/rb/queue-it)
|
4
|
+
[![CircleCI](https://circleci.com/gh/platanus/queue-it.svg?style=shield)](https://app.circleci.com/pipelines/github/platanus/queue-it)
|
5
|
+
|
6
|
+
This gem has been develope to manage recurrent processes that need someone (or something) responsable.
|
7
|
+
For example, imagine you have a recurrent task for a certain group of people like responding the chat of
|
8
|
+
your website. A recurrent queue would help you distribuit in a uniform way the workload of the people in the group.
|
9
|
+
This gem installs an engine in your rails app.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add to your Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem "queue-it"
|
17
|
+
```
|
18
|
+
|
19
|
+
```bash
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
Then, run the installer:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
rails generate queue_it:install
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
For the purpose of this explanation we'll use the models `Task` and `User` to explain the workaround of this gem. Both models only have one attribute: `:name`.
|
32
|
+
### Models of the gem
|
33
|
+
This gem implements the models `QueueIt::Queue` and `QueueIt::Node`, each queue has polymorphic relation with a queable object (i.e. a `Task` instace) and each node has a polymorphic relation with a nodable object (i.e. the object queued).
|
34
|
+
|
35
|
+
### Before Starting
|
36
|
+
This gem uses [`ActiveRecord::Locking::Pessimistic `](https://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html) so the behaviour with sqlite is not the same as with Postgres or MySql. Make sure you use one of the latters.
|
37
|
+
### Queable concern
|
38
|
+
Add the `QueueIt::Queable` concern to the model you want to have a queue. In this case we'll ilustrate this with the task model:
|
39
|
+
```ruby
|
40
|
+
class Task < ApplicationRecord
|
41
|
+
include QueueIt::Queable
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### Concern methods
|
46
|
+
With the `QueueIt::Queable` concern added to your model you'll have access to a group of methods to manage the queue's behaviour.
|
47
|
+
Note that in this version of the gem the model with the concern will have only one queue through a `has_one` relationship included in the concern.
|
48
|
+
|
49
|
+
#### Create a Queue
|
50
|
+
The method `find_or_create_queue!` present in the concern will return a new queue (in case it was not created) or the queue realated to the instance model.
|
51
|
+
```ruby
|
52
|
+
task = Task.create!(name: 'Example Task')
|
53
|
+
task_queue = task.find_or_create_queue!
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Add a node to the Queue
|
57
|
+
The method `push_to_queue` will allow you to add a nodable in the first position of the queue or the last one depending on the `head_node` param.
|
58
|
+
```ruby
|
59
|
+
task = Task.create!(name: 'Example Task')
|
60
|
+
nodable = User.create!(name: 'Gabriel')
|
61
|
+
head_node = true
|
62
|
+
# add the user as the nodable object in the first node of the queue
|
63
|
+
task.push_to_queue(nodable, head_node)
|
64
|
+
```
|
65
|
+
Note that the second value (`head_node`) is optional with a default `true` value.
|
66
|
+
|
67
|
+
> It's not necessary to create the queue manually. The `push_to_queue` method will execute `find_or_create_queue!` before adding the node.
|
68
|
+
|
69
|
+
#### Get next nodable/node of the queue
|
70
|
+
To obtain the next nodable/node of the queue we've implemented the methods `get_next_in_queue` and `get_next_node_in_queue`. The first one calls the second one but instead of returning the node returns the nodable object.
|
71
|
+
First, let's add some nodes to the queue:
|
72
|
+
```ruby
|
73
|
+
task = Task.create!(name: 'Example')
|
74
|
+
task.push_to_queue(User.create!(name: 'Gabriel'))
|
75
|
+
task.push_to_queue(User.create!(name: 'Leandro'))
|
76
|
+
task.push_to_queue(User.create!(name: 'Raimundo'))
|
77
|
+
# Note that the order of the queue is now: [Raimundo's node, Leandro's node, Gabriel's node]
|
78
|
+
```
|
79
|
+
Now with the `get_next_in_queue` method we'll the obtain user with name `'Raimundo'` and the order of the queue will be updated.
|
80
|
+
```ruby
|
81
|
+
nodable = task.get_next_in_queue
|
82
|
+
nodable.name == 'Raimundo' # true
|
83
|
+
# the new order of the queue will be: [Leandro's node, Gabriel's node, Raimundo's node]
|
84
|
+
```
|
85
|
+
Now if we would of used `get_next_node_in_queue` instead of `get_next_in_queue` method we would of obtained the node containing the user with name `'Raimundo'` as nodable and the order of the queue would have been updated like before.
|
86
|
+
```ruby
|
87
|
+
node = task.get_next_in_queue
|
88
|
+
node.nodable.name == 'Raimundo' # true
|
89
|
+
# the new order of the queue will be: [Leandro's node, Gabriel's node, Raimundo's node]
|
90
|
+
```
|
91
|
+
|
92
|
+
#### Formatted Queue
|
93
|
+
We included a method to obtain the queue formatted by an attribute/method. Note that the nodables will need to have the attribute or an implementation of the method called.
|
94
|
+
```ruby
|
95
|
+
# creation of the queue
|
96
|
+
task = Task.create!(name: 'Example')
|
97
|
+
task.push_to_queue(User.create!(name: 'Gabriel'))
|
98
|
+
task.push_to_queue(User.create!(name: 'Leandro'))
|
99
|
+
task.push_to_queue(User.create!(name: 'Raimundo'))
|
100
|
+
# The order of the queue is now: [Raimundo's node, Leandro's node, Gabriel's node]
|
101
|
+
response = task.formatted_queue('name')
|
102
|
+
response == ['Raimundo', 'Leandro', 'Gabriel'] # true
|
103
|
+
```
|
104
|
+
|
105
|
+
#### Delete all the nodes of the queue
|
106
|
+
With the method `delete_queue_nodes` you'll be able to clean the queue.
|
107
|
+
```ruby
|
108
|
+
task = Task.create!(name: 'Example')
|
109
|
+
task.push_to_queue(User.create!(name: 'Gabriel'))
|
110
|
+
task.push_to_queue(User.create!(name: 'Leandro'))
|
111
|
+
task.push_to_queue(User.create!(name: 'Raimundo'))
|
112
|
+
# delete de queue nodes
|
113
|
+
task.delete_queue_nodes
|
114
|
+
task.queue.size? == 0 # true
|
115
|
+
```
|
116
|
+
|
117
|
+
#### Remove a nodable object
|
118
|
+
In case you need to remove all the nodes of a queue containing an specific nodable you can use the `remove_from_queue(nodable)` method.
|
119
|
+
```ruby
|
120
|
+
task = Task.create!(name: 'Example')
|
121
|
+
gabriel = User.create!(name: 'Gabriel')
|
122
|
+
leandro = User.create!(name: 'Leandro')
|
123
|
+
raimundo = User.create!(name: 'Raimundo')
|
124
|
+
task.push_to_queue(gabriel)
|
125
|
+
task.push_to_queue(leandro)
|
126
|
+
task.push_to_queue(raimundo)
|
127
|
+
task.push_to_queue(leandro)
|
128
|
+
# Now we have a queue that look's like this:
|
129
|
+
# [Leandro's node, Raimundo's node, Leandro's node, Gabriel's node]
|
130
|
+
task.remove_from_queue(leandro)
|
131
|
+
# The queue will now look like this: [Raimundo's node, Gabriel's node]
|
132
|
+
```
|
133
|
+
|
134
|
+
## Development
|
135
|
+
|
136
|
+
### Models and migrations
|
137
|
+
|
138
|
+
- Create dummy app models with development and testing purposes inside the dummy app `spec/dummy`:
|
139
|
+
|
140
|
+
`bin/rails g model user`
|
141
|
+
|
142
|
+
The `User` model will be created in `spec/dummy/app/models`.
|
143
|
+
The `user_spec.rb` file needs to be deleted, but it is a good idea to leave the factory.
|
144
|
+
|
145
|
+
- Create engine related models inside the engine's root path '/':
|
146
|
+
|
147
|
+
`bin/rails g model job`
|
148
|
+
|
149
|
+
The `EngineName::Job` model will be created in `app/models/engine_name`.
|
150
|
+
A factory will be added to `engine_name/spec/factories/engine_name/jobs.rb`, you must to add the `class` option manually.
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
FactoryBot.define do
|
154
|
+
factory :job, class: "EngineName::Job" do
|
155
|
+
# ...
|
156
|
+
end
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
- While developing the engine run migrations in the root path `bin/rails db:migrate`. This will apply the gem and dummy app migrations too.
|
161
|
+
- When using in a project, the engine migrations must be copied to it. This can be done by running: `bin/rails engine_name:install:migrations`
|
162
|
+
|
163
|
+
## Testing
|
164
|
+
|
165
|
+
To run the specs you need to execute, in the root path of the engine, the following command:
|
166
|
+
|
167
|
+
```bash
|
168
|
+
bundle exec guard
|
169
|
+
```
|
170
|
+
|
171
|
+
You need to put **all your tests** in the `/queue_it/spec` directory.
|
172
|
+
|
173
|
+
## Publishing
|
174
|
+
|
175
|
+
On master/main branch...
|
176
|
+
|
177
|
+
1. Change `VERSION` in `lib/queue_it/version.rb`.
|
178
|
+
2. Change `Unreleased` title to current version in `CHANGELOG.md`.
|
179
|
+
3. Run `bundle install`.
|
180
|
+
4. Commit new release. For example: `Releasing v0.1.0`.
|
181
|
+
5. Create tag. For example: `git tag v0.1.0`.
|
182
|
+
6. Push tag. For example: `git push origin v0.1.0`.
|
183
|
+
|
184
|
+
## Contributing
|
185
|
+
|
186
|
+
1. Fork it
|
187
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
188
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
189
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
190
|
+
5. Create new Pull Request
|
191
|
+
|
192
|
+
## Credits
|
193
|
+
|
194
|
+
Thank you [contributors](https://github.com/platanus/queue_it/graphs/contributors)!
|
195
|
+
|
196
|
+
<img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
|
197
|
+
|
198
|
+
Queue It is maintained by [platanus](http://platan.us).
|
199
|
+
|
200
|
+
## License
|
201
|
+
|
202
|
+
Queue It is © 2021 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
|