quiq 0.1.0
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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +181 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/quiq +36 -0
- data/bin/setup +8 -0
- data/lib/quiq.rb +45 -0
- data/lib/quiq/client.rb +19 -0
- data/lib/quiq/config.rb +29 -0
- data/lib/quiq/server.rb +31 -0
- data/lib/quiq/version.rb +5 -0
- data/lib/quiq/worker.rb +22 -0
- data/quiq.gemspec +28 -0
- data/testapp/.ruby-version +1 -0
- data/testapp/Gemfile +14 -0
- data/testapp/Gemfile.lock +181 -0
- data/testapp/README.md +24 -0
- data/testapp/Rakefile +6 -0
- data/testapp/app/controllers/application_controller.rb +2 -0
- data/testapp/app/controllers/concerns/.keep +0 -0
- data/testapp/app/jobs/application_job.rb +7 -0
- data/testapp/app/jobs/test_job.rb +9 -0
- data/testapp/app/models/concerns/.keep +0 -0
- data/testapp/bin/bundle +114 -0
- data/testapp/bin/rails +4 -0
- data/testapp/bin/rake +4 -0
- data/testapp/bin/setup +25 -0
- data/testapp/config.ru +5 -0
- data/testapp/config/application.rb +40 -0
- data/testapp/config/boot.rb +4 -0
- data/testapp/config/credentials.yml.enc +1 -0
- data/testapp/config/environment.rb +5 -0
- data/testapp/config/environments/development.rb +38 -0
- data/testapp/config/environments/production.rb +88 -0
- data/testapp/config/environments/test.rb +38 -0
- data/testapp/config/initializers/application_controller_renderer.rb +8 -0
- data/testapp/config/initializers/backtrace_silencers.rb +7 -0
- data/testapp/config/initializers/cors.rb +16 -0
- data/testapp/config/initializers/filter_parameter_logging.rb +4 -0
- data/testapp/config/initializers/inflections.rb +16 -0
- data/testapp/config/initializers/mime_types.rb +4 -0
- data/testapp/config/initializers/quiq.rb +28 -0
- data/testapp/config/initializers/wrap_parameters.rb +9 -0
- data/testapp/config/locales/en.yml +33 -0
- data/testapp/config/master.key +1 -0
- data/testapp/config/routes.rb +3 -0
- data/testapp/lib/tasks/.keep +0 -0
- data/testapp/public/robots.txt +1 -0
- data/testapp/tmp/.keep +0 -0
- data/testapp/tmp/development_secret.txt +1 -0
- data/testapp/tmp/pids/.keep +0 -0
- data/testapp/vendor/.keep +0 -0
- metadata +144 -0
data/lib/quiq/server.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
require 'async/container'
|
5
|
+
require 'async/redis'
|
6
|
+
require_relative 'worker'
|
7
|
+
|
8
|
+
module Quiq
|
9
|
+
class Server < Async::Container::Controller
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
# Called by Server.instance.run
|
13
|
+
def setup(container)
|
14
|
+
@queues = Quiq.queues.map { |q| "queue:#{q}" }
|
15
|
+
|
16
|
+
container.async do
|
17
|
+
loop do
|
18
|
+
job = fetch_one
|
19
|
+
Worker.new(job).run
|
20
|
+
end
|
21
|
+
ensure
|
22
|
+
Quiq.redis.close
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch_one
|
27
|
+
# BRPOP returns a tuple made of the queue name then the args
|
28
|
+
Quiq.redis.brpop(*@queues).last
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/quiq/version.rb
ADDED
data/lib/quiq/worker.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Quiq
|
6
|
+
class Worker
|
7
|
+
def initialize(job)
|
8
|
+
# TODO: handle deserialization errors
|
9
|
+
@job = JSON.parse(job) rescue nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
return if @job.nil?
|
14
|
+
|
15
|
+
Async do
|
16
|
+
klass = Object.const_get(@job['job_class'])
|
17
|
+
args = @job['arguments']
|
18
|
+
klass.new.perform(*args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/quiq.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/quiq/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'quiq'
|
7
|
+
spec.version = Quiq::VERSION
|
8
|
+
spec.authors = ['Salim Semaoune']
|
9
|
+
|
10
|
+
spec.summary = 'amazing summary'
|
11
|
+
spec.description = 'gorgeous description'
|
12
|
+
spec.homepage = 'https://github.com/sailor/quiq'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'bin'
|
22
|
+
spec.executables = ['quiq']
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'async-container', '~> 0.16'
|
26
|
+
spec.add_dependency 'async-redis', '~> 0.4'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.7.0
|
data/testapp/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
5
|
+
|
6
|
+
ruby '2.7.0'
|
7
|
+
|
8
|
+
gem 'bootsnap', '>= 1.4.2', require: false
|
9
|
+
gem 'quiq', path: '..'
|
10
|
+
gem 'rails', '~> 6.0.2', '>= 6.0.2.1'
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem 'listen', '>= 3.0.5', '< 3.2'
|
14
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
quiq (0.1.0)
|
5
|
+
async-container (~> 0.16)
|
6
|
+
async-redis (~> 0.4)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (6.0.2.1)
|
12
|
+
actionpack (= 6.0.2.1)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (6.0.2.1)
|
16
|
+
actionpack (= 6.0.2.1)
|
17
|
+
activejob (= 6.0.2.1)
|
18
|
+
activerecord (= 6.0.2.1)
|
19
|
+
activestorage (= 6.0.2.1)
|
20
|
+
activesupport (= 6.0.2.1)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
actionmailer (6.0.2.1)
|
23
|
+
actionpack (= 6.0.2.1)
|
24
|
+
actionview (= 6.0.2.1)
|
25
|
+
activejob (= 6.0.2.1)
|
26
|
+
mail (~> 2.5, >= 2.5.4)
|
27
|
+
rails-dom-testing (~> 2.0)
|
28
|
+
actionpack (6.0.2.1)
|
29
|
+
actionview (= 6.0.2.1)
|
30
|
+
activesupport (= 6.0.2.1)
|
31
|
+
rack (~> 2.0, >= 2.0.8)
|
32
|
+
rack-test (>= 0.6.3)
|
33
|
+
rails-dom-testing (~> 2.0)
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
35
|
+
actiontext (6.0.2.1)
|
36
|
+
actionpack (= 6.0.2.1)
|
37
|
+
activerecord (= 6.0.2.1)
|
38
|
+
activestorage (= 6.0.2.1)
|
39
|
+
activesupport (= 6.0.2.1)
|
40
|
+
nokogiri (>= 1.8.5)
|
41
|
+
actionview (6.0.2.1)
|
42
|
+
activesupport (= 6.0.2.1)
|
43
|
+
builder (~> 3.1)
|
44
|
+
erubi (~> 1.4)
|
45
|
+
rails-dom-testing (~> 2.0)
|
46
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
47
|
+
activejob (6.0.2.1)
|
48
|
+
activesupport (= 6.0.2.1)
|
49
|
+
globalid (>= 0.3.6)
|
50
|
+
activemodel (6.0.2.1)
|
51
|
+
activesupport (= 6.0.2.1)
|
52
|
+
activerecord (6.0.2.1)
|
53
|
+
activemodel (= 6.0.2.1)
|
54
|
+
activesupport (= 6.0.2.1)
|
55
|
+
activestorage (6.0.2.1)
|
56
|
+
actionpack (= 6.0.2.1)
|
57
|
+
activejob (= 6.0.2.1)
|
58
|
+
activerecord (= 6.0.2.1)
|
59
|
+
marcel (~> 0.3.1)
|
60
|
+
activesupport (6.0.2.1)
|
61
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
62
|
+
i18n (>= 0.7, < 2)
|
63
|
+
minitest (~> 5.1)
|
64
|
+
tzinfo (~> 1.1)
|
65
|
+
zeitwerk (~> 2.2)
|
66
|
+
async (1.24.2)
|
67
|
+
console (~> 1.0)
|
68
|
+
nio4r (~> 2.3)
|
69
|
+
timers (~> 4.1)
|
70
|
+
async-container (0.16.1)
|
71
|
+
async (~> 1.0)
|
72
|
+
async-io (~> 1.26)
|
73
|
+
process-group
|
74
|
+
async-io (1.27.3)
|
75
|
+
async (~> 1.14)
|
76
|
+
async-redis (0.4.1)
|
77
|
+
async (~> 1.8)
|
78
|
+
async-io (~> 1.10)
|
79
|
+
protocol-redis (~> 0.2.0)
|
80
|
+
bootsnap (1.4.5)
|
81
|
+
msgpack (~> 1.0)
|
82
|
+
builder (3.2.4)
|
83
|
+
concurrent-ruby (1.1.5)
|
84
|
+
console (1.8.0)
|
85
|
+
crass (1.0.6)
|
86
|
+
erubi (1.9.0)
|
87
|
+
ffi (1.12.1)
|
88
|
+
globalid (0.4.2)
|
89
|
+
activesupport (>= 4.2.0)
|
90
|
+
i18n (1.8.2)
|
91
|
+
concurrent-ruby (~> 1.0)
|
92
|
+
listen (3.1.5)
|
93
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
94
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
95
|
+
ruby_dep (~> 1.2)
|
96
|
+
loofah (2.4.0)
|
97
|
+
crass (~> 1.0.2)
|
98
|
+
nokogiri (>= 1.5.9)
|
99
|
+
mail (2.7.1)
|
100
|
+
mini_mime (>= 0.1.1)
|
101
|
+
marcel (0.3.3)
|
102
|
+
mimemagic (~> 0.3.2)
|
103
|
+
method_source (0.9.2)
|
104
|
+
mimemagic (0.3.3)
|
105
|
+
mini_mime (1.0.2)
|
106
|
+
mini_portile2 (2.4.0)
|
107
|
+
minitest (5.14.0)
|
108
|
+
msgpack (1.3.1)
|
109
|
+
nio4r (2.5.2)
|
110
|
+
nokogiri (1.10.7)
|
111
|
+
mini_portile2 (~> 2.4.0)
|
112
|
+
process-group (1.2.1)
|
113
|
+
process-terminal (~> 0.2.0)
|
114
|
+
process-terminal (0.2.0)
|
115
|
+
ffi
|
116
|
+
protocol-redis (0.2.0)
|
117
|
+
rack (2.1.1)
|
118
|
+
rack-test (1.1.0)
|
119
|
+
rack (>= 1.0, < 3)
|
120
|
+
rails (6.0.2.1)
|
121
|
+
actioncable (= 6.0.2.1)
|
122
|
+
actionmailbox (= 6.0.2.1)
|
123
|
+
actionmailer (= 6.0.2.1)
|
124
|
+
actionpack (= 6.0.2.1)
|
125
|
+
actiontext (= 6.0.2.1)
|
126
|
+
actionview (= 6.0.2.1)
|
127
|
+
activejob (= 6.0.2.1)
|
128
|
+
activemodel (= 6.0.2.1)
|
129
|
+
activerecord (= 6.0.2.1)
|
130
|
+
activestorage (= 6.0.2.1)
|
131
|
+
activesupport (= 6.0.2.1)
|
132
|
+
bundler (>= 1.3.0)
|
133
|
+
railties (= 6.0.2.1)
|
134
|
+
sprockets-rails (>= 2.0.0)
|
135
|
+
rails-dom-testing (2.0.3)
|
136
|
+
activesupport (>= 4.2.0)
|
137
|
+
nokogiri (>= 1.6)
|
138
|
+
rails-html-sanitizer (1.3.0)
|
139
|
+
loofah (~> 2.3)
|
140
|
+
railties (6.0.2.1)
|
141
|
+
actionpack (= 6.0.2.1)
|
142
|
+
activesupport (= 6.0.2.1)
|
143
|
+
method_source
|
144
|
+
rake (>= 0.8.7)
|
145
|
+
thor (>= 0.20.3, < 2.0)
|
146
|
+
rake (13.0.1)
|
147
|
+
rb-fsevent (0.10.3)
|
148
|
+
rb-inotify (0.10.1)
|
149
|
+
ffi (~> 1.0)
|
150
|
+
ruby_dep (1.5.0)
|
151
|
+
sprockets (4.0.0)
|
152
|
+
concurrent-ruby (~> 1.0)
|
153
|
+
rack (> 1, < 3)
|
154
|
+
sprockets-rails (3.2.1)
|
155
|
+
actionpack (>= 4.0)
|
156
|
+
activesupport (>= 4.0)
|
157
|
+
sprockets (>= 3.0.0)
|
158
|
+
thor (1.0.1)
|
159
|
+
thread_safe (0.3.6)
|
160
|
+
timers (4.3.0)
|
161
|
+
tzinfo (1.2.6)
|
162
|
+
thread_safe (~> 0.1)
|
163
|
+
websocket-driver (0.7.1)
|
164
|
+
websocket-extensions (>= 0.1.0)
|
165
|
+
websocket-extensions (0.1.4)
|
166
|
+
zeitwerk (2.2.2)
|
167
|
+
|
168
|
+
PLATFORMS
|
169
|
+
ruby
|
170
|
+
|
171
|
+
DEPENDENCIES
|
172
|
+
bootsnap (>= 1.4.2)
|
173
|
+
listen (>= 3.0.5, < 3.2)
|
174
|
+
quiq!
|
175
|
+
rails (~> 6.0.2, >= 6.0.2.1)
|
176
|
+
|
177
|
+
RUBY VERSION
|
178
|
+
ruby 2.7.0p0
|
179
|
+
|
180
|
+
BUNDLED WITH
|
181
|
+
2.1.2
|
data/testapp/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
data/testapp/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
7
|
+
end
|
File without changes
|
data/testapp/bin/bundle
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "rubygems"
|
12
|
+
|
13
|
+
m = Module.new do
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def invoked_as_script?
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV["BUNDLER_VERSION"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def cli_arg_version
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
27
|
+
bundler_version = nil
|
28
|
+
update_index = nil
|
29
|
+
ARGV.each_with_index do |a, i|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
+
bundler_version = a
|
32
|
+
end
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
+
bundler_version = $1
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lockfile
|
48
|
+
lockfile =
|
49
|
+
case File.basename(gemfile)
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
51
|
+
else "#{gemfile}.lock"
|
52
|
+
end
|
53
|
+
File.expand_path(lockfile)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lockfile_version
|
57
|
+
return unless File.file?(lockfile)
|
58
|
+
lockfile_contents = File.read(lockfile)
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
60
|
+
Regexp.last_match(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bundler_version
|
64
|
+
@bundler_version ||=
|
65
|
+
env_var_version || cli_arg_version ||
|
66
|
+
lockfile_version
|
67
|
+
end
|
68
|
+
|
69
|
+
def bundler_requirement
|
70
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
71
|
+
|
72
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
73
|
+
|
74
|
+
requirement = bundler_gem_version.approximate_recommendation
|
75
|
+
|
76
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
77
|
+
|
78
|
+
requirement += ".a" if bundler_gem_version.prerelease?
|
79
|
+
|
80
|
+
requirement
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_bundler!
|
84
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
85
|
+
|
86
|
+
activate_bundler
|
87
|
+
end
|
88
|
+
|
89
|
+
def activate_bundler
|
90
|
+
gem_error = activation_error_handling do
|
91
|
+
gem "bundler", bundler_requirement
|
92
|
+
end
|
93
|
+
return if gem_error.nil?
|
94
|
+
require_error = activation_error_handling do
|
95
|
+
require "bundler/version"
|
96
|
+
end
|
97
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
98
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
99
|
+
exit 42
|
100
|
+
end
|
101
|
+
|
102
|
+
def activation_error_handling
|
103
|
+
yield
|
104
|
+
nil
|
105
|
+
rescue StandardError, LoadError => e
|
106
|
+
e
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
m.load_bundler!
|
111
|
+
|
112
|
+
if m.invoked_as_script?
|
113
|
+
load Gem.bin_path("bundler", "bundle")
|
114
|
+
end
|