lowkiq 1.1.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +52 -1
- data/assets/app.js +1 -1
- data/lib/lowkiq/queue/fetch.rb +2 -2
- data/lib/lowkiq/queue/queue.rb +3 -3
- data/lib/lowkiq/shard_handler.rb +2 -1
- data/lib/lowkiq/version.rb +1 -1
- data/lib/lowkiq/worker.rb +14 -9
- data/lib/lowkiq.rb +16 -3
- data/lowkiq.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97231d250b03b74533a83cc66b69aafcab6422a55b83ad4a479d4898c00a2b9b
|
4
|
+
data.tar.gz: 6e29b0b370b9a201d10b3398fd1ed24a87efed091183a02cb29fea68625cf8fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4275cf8a1235c9c5f527b40b011edaea72bebda8493128a8029c35c5cd166288ffb01187e39d6a301b132d27b3cd6d32f7b9f9cfec9d6fa0e3edfe943eaa0da2
|
7
|
+
data.tar.gz: 46b65d96ffbc183fa47e85b487f88fe0d9aee256eb379be9fe20fcdc54c0239dcd4fecc2873c14a460024cb3f764c4a1797805b77c7b8d2f1078a40f14db404c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lowkiq (1.1
|
4
|
+
lowkiq (1.2.1)
|
5
5
|
connection_pool (~> 2.2, >= 2.2.2)
|
6
6
|
rack (>= 1.5.0)
|
7
7
|
redis (>= 4.0.1, < 5)
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
byebug (11.1.3)
|
13
13
|
coderay (1.1.3)
|
14
|
-
connection_pool (2.2.
|
14
|
+
connection_pool (2.2.5)
|
15
15
|
diff-lcs (1.3)
|
16
16
|
method_source (1.0.0)
|
17
17
|
pry (0.13.1)
|
@@ -24,7 +24,7 @@ GEM
|
|
24
24
|
rack-test (1.1.0)
|
25
25
|
rack (>= 1.0, < 3)
|
26
26
|
rake (12.3.3)
|
27
|
-
redis (4.
|
27
|
+
redis (4.7.1)
|
28
28
|
rspec (3.9.0)
|
29
29
|
rspec-core (~> 3.9.0)
|
30
30
|
rspec-expectations (~> 3.9.0)
|
@@ -43,7 +43,7 @@ PLATFORMS
|
|
43
43
|
ruby
|
44
44
|
|
45
45
|
DEPENDENCIES
|
46
|
-
bundler (~> 2.1
|
46
|
+
bundler (~> 2.1)
|
47
47
|
lowkiq!
|
48
48
|
pry-byebug (~> 3.9.0)
|
49
49
|
rack-test (~> 1.1)
|
@@ -52,4 +52,4 @@ DEPENDENCIES
|
|
52
52
|
rspec-mocks (~> 3.8)
|
53
53
|
|
54
54
|
BUNDLED WITH
|
55
|
-
2.
|
55
|
+
2.2.22
|
data/README.md
CHANGED
@@ -28,6 +28,8 @@ Ordered background jobs processing
|
|
28
28
|
* [Recommendations on configuration](#recommendations-on-configuration)
|
29
29
|
+ [`SomeWorker.shards_count`](#someworkershards_count)
|
30
30
|
+ [`SomeWorker.max_retry_count`](#someworkermax_retry_count)
|
31
|
+
* [Changing of worker's shards amount](#changing-of-workers-shards-amount)
|
32
|
+
* [Extended error info](#extended-error-info)
|
31
33
|
|
32
34
|
## Rationale
|
33
35
|
|
@@ -204,6 +206,12 @@ module ATestWorker
|
|
204
206
|
10 * (count + 1) # (i.e. 10, 20, 30, 40, 50)
|
205
207
|
end
|
206
208
|
|
209
|
+
def self.retries_exhausted(batch)
|
210
|
+
batch.each do |job|
|
211
|
+
Rails.logger.info "retries exhausted for #{name} with error #{job[:error]}"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
207
215
|
def self.perform(payloads_by_id)
|
208
216
|
# payloads_by_id is a hash map
|
209
217
|
payloads_by_id.each do |id, payloads|
|
@@ -285,7 +293,8 @@ Options and their default values are:
|
|
285
293
|
+ `Lowkiq.redis = ->() { Redis.new url: ENV.fetch('REDIS_URL') }` - redis connection options
|
286
294
|
+ `Lowkiq.client_pool_size = 5` - redis pool size for queueing jobs
|
287
295
|
+ `Lowkiq.pool_timeout = 5` - client and server redis pool timeout
|
288
|
-
+ `Lowkiq.server_middlewares = []` - a middleware list, used
|
296
|
+
+ `Lowkiq.server_middlewares = []` - a middleware list, used when job is processed
|
297
|
+
+ `Lowkiq.client_middlewares = []` - a middleware list, used when job is enqueued
|
289
298
|
+ `Lowkiq.on_server_init = ->() {}` - a lambda is being executed when server inits
|
290
299
|
+ `Lowkiq.build_scheduler = ->() { Lowkiq.build_lag_scheduler }` is a scheduler
|
291
300
|
+ `Lowkiq.build_splitter = ->() { Lowkiq.build_default_splitter }` is a splitter
|
@@ -293,6 +302,10 @@ Options and their default values are:
|
|
293
302
|
+ `Lowkiq.dump_payload = Marshal.method :dump`
|
294
303
|
+ `Lowkiq.load_payload = Marshal.method :load`
|
295
304
|
|
305
|
+
+ `Lowkiq.format_error = -> (error) { error.message }` can be used to add error backtrace. Please see [Extended error info](#extended-error-info)
|
306
|
+
+ `Lowkiq.dump_error = -> (msg) { msg }` can be used to implement a custom compression logic for errors. Recommended when using `Lowkiq.format_error`.
|
307
|
+
+ `Lowkiq.load_error = -> (msg) { msg }` can be used to implement a custom decompression logic for errors.
|
308
|
+
|
296
309
|
```ruby
|
297
310
|
$logger = Logger.new(STDOUT)
|
298
311
|
|
@@ -310,6 +323,13 @@ Lowkiq.server_middlewares << -> (worker, batch, &block) do
|
|
310
323
|
raise e
|
311
324
|
end
|
312
325
|
end
|
326
|
+
|
327
|
+
Lowkiq.client_middlewares << -> (worker, batch, &block) do
|
328
|
+
$logger.info "Enqueueing job for #{worker} #{batch}"
|
329
|
+
block.call
|
330
|
+
$logger.info "Enqueued job for #{worker} #{batch}"
|
331
|
+
end
|
332
|
+
|
313
333
|
```
|
314
334
|
|
315
335
|
## Performance
|
@@ -486,6 +506,17 @@ Lowkiq.on_server_init = ->() do
|
|
486
506
|
end
|
487
507
|
```
|
488
508
|
|
509
|
+
Note: In Rails 7, the worker files wouldn't be loaded by default in the initializers since they are managed by the `main` autoloader. To solve this, we can wrap setting the workers around the `to_prepare` configuration.
|
510
|
+
|
511
|
+
```ruby
|
512
|
+
Rails.application.config.to_prepare do
|
513
|
+
Lowkiq.workers = [
|
514
|
+
ATestWorker,
|
515
|
+
OtherCoolWorker
|
516
|
+
]
|
517
|
+
end
|
518
|
+
```
|
519
|
+
|
489
520
|
Execution: `bundle exec lowkiq -r ./config/environment.rb`
|
490
521
|
|
491
522
|
|
@@ -666,3 +697,23 @@ module ATestMigrationWorker
|
|
666
697
|
end
|
667
698
|
end
|
668
699
|
```
|
700
|
+
|
701
|
+
## Extended error info
|
702
|
+
For failed jobs, lowkiq only stores `error.message` by default. This can be configured by using `Lowkiq.format_error` setting.
|
703
|
+
`Lowkiq.dump` and `Lowkiq.load_error` can be used to compress and decompress the error messages respectively.
|
704
|
+
Example:
|
705
|
+
```ruby
|
706
|
+
Lowkiq.format_error = -> (error) { error.full_message(highlight: false) }
|
707
|
+
|
708
|
+
Lowkiq.dump_error = Proc.new do |msg|
|
709
|
+
compressed = Zlib::Deflate.deflate(msg.to_s)
|
710
|
+
Base64.encode64(compressed)
|
711
|
+
end
|
712
|
+
|
713
|
+
Lowkiq.load_error = Proc.new do |input|
|
714
|
+
decoded = Base64.decode64(input)
|
715
|
+
Zlib::Inflate.inflate(decoded)
|
716
|
+
rescue
|
717
|
+
input
|
718
|
+
end
|
719
|
+
```
|