rb-cola 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -3
- data/README.md +88 -2
- data/cola.gemspec +1 -1
- data/lib/cola/queue.rb +3 -0
- data/lib/cola/version.rb +1 -1
- metadata +7 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be38dd0666f61a38c22ff64385ead51795d51e13297e3a010b55ba4a9542afdb
|
4
|
+
data.tar.gz: ddd118952cd6cda2f11f11e2f50d3a035a707e3dd6c4b1ac5478c1b11dff0ec1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 876274c2edd5cba870c289c2b1ca9ea5000b9aa2e715b9accbf61d19d19eed9c782068c82afb5a43e54f6a69bebed7ab4f50591419ab5719b0c7a13e7317f4f2
|
7
|
+
data.tar.gz: d7a03ffbd1fbb3e91ae409ad91c725ab783f738375cea10d817610a81c00f2332de6d70eb3582c5ecf540bb3ae04f3a506e0fdda83551babb3cd315dda87ce4b
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rb-cola (0.0.
|
5
|
-
redis (>= 3.3.5
|
4
|
+
rb-cola (0.0.3)
|
5
|
+
redis (>= 3.3.5)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
byebug (11.0.1)
|
11
|
+
connection_pool (2.3.0)
|
11
12
|
diff-lcs (1.3)
|
12
|
-
redis (
|
13
|
+
redis (5.0.5)
|
14
|
+
redis-client (>= 0.9.0)
|
15
|
+
redis-client (0.11.2)
|
16
|
+
connection_pool
|
13
17
|
rspec (3.9.0)
|
14
18
|
rspec-core (~> 3.9.0)
|
15
19
|
rspec-expectations (~> 3.9.0)
|
data/README.md
CHANGED
@@ -1,6 +1,92 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
<img src="http://cdn2-cloud66-com.s3.amazonaws.com/images/oss-sponsorship.png" width=150/>
|
2
|
+
|
3
|
+
# Cola
|
4
|
+
|
5
|
+
---
|
3
6
|
|
4
7
|
Cola is a simple distributed, transactional queue gem for Ruby backed by Redis. It uses Redis lists to provide its functionality with minimal additions. Cola supports transactions, retries, deadletter queues and timeouts. This gem is based on https://github.com/taganaka/redis-queue
|
5
8
|
|
9
|
+
## Install
|
10
|
+
|
11
|
+
Run
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install rb-cola
|
15
|
+
```
|
16
|
+
|
17
|
+
or add this to your `Gemfile`
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'rb-cola'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Create a queue, push and pop messages to and from the queue:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
q = ::Cola::Queue.new
|
29
|
+
q.push("message")
|
30
|
+
message = q.pop
|
31
|
+
q.commit
|
32
|
+
```
|
33
|
+
|
34
|
+
See the files under `examples` folder for more information.
|
35
|
+
|
36
|
+
### Push
|
37
|
+
|
38
|
+
You can push messages onto the queue using `push` or `<<`:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
queue << message
|
42
|
+
queue.push(message)
|
43
|
+
queue.push(another_message, ttl: 30) # this message will expire in 30 seconds
|
44
|
+
```
|
45
|
+
|
46
|
+
### Pop
|
47
|
+
|
48
|
+
You can pull the messages from the queue with blocking or non-blocking actions. Blocking actions will wait until a message is available to pop. Non-blocking actions will return `nil` is no message is available.
|
49
|
+
|
50
|
+
### Envelope
|
51
|
+
|
52
|
+
Each message is stored in an envelope when put on the queue. `pop` and `process` return the message itself when called. However, you can use `pop_with_envelope` to get the entire envelope.
|
53
|
+
|
54
|
+
Attribute | Description | Default
|
55
|
+
---|---|---
|
56
|
+
message | The message | `nil`
|
57
|
+
timestamp | Message timestamp | Timestamp of the push
|
58
|
+
retries | Number of times the message has been retried | 0
|
59
|
+
last_reason | The reason for the last retry failure | `nil`
|
60
|
+
version | Envelope version | `0`
|
61
|
+
uuid | Unique ID of the message | Automatically generated
|
62
|
+
ttl | Time to live | `0`
|
63
|
+
|
64
|
+
### Retries
|
65
|
+
|
66
|
+
By default, if a pop fails, the message is lost and an exception is raised. This can be changed so Cola retries the message more than once. See `options` for more info. This is most useful when used with the `process` function in case an exception is raised within the process block.
|
67
|
+
|
68
|
+
### Deadletter Queue
|
69
|
+
|
70
|
+
In case of multiple failures, the message can be pushed to a deadletter queue for further manual inspection. This is disabled by default.
|
71
|
+
|
72
|
+
### Message Expiry
|
73
|
+
|
74
|
+
When pushing messages onto the queue, you can assign them a Time to Live (ttl). Messages will expire after their ttl is passed and they are not picked up for processing.
|
75
|
+
|
76
|
+
## Options
|
77
|
+
|
78
|
+
When creating a queue, you can use the following options:
|
79
|
+
|
80
|
+
Option | Description | Default
|
81
|
+
---|---|---
|
82
|
+
redis | Redis instance to use | Using the current redis instance
|
83
|
+
deadletter | Support deadletter queue | `false`
|
84
|
+
queue_name | Set the queue name | Random queue name
|
85
|
+
timeout | Message timeout | `0` (No timeout)
|
86
|
+
retries | Number of retries | `0` (No retries)
|
87
|
+
|
88
|
+
Example:
|
6
89
|
|
90
|
+
```ruby
|
91
|
+
q = ::Cola::Queue.new(timeout: 10, redis: @some_redis_instance)
|
92
|
+
```
|
data/cola.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_runtime_dependency 'redis', '>= 3.3.5'
|
24
|
+
spec.add_runtime_dependency 'redis', '>= 3.3.5'
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.8"
|
data/lib/cola/queue.rb
CHANGED
@@ -24,6 +24,8 @@ module Cola
|
|
24
24
|
@retries = options[:retries] ||= 0
|
25
25
|
end
|
26
26
|
|
27
|
+
# returns the count of the items on the queue.
|
28
|
+
# note that this returns the total number which might include expired messages
|
27
29
|
def len
|
28
30
|
@redis.llen @queue_name
|
29
31
|
end
|
@@ -68,6 +70,7 @@ module Cola
|
|
68
70
|
end
|
69
71
|
|
70
72
|
@redis.lpush(@queue_name, wrapped.to_json)
|
73
|
+
return wrapped
|
71
74
|
end
|
72
75
|
|
73
76
|
def pop(non_block = false, timeout: @timeout)
|
data/lib/cola/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-cola
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Khash Sajadi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.3.5
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '5'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,9 +24,6 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 3.3.5
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '5'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: bundler
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +66,7 @@ dependencies:
|
|
72
66
|
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
68
|
version: '11.0'
|
75
|
-
description:
|
69
|
+
description:
|
76
70
|
email:
|
77
71
|
- khash@cloud66.com
|
78
72
|
executables:
|
@@ -102,7 +96,7 @@ files:
|
|
102
96
|
homepage: https://github.com/cloud66-oss/rb-cola
|
103
97
|
licenses: []
|
104
98
|
metadata: {}
|
105
|
-
post_install_message:
|
99
|
+
post_install_message:
|
106
100
|
rdoc_options: []
|
107
101
|
require_paths:
|
108
102
|
- lib
|
@@ -117,9 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
111
|
- !ruby/object:Gem::Version
|
118
112
|
version: '0'
|
119
113
|
requirements: []
|
120
|
-
|
121
|
-
|
122
|
-
signing_key:
|
114
|
+
rubygems_version: 3.3.24
|
115
|
+
signing_key:
|
123
116
|
specification_version: 4
|
124
117
|
summary: A distributed queue based on Redis
|
125
118
|
test_files: []
|