quiq 0.2.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/.github/workflows/ruby.yml +20 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +174 -0
- data/LICENSE.txt +21 -0
- data/README.md +163 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/quiq +42 -0
- data/bin/quiqload +46 -0
- data/bin/setup +8 -0
- data/lib/quiq.rb +49 -0
- data/lib/quiq/client.rb +22 -0
- data/lib/quiq/config.rb +35 -0
- data/lib/quiq/job.rb +51 -0
- data/lib/quiq/queue.rb +65 -0
- data/lib/quiq/redis.rb +17 -0
- data/lib/quiq/scheduler.rb +51 -0
- data/lib/quiq/server.rb +28 -0
- data/lib/quiq/version.rb +5 -0
- data/lib/quiq/worker.rb +28 -0
- data/quiq.gemspec +30 -0
- data/testapp/Gemfile +15 -0
- data/testapp/Gemfile.lock +190 -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/http_job.rb +14 -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 +29 -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 +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f90fff6709ecb676daed0452eb08a59829a574b6a0d7b5819c9efe210a022453
|
4
|
+
data.tar.gz: 8391e3cc14ff6dc6ee97370f114bc314655714c983f04176cae17b1c251bbfb6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87eceeb1209250a2932c1ef82c766c0fd9e333ede059ffffaebad9dca2e503d9ff9ff550f3a2424dd2db97bcbd090bf81cdede5d7ab589439bab3e6bc1f70f65
|
7
|
+
data.tar.gz: d3cc1741271ac08ef7abdc4e77262b411f0ae712c6415a62153227855094ff8e23ad35644496149cb6c914064395c5fe9dc7f1cfbb9afb2e74a5de468db97f5a
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby 7.6
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.7.x
|
16
|
+
- name: Build and test with Rake
|
17
|
+
run: |
|
18
|
+
gem install bundler
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
bundle exec rake spec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
quiq (0.2.0)
|
5
|
+
async-redis (~> 0.4.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (6.0.2.1)
|
11
|
+
actionpack (= 6.0.2.1)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (>= 0.6.1)
|
14
|
+
actionmailbox (6.0.2.1)
|
15
|
+
actionpack (= 6.0.2.1)
|
16
|
+
activejob (= 6.0.2.1)
|
17
|
+
activerecord (= 6.0.2.1)
|
18
|
+
activestorage (= 6.0.2.1)
|
19
|
+
activesupport (= 6.0.2.1)
|
20
|
+
mail (>= 2.7.1)
|
21
|
+
actionmailer (6.0.2.1)
|
22
|
+
actionpack (= 6.0.2.1)
|
23
|
+
actionview (= 6.0.2.1)
|
24
|
+
activejob (= 6.0.2.1)
|
25
|
+
mail (~> 2.5, >= 2.5.4)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
actionpack (6.0.2.1)
|
28
|
+
actionview (= 6.0.2.1)
|
29
|
+
activesupport (= 6.0.2.1)
|
30
|
+
rack (~> 2.0, >= 2.0.8)
|
31
|
+
rack-test (>= 0.6.3)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
34
|
+
actiontext (6.0.2.1)
|
35
|
+
actionpack (= 6.0.2.1)
|
36
|
+
activerecord (= 6.0.2.1)
|
37
|
+
activestorage (= 6.0.2.1)
|
38
|
+
activesupport (= 6.0.2.1)
|
39
|
+
nokogiri (>= 1.8.5)
|
40
|
+
actionview (6.0.2.1)
|
41
|
+
activesupport (= 6.0.2.1)
|
42
|
+
builder (~> 3.1)
|
43
|
+
erubi (~> 1.4)
|
44
|
+
rails-dom-testing (~> 2.0)
|
45
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
46
|
+
activejob (6.0.2.1)
|
47
|
+
activesupport (= 6.0.2.1)
|
48
|
+
globalid (>= 0.3.6)
|
49
|
+
activemodel (6.0.2.1)
|
50
|
+
activesupport (= 6.0.2.1)
|
51
|
+
activerecord (6.0.2.1)
|
52
|
+
activemodel (= 6.0.2.1)
|
53
|
+
activesupport (= 6.0.2.1)
|
54
|
+
activestorage (6.0.2.1)
|
55
|
+
actionpack (= 6.0.2.1)
|
56
|
+
activejob (= 6.0.2.1)
|
57
|
+
activerecord (= 6.0.2.1)
|
58
|
+
marcel (~> 0.3.1)
|
59
|
+
activesupport (6.0.2.1)
|
60
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
61
|
+
i18n (>= 0.7, < 2)
|
62
|
+
minitest (~> 5.1)
|
63
|
+
tzinfo (~> 1.1)
|
64
|
+
zeitwerk (~> 2.2)
|
65
|
+
async (1.24.2)
|
66
|
+
console (~> 1.0)
|
67
|
+
nio4r (~> 2.3)
|
68
|
+
timers (~> 4.1)
|
69
|
+
async-io (1.27.3)
|
70
|
+
async (~> 1.14)
|
71
|
+
async-pool (0.2.0)
|
72
|
+
async (~> 1.8)
|
73
|
+
async-redis (0.4.3)
|
74
|
+
async (~> 1.8)
|
75
|
+
async-io (~> 1.10)
|
76
|
+
async-pool (~> 0.2)
|
77
|
+
protocol-redis (~> 0.4.0)
|
78
|
+
builder (3.2.4)
|
79
|
+
concurrent-ruby (1.1.5)
|
80
|
+
console (1.8.1)
|
81
|
+
crass (1.0.6)
|
82
|
+
diff-lcs (1.3)
|
83
|
+
erubi (1.9.0)
|
84
|
+
globalid (0.4.2)
|
85
|
+
activesupport (>= 4.2.0)
|
86
|
+
i18n (1.8.2)
|
87
|
+
concurrent-ruby (~> 1.0)
|
88
|
+
loofah (2.4.0)
|
89
|
+
crass (~> 1.0.2)
|
90
|
+
nokogiri (>= 1.5.9)
|
91
|
+
mail (2.7.1)
|
92
|
+
mini_mime (>= 0.1.1)
|
93
|
+
marcel (0.3.3)
|
94
|
+
mimemagic (~> 0.3.2)
|
95
|
+
method_source (0.9.2)
|
96
|
+
mimemagic (0.3.3)
|
97
|
+
mini_mime (1.0.2)
|
98
|
+
mini_portile2 (2.4.0)
|
99
|
+
minitest (5.14.0)
|
100
|
+
nio4r (2.5.2)
|
101
|
+
nokogiri (1.10.7)
|
102
|
+
mini_portile2 (~> 2.4.0)
|
103
|
+
protocol-redis (0.4.2)
|
104
|
+
rack (2.1.1)
|
105
|
+
rack-test (1.1.0)
|
106
|
+
rack (>= 1.0, < 3)
|
107
|
+
rails (6.0.2.1)
|
108
|
+
actioncable (= 6.0.2.1)
|
109
|
+
actionmailbox (= 6.0.2.1)
|
110
|
+
actionmailer (= 6.0.2.1)
|
111
|
+
actionpack (= 6.0.2.1)
|
112
|
+
actiontext (= 6.0.2.1)
|
113
|
+
actionview (= 6.0.2.1)
|
114
|
+
activejob (= 6.0.2.1)
|
115
|
+
activemodel (= 6.0.2.1)
|
116
|
+
activerecord (= 6.0.2.1)
|
117
|
+
activestorage (= 6.0.2.1)
|
118
|
+
activesupport (= 6.0.2.1)
|
119
|
+
bundler (>= 1.3.0)
|
120
|
+
railties (= 6.0.2.1)
|
121
|
+
sprockets-rails (>= 2.0.0)
|
122
|
+
rails-dom-testing (2.0.3)
|
123
|
+
activesupport (>= 4.2.0)
|
124
|
+
nokogiri (>= 1.6)
|
125
|
+
rails-html-sanitizer (1.3.0)
|
126
|
+
loofah (~> 2.3)
|
127
|
+
railties (6.0.2.1)
|
128
|
+
actionpack (= 6.0.2.1)
|
129
|
+
activesupport (= 6.0.2.1)
|
130
|
+
method_source
|
131
|
+
rake (>= 0.8.7)
|
132
|
+
thor (>= 0.20.3, < 2.0)
|
133
|
+
rake (12.3.3)
|
134
|
+
rspec (3.9.0)
|
135
|
+
rspec-core (~> 3.9.0)
|
136
|
+
rspec-expectations (~> 3.9.0)
|
137
|
+
rspec-mocks (~> 3.9.0)
|
138
|
+
rspec-core (3.9.1)
|
139
|
+
rspec-support (~> 3.9.1)
|
140
|
+
rspec-expectations (3.9.0)
|
141
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
142
|
+
rspec-support (~> 3.9.0)
|
143
|
+
rspec-mocks (3.9.1)
|
144
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
145
|
+
rspec-support (~> 3.9.0)
|
146
|
+
rspec-support (3.9.2)
|
147
|
+
sprockets (4.0.0)
|
148
|
+
concurrent-ruby (~> 1.0)
|
149
|
+
rack (> 1, < 3)
|
150
|
+
sprockets-rails (3.2.1)
|
151
|
+
actionpack (>= 4.0)
|
152
|
+
activesupport (>= 4.0)
|
153
|
+
sprockets (>= 3.0.0)
|
154
|
+
thor (1.0.1)
|
155
|
+
thread_safe (0.3.6)
|
156
|
+
timers (4.3.0)
|
157
|
+
tzinfo (1.2.6)
|
158
|
+
thread_safe (~> 0.1)
|
159
|
+
websocket-driver (0.7.1)
|
160
|
+
websocket-extensions (>= 0.1.0)
|
161
|
+
websocket-extensions (0.1.4)
|
162
|
+
zeitwerk (2.2.2)
|
163
|
+
|
164
|
+
PLATFORMS
|
165
|
+
ruby
|
166
|
+
|
167
|
+
DEPENDENCIES
|
168
|
+
quiq!
|
169
|
+
rails
|
170
|
+
rake (~> 12.0)
|
171
|
+
rspec (~> 3.0)
|
172
|
+
|
173
|
+
BUNDLED WITH
|
174
|
+
2.1.4
|
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,163 @@
|
|
1
|
+
# Quiq
|
2
|
+
|
3
|
+
Quiq is a distributed task queue backed by Redis to process jobs in background.
|
4
|
+
|
5
|
+
It relies on asynchronous IOs to process multiple jobs simultaneously. The event loop is provided by the [Async](https://github.com/socketry/async) library and many other gems of the [Socketry](https://github.com/socketry) family.
|
6
|
+
|
7
|
+
It can be used without Rails, but will play nicely with [ActiveJob](https://guides.rubyonrails.org/active_job_basics.html) even though it's not supported officialy (more details [here](#activejob-support)).
|
8
|
+
|
9
|
+
The library is in a very early stage, it is **not suitable for production** yet.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'quiq'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle install
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install quiq
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To launch the workers, you can use the `quiq` command.
|
30
|
+
|
31
|
+
```
|
32
|
+
Usage: quiq [options]
|
33
|
+
-p, --path PATH Location of the workers to load
|
34
|
+
-q, --queues NAMES Comma-separated list of queues to poll
|
35
|
+
-l, --log-level LEVEL The logging level
|
36
|
+
-v, --version Output version and exit
|
37
|
+
-h, --help Show this message
|
38
|
+
```
|
39
|
+
|
40
|
+
This is how to use it with a Rails application using [ActiveJob](https://guides.rubyonrails.org/active_job_basics.html)
|
41
|
+
|
42
|
+
$ bundle exec quiq -p ./config/environment.rb -q critical,medium,low -l WARN
|
43
|
+
|
44
|
+
## Configuration
|
45
|
+
|
46
|
+
Here is an example of a configuration within a Rails application:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Quiq.configure do |config|
|
50
|
+
config.redis = 'redis://localhost:6379'
|
51
|
+
config.logger = Rails.logger
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
### ActiveJob support
|
56
|
+
|
57
|
+
As there is no official support for Quiq in ActiveJob, you must monkey patch it to use it as you would do with any other background jobs system. You can find a complete example here: [testapp/config/initializers/quiq.rb](https://github.com/sailor/quiq/blob/master/testapp/config/initializers/quiq.rb)
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
module ActiveJob
|
61
|
+
module QueueAdapters
|
62
|
+
class QuiqAdapter
|
63
|
+
def enqueue(job)
|
64
|
+
Quiq::Client.push(job)
|
65
|
+
end
|
66
|
+
|
67
|
+
def enqueue_at(job, timestamp)
|
68
|
+
Quiq::Client.push(job, scheduled_at: timestamp)
|
69
|
+
end
|
70
|
+
|
71
|
+
class JobWrapper
|
72
|
+
class << self
|
73
|
+
def perform(job_data)
|
74
|
+
Base.execute job_data
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
## Jobs
|
84
|
+
|
85
|
+
As it is using the [Async](https://github.com/socketry/async) gem, we can use the many features provided by this library.
|
86
|
+
|
87
|
+
You can access the underlying `Async::Task` by using `Quiq.current_task`.
|
88
|
+
|
89
|
+
A very dumb example:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
class TestJob < ApplicationJob
|
93
|
+
def perform(data, wait)
|
94
|
+
puts "Receiving new job: #{data}"
|
95
|
+
Quiq.current_task.sleep wait # Non blocking call
|
96
|
+
puts "Time to wake up after #{wait} seconds"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
More interesting use case. If you combine `quiq` with the [async-http](https://github.com/socketry/async-http) gem, you'll be able to make asynchronous HTTP calls:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
require 'uri'
|
105
|
+
require 'async/http/internet'
|
106
|
+
|
107
|
+
class HttpJob < ApplicationJob
|
108
|
+
def perform(url)
|
109
|
+
uri = URI(url)
|
110
|
+
|
111
|
+
client = Async::HTTP::Internet.new
|
112
|
+
response = client.get(url)
|
113
|
+
Quiq.logger.info response.read
|
114
|
+
end
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
### Scheduled jobs
|
119
|
+
|
120
|
+
Since Quiq supports ActiveJob interface you can use the same approach to schedule jobs for the future.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
TestJob.set(wait: 5.seconds).perform_later(1, 2)
|
124
|
+
```
|
125
|
+
|
126
|
+
## Development
|
127
|
+
|
128
|
+
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.
|
129
|
+
|
130
|
+
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).
|
131
|
+
|
132
|
+
## Benchmarks
|
133
|
+
|
134
|
+
To benchmark the system you can use the `quiqload` binary. To launch it, execute:
|
135
|
+
|
136
|
+
$ time bin/quiqload -n 10_000 -w 1
|
137
|
+
|
138
|
+
```
|
139
|
+
Usage: quiqload [options]
|
140
|
+
-n, --number JOBS Number of jobs to enqueue
|
141
|
+
-w, --wait DURATION Idle time within each job (in seconds)
|
142
|
+
-h, --help Show this message
|
143
|
+
```
|
144
|
+
|
145
|
+
## Todo
|
146
|
+
|
147
|
+
- [ ] Graceful shutdown
|
148
|
+
- [x] Customizable logger
|
149
|
+
- [x] Dead-letter queue
|
150
|
+
- [x] Scheduler
|
151
|
+
- [ ] Specs
|
152
|
+
- [ ] Retry system
|
153
|
+
- [ ] Batches support
|
154
|
+
- [x] Load testing script
|
155
|
+
- [ ] Admin user interface
|
156
|
+
|
157
|
+
## Contributing
|
158
|
+
|
159
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sailor/quiq.
|
160
|
+
|
161
|
+
## License
|
162
|
+
|
163
|
+
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__)
|