quiq 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/.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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '087c9f77d2ec6838e562f95595c17620f00089367bcacd513dded5b35f4348da'
|
4
|
+
data.tar.gz: b8939bc5606d8677b78aa56b98a2c530a07f22d1c5a91d5433e5750041f56cf6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8502ee18454f56f2a7ff26d5c528b32a4cf5c417752a5d68e241d9662c7d7b94196067ffdcdd0591cbea6557c50263e4a4209f441e49aa971b8a2d68a9936aac
|
7
|
+
data.tar.gz: dc3e2e731796bc8834b453b1ab957a1a2307b59cd2613c5175ca3a6a001bb43d5c59d85f6aa020e36a8df26dbe2d493c23a14bc86719a747f5d2022b1abbb57a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -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
|
+
builder (3.2.4)
|
81
|
+
concurrent-ruby (1.1.5)
|
82
|
+
console (1.8.0)
|
83
|
+
crass (1.0.6)
|
84
|
+
diff-lcs (1.3)
|
85
|
+
erubi (1.9.0)
|
86
|
+
ffi (1.12.2)
|
87
|
+
globalid (0.4.2)
|
88
|
+
activesupport (>= 4.2.0)
|
89
|
+
i18n (1.8.2)
|
90
|
+
concurrent-ruby (~> 1.0)
|
91
|
+
loofah (2.4.0)
|
92
|
+
crass (~> 1.0.2)
|
93
|
+
nokogiri (>= 1.5.9)
|
94
|
+
mail (2.7.1)
|
95
|
+
mini_mime (>= 0.1.1)
|
96
|
+
marcel (0.3.3)
|
97
|
+
mimemagic (~> 0.3.2)
|
98
|
+
method_source (0.9.2)
|
99
|
+
mimemagic (0.3.3)
|
100
|
+
mini_mime (1.0.2)
|
101
|
+
mini_portile2 (2.4.0)
|
102
|
+
minitest (5.14.0)
|
103
|
+
nio4r (2.5.2)
|
104
|
+
nokogiri (1.10.7)
|
105
|
+
mini_portile2 (~> 2.4.0)
|
106
|
+
process-group (1.2.1)
|
107
|
+
process-terminal (~> 0.2.0)
|
108
|
+
process-terminal (0.2.0)
|
109
|
+
ffi
|
110
|
+
protocol-redis (0.2.0)
|
111
|
+
rack (2.1.1)
|
112
|
+
rack-test (1.1.0)
|
113
|
+
rack (>= 1.0, < 3)
|
114
|
+
rails (6.0.2.1)
|
115
|
+
actioncable (= 6.0.2.1)
|
116
|
+
actionmailbox (= 6.0.2.1)
|
117
|
+
actionmailer (= 6.0.2.1)
|
118
|
+
actionpack (= 6.0.2.1)
|
119
|
+
actiontext (= 6.0.2.1)
|
120
|
+
actionview (= 6.0.2.1)
|
121
|
+
activejob (= 6.0.2.1)
|
122
|
+
activemodel (= 6.0.2.1)
|
123
|
+
activerecord (= 6.0.2.1)
|
124
|
+
activestorage (= 6.0.2.1)
|
125
|
+
activesupport (= 6.0.2.1)
|
126
|
+
bundler (>= 1.3.0)
|
127
|
+
railties (= 6.0.2.1)
|
128
|
+
sprockets-rails (>= 2.0.0)
|
129
|
+
rails-dom-testing (2.0.3)
|
130
|
+
activesupport (>= 4.2.0)
|
131
|
+
nokogiri (>= 1.6)
|
132
|
+
rails-html-sanitizer (1.3.0)
|
133
|
+
loofah (~> 2.3)
|
134
|
+
railties (6.0.2.1)
|
135
|
+
actionpack (= 6.0.2.1)
|
136
|
+
activesupport (= 6.0.2.1)
|
137
|
+
method_source
|
138
|
+
rake (>= 0.8.7)
|
139
|
+
thor (>= 0.20.3, < 2.0)
|
140
|
+
rake (12.3.3)
|
141
|
+
rspec (3.9.0)
|
142
|
+
rspec-core (~> 3.9.0)
|
143
|
+
rspec-expectations (~> 3.9.0)
|
144
|
+
rspec-mocks (~> 3.9.0)
|
145
|
+
rspec-core (3.9.1)
|
146
|
+
rspec-support (~> 3.9.1)
|
147
|
+
rspec-expectations (3.9.0)
|
148
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
149
|
+
rspec-support (~> 3.9.0)
|
150
|
+
rspec-mocks (3.9.1)
|
151
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
152
|
+
rspec-support (~> 3.9.0)
|
153
|
+
rspec-support (3.9.2)
|
154
|
+
sprockets (4.0.0)
|
155
|
+
concurrent-ruby (~> 1.0)
|
156
|
+
rack (> 1, < 3)
|
157
|
+
sprockets-rails (3.2.1)
|
158
|
+
actionpack (>= 4.0)
|
159
|
+
activesupport (>= 4.0)
|
160
|
+
sprockets (>= 3.0.0)
|
161
|
+
thor (1.0.1)
|
162
|
+
thread_safe (0.3.6)
|
163
|
+
timers (4.3.0)
|
164
|
+
tzinfo (1.2.6)
|
165
|
+
thread_safe (~> 0.1)
|
166
|
+
websocket-driver (0.7.1)
|
167
|
+
websocket-extensions (>= 0.1.0)
|
168
|
+
websocket-extensions (0.1.4)
|
169
|
+
zeitwerk (2.2.2)
|
170
|
+
|
171
|
+
PLATFORMS
|
172
|
+
ruby
|
173
|
+
|
174
|
+
DEPENDENCIES
|
175
|
+
quiq!
|
176
|
+
rails
|
177
|
+
rake (~> 12.0)
|
178
|
+
rspec (~> 3.0)
|
179
|
+
|
180
|
+
BUNDLED WITH
|
181
|
+
2.1.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Salim Semaoune
|
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,46 @@
|
|
1
|
+
# Quiq
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/quiq`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'quiq'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install quiq
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sailor/quiq.
|
36
|
+
|
37
|
+
## TODO
|
38
|
+
|
39
|
+
- [ ] Graceful shutdown
|
40
|
+
- [ ] Add a customizable logger
|
41
|
+
- [ ] Implement a DLQ
|
42
|
+
- [ ] Support job scheduled in the future
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "quiq"
|
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(__FILE__)
|
data/bin/quiq
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/quiq'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = 'Usage: quiq [options]'
|
10
|
+
|
11
|
+
opts.on('-p', '--path [PATH|DIR]", "Location of the workers to require') do |path|
|
12
|
+
options[:path] = path
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on('-q', '--queues [NAMES]", "Comma-separated list of queues to fetch jobs from') do |queues|
|
16
|
+
options[:queues] = queues.split(',')
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on '-v', '--version', 'Output version and exit' do |arg|
|
20
|
+
puts "Quiq #{Quiq::VERSION}"
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
25
|
+
puts opts
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
end.parse!
|
29
|
+
|
30
|
+
begin
|
31
|
+
Quiq.run(options)
|
32
|
+
rescue
|
33
|
+
warn $!.message
|
34
|
+
warn $!.backtrace.join("\n")
|
35
|
+
exit 1
|
36
|
+
end
|
data/bin/setup
ADDED
data/lib/quiq.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'quiq/version'
|
4
|
+
require_relative 'quiq/config'
|
5
|
+
require_relative 'quiq/server'
|
6
|
+
require_relative 'quiq/client'
|
7
|
+
require 'async/redis'
|
8
|
+
|
9
|
+
module Quiq
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
self.configuration ||= Config.instance
|
16
|
+
yield(configuration) if block_given?
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.redis
|
20
|
+
configuration.redis
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.run(options)
|
24
|
+
configure if configuration.nil?
|
25
|
+
configuration.queues = options[:queues] || ['default']
|
26
|
+
|
27
|
+
# Lookup for workers in the given path or the current directory
|
28
|
+
path = options[:path] || Dir.pwd
|
29
|
+
if File.directory?(path)
|
30
|
+
Dir.glob(File.join(path, '*.rb')).each { |file| require file }
|
31
|
+
else
|
32
|
+
require path
|
33
|
+
end
|
34
|
+
|
35
|
+
Server.instance.run
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.queues
|
39
|
+
configuration.queues
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.current_task
|
43
|
+
Async::Task.current
|
44
|
+
end
|
45
|
+
end
|
data/lib/quiq/client.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Quiq
|
7
|
+
class Client
|
8
|
+
def push(job)
|
9
|
+
serialized = JSON.dump(job.serialize)
|
10
|
+
Async do
|
11
|
+
Quiq.redis.lpush("queue:#{job.queue_name}", serialized)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.push(job)
|
16
|
+
new.push(job)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/quiq/config.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Quiq
|
7
|
+
class Config
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_accessor :queues
|
11
|
+
|
12
|
+
# Return a connection to the local
|
13
|
+
# Redis instance if not configured
|
14
|
+
def redis
|
15
|
+
@redis ||= begin
|
16
|
+
endpoint = Async::Redis.local_endpoint
|
17
|
+
Async::Redis::Client.new(endpoint)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Only accepts a redis connection uri for now
|
22
|
+
# Note the client used is far from being production ready
|
23
|
+
def redis=(server)
|
24
|
+
uri = URI(server)
|
25
|
+
endpoint = Async::IO::Endpoint.tcp(uri.host, uri.port)
|
26
|
+
@redis = Async::Redis::Client.new(endpoint)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|