insque 0.5.2 → 0.6.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 +4 -4
- data/README.md +12 -19
- data/insque.gemspec +1 -1
- data/lib/insque/version.rb +1 -1
- data/lib/insque.rb +17 -5
- data/lib/tasks/insque.rake +3 -0
- metadata +6 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6bc4d6a0e64d20aa174ad1edb4e7b0800db567f
|
4
|
+
data.tar.gz: 0c055a801704a918e7f5c54de6c13a6d2a4aa855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc420d9a911864023ec1f2a99fbba467228f349a3363be2bda5edf254b24f10dca161a251f600835c95ff9897de9ea51aa8949c102fde3dc756e53c187b46689
|
7
|
+
data.tar.gz: 92a6ae35dd54be1e6db13a7dcb47b9a5694be04817752ef0479c05364a5ddd182047174e8ea571028db14703d0cc3934e268f5db9a6b256feb30e86344812ee5
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Instant queue. Background processing and message driven communication tool. Fast
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Add this line to your application's Gemfile
|
7
|
+
Add this line to your application's `Gemfile`:
|
8
8
|
|
9
9
|
gem 'insque'
|
10
10
|
|
@@ -29,12 +29,19 @@ To broadcast message use:
|
|
29
29
|
```ruby
|
30
30
|
Insque.broadcast :message_name, {:params => {:some => :params}}
|
31
31
|
```
|
32
|
-
There is an easy way to use insque as background jobs processing. You can use `send_later` method to call any method of your rails models in background
|
33
|
-
. You still need listener running to make this work.
|
32
|
+
There is an easy way to use insque as background jobs processing. You can use `send_later` method to call any method of your rails models in background:
|
34
33
|
```ruby
|
35
34
|
@model = MyModel.first
|
36
35
|
@model.send_later :mymethod, 'some', 'params'
|
37
36
|
```
|
37
|
+
You'll need a special slow listener running to make this work.
|
38
|
+
```ruby
|
39
|
+
Insque.slow_listen
|
40
|
+
```
|
41
|
+
there is a matching slow janitor as well:
|
42
|
+
```ruby
|
43
|
+
Insque.slow_janitor
|
44
|
+
```
|
38
45
|
|
39
46
|
### Recieving
|
40
47
|
|
@@ -61,28 +68,14 @@ To start recieving messages you need to:
|
|
61
68
|
|
62
69
|
or just run `bundle exec rake insque:janitor` from your console.
|
63
70
|
|
64
|
-
###
|
65
|
-
|
66
|
-
Insque can be used for processing slow tasks in background. Slow tasks created with send_later method call of any ActiveRecord model:
|
67
|
-
```ruby
|
68
|
-
User.send_later :some_slow_method
|
69
|
-
```
|
70
|
-
and processed by a special slow listener:
|
71
|
-
```ruby
|
72
|
-
Insque.slow_listen
|
73
|
-
```
|
74
|
-
there is matching slow janitor as well:
|
75
|
-
```ruby
|
76
|
-
Insque.slow_janitor
|
77
|
-
```
|
78
|
-
### insque:run
|
71
|
+
### Run All At Once
|
79
72
|
|
80
73
|
There is a simple way to run all insque workers, both regular and slow in a single multi-threaded process:
|
81
74
|
```ruby
|
82
75
|
bundle exec rake insque:run
|
83
76
|
```
|
84
77
|
|
85
|
-
###
|
78
|
+
### Redis Cluster Support
|
86
79
|
|
87
80
|
To make insque run on Redis Cluster add this line to your application's `Gemfile`:
|
88
81
|
|
data/insque.gemspec
CHANGED
data/lib/insque/version.rb
CHANGED
data/lib/insque.rb
CHANGED
@@ -3,6 +3,16 @@ require "redis"
|
|
3
3
|
require "insque/railtie" if defined?(Rails)
|
4
4
|
|
5
5
|
module Insque
|
6
|
+
DEFAULT_INBOX_TTL = 10800 # seconds
|
7
|
+
|
8
|
+
def self.inbox_ttl= val
|
9
|
+
@inbox_ttl = val
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.inbox_ttl
|
13
|
+
@inbox_ttl || DEFAULT_INBOX_TTL
|
14
|
+
end
|
15
|
+
|
6
16
|
def self.debug= debug
|
7
17
|
@debug = debug
|
8
18
|
end
|
@@ -31,6 +41,7 @@ module Insque
|
|
31
41
|
def self.sender= sender
|
32
42
|
@sender = sender
|
33
43
|
@inbox = "{insque}inbox_#{sender}"
|
44
|
+
@inbox_pointer = "{insque}inbox_pointer_#{sender}"
|
34
45
|
@processing = "{insque}processing_#{sender}"
|
35
46
|
@slow_inbox = "{insque}slow_inbox_#{sender}"
|
36
47
|
@slow_processing = "{insque}slow_processing_#{sender}"
|
@@ -41,7 +52,7 @@ module Insque
|
|
41
52
|
keys = []
|
42
53
|
case recipient
|
43
54
|
when :any
|
44
|
-
keys = @redis.
|
55
|
+
keys = @redis.mget *@redis.keys('{insque}inbox_pointer_*')
|
45
56
|
when :self
|
46
57
|
keys = [@inbox]
|
47
58
|
when :slow
|
@@ -58,8 +69,7 @@ module Insque
|
|
58
69
|
|
59
70
|
def self.listen worker_name='', redis=nil
|
60
71
|
redis ||= create_redis_connection
|
61
|
-
redis
|
62
|
-
do_listen @inbox, @processing, redis, worker_name
|
72
|
+
do_listen @inbox, @processing, redis, worker_name, @inbox_pointer
|
63
73
|
end
|
64
74
|
|
65
75
|
def self.slow_listen worker_name='', redis=nil
|
@@ -75,14 +85,16 @@ module Insque
|
|
75
85
|
end
|
76
86
|
|
77
87
|
private
|
78
|
-
def self.do_listen inbox, processing, redis, worker_name
|
88
|
+
def self.do_listen inbox, processing, redis, worker_name, pointer=nil
|
79
89
|
log "#{worker_name} START LISTENING #{inbox}"
|
80
90
|
loop do
|
91
|
+
redis.setex(pointer, inbox_ttl, inbox) if pointer
|
81
92
|
message = redis.brpoplpush(inbox, processing, 0)
|
82
93
|
log "#{worker_name} RECEIVING: #{message}" if @debug
|
83
94
|
begin
|
84
95
|
parsed_message = JSON.parse message
|
85
|
-
send(parsed_message['message'], parsed_message)
|
96
|
+
send(parsed_message['message'], parsed_message)
|
97
|
+
rescue NoMethodError
|
86
98
|
rescue => e
|
87
99
|
log "#{worker_name} ========== BROKEN_MESSAGE: #{message} =========="
|
88
100
|
log e.inspect
|
data/lib/tasks/insque.rake
CHANGED
@@ -2,6 +2,7 @@ namespace :insque do
|
|
2
2
|
desc 'Starts insque listener and janitor'
|
3
3
|
task :run => :environment do
|
4
4
|
trap('TERM') { puts "SIGTERM"; exit 0 }
|
5
|
+
Thread.abort_on_exception=true
|
5
6
|
threads = []
|
6
7
|
threads << Thread.new() { Insque.listen }
|
7
8
|
threads << Thread.new() { Insque.janitor }
|
@@ -13,12 +14,14 @@ namespace :insque do
|
|
13
14
|
desc 'Starts insque listener'
|
14
15
|
task :listener => :environment do
|
15
16
|
trap('TERM') { puts "SIGTERM"; exit 0 }
|
17
|
+
Thread.abort_on_exception=true
|
16
18
|
Insque.listen
|
17
19
|
end
|
18
20
|
|
19
21
|
desc 'Starts insque janitor'
|
20
22
|
task :janitor => :environment do
|
21
23
|
trap('TERM') { puts "SIGTERM"; exit 0 }
|
24
|
+
Thread.abort_on_exception=true
|
22
25
|
Insque.janitor
|
23
26
|
end
|
24
27
|
end
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gropher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.2.2
|
19
|
+
version: '2'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.2'
|
30
|
-
- - ">="
|
24
|
+
- - ">"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2
|
26
|
+
version: '2'
|
33
27
|
description: Instant queue. Background processing and message driven communication
|
34
28
|
tool. Faster and simplier alternative to Resque.
|
35
29
|
email:
|