upperkut 1.0.0.rc → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/Dockerfile +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -17
- data/Makefile +4 -0
- data/docker-compose.yml +18 -0
- data/lib/upperkut.rb +1 -1
- data/lib/upperkut/item.rb +2 -30
- data/lib/upperkut/processor.rb +1 -0
- data/lib/upperkut/strategies/buffered_queue.rb +3 -3
- data/lib/upperkut/strategies/priority_queue.rb +1 -1
- data/lib/upperkut/strategies/scheduled_queue.rb +16 -10
- data/lib/upperkut/util.rb +20 -4
- data/lib/upperkut/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edf84d6612f4c9577cfe53e578e16983e3936863379c7d4c1041e9c92637f867
|
4
|
+
data.tar.gz: ce0ad624fe65306bb8fe818b8018acfe519326cbb744ef9af0519b26fd25faed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f6325ce299c9af7c50c9891acee2e771131d002c27b27fe6e245227d73ce177afd65451116daf7a5af5fc5e546b8b52b796ea82abf05bb8eae88966a16efa46
|
7
|
+
data.tar.gz: 482e700d0cd87b0f6de61c528ef42d7c57bbc96afce8d5d6b1593420a4fa9308f6be668cc8c183fc98b9347a6a33800be9df5bebc3da98ac7a673f2204440cc2
|
data/.circleci/config.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Dockerfile
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
upperkut (1.0.
|
4
|
+
upperkut (1.0.2)
|
5
5
|
connection_pool (~> 2.2, >= 2.2.2)
|
6
6
|
redis (>= 4.1.0, < 5.0.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
coderay (1.1.
|
11
|
+
coderay (1.1.3)
|
12
12
|
connection_pool (2.2.3)
|
13
|
-
diff-lcs (1.
|
13
|
+
diff-lcs (1.4.4)
|
14
14
|
docile (1.3.2)
|
15
15
|
fivemat (1.3.7)
|
16
|
-
json (2.3.
|
16
|
+
json (2.3.1)
|
17
17
|
method_source (1.0.0)
|
18
18
|
pry (0.13.1)
|
19
19
|
coderay (~> 1.1)
|
20
20
|
method_source (~> 1.0)
|
21
21
|
rake (13.0.1)
|
22
|
-
redis (4.2.
|
23
|
-
rspec (3.
|
24
|
-
rspec-core (~> 3.
|
25
|
-
rspec-expectations (~> 3.
|
26
|
-
rspec-mocks (~> 3.
|
27
|
-
rspec-core (3.
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-expectations (3.
|
22
|
+
redis (4.2.5)
|
23
|
+
rspec (3.10.0)
|
24
|
+
rspec-core (~> 3.10.0)
|
25
|
+
rspec-expectations (~> 3.10.0)
|
26
|
+
rspec-mocks (~> 3.10.0)
|
27
|
+
rspec-core (3.10.0)
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-expectations (3.10.0)
|
30
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-mocks (3.
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-mocks (3.10.0)
|
33
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.
|
35
|
-
rspec-support (3.
|
34
|
+
rspec-support (~> 3.10.0)
|
35
|
+
rspec-support (3.10.0)
|
36
36
|
rspec_junit_formatter (0.4.1)
|
37
37
|
rspec-core (>= 2, < 4, != 2.12.0)
|
38
38
|
simplecov (0.17.1)
|
@@ -51,7 +51,7 @@ DEPENDENCIES
|
|
51
51
|
rake (~> 13.0)
|
52
52
|
rspec (~> 3.0)
|
53
53
|
rspec_junit_formatter
|
54
|
-
simplecov
|
54
|
+
simplecov (< 0.18)
|
55
55
|
upperkut!
|
56
56
|
|
57
57
|
BUNDLED WITH
|
data/Makefile
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
services:
|
2
|
+
gem:
|
3
|
+
build: .
|
4
|
+
volumes:
|
5
|
+
- .:/code
|
6
|
+
environment:
|
7
|
+
- REDIS_URL=redis://redis:6379
|
8
|
+
depends_on:
|
9
|
+
- redis
|
10
|
+
redis:
|
11
|
+
image: redis:5.0.4-alpine
|
12
|
+
command: redis-server --save "" --appendonly yes --appendfsync everysec
|
13
|
+
ports:
|
14
|
+
- 6379:6379
|
15
|
+
volumes:
|
16
|
+
- redis-data:/data
|
17
|
+
volumes:
|
18
|
+
redis-data:
|
data/lib/upperkut.rb
CHANGED
data/lib/upperkut/item.rb
CHANGED
@@ -4,27 +4,13 @@ module Upperkut
|
|
4
4
|
class Item
|
5
5
|
attr_reader :id, :body, :enqueued_at
|
6
6
|
|
7
|
-
def initialize(body:,
|
8
|
-
|
9
|
-
|
7
|
+
def initialize(id:, body:, enqueued_at: nil)
|
8
|
+
@id = id
|
10
9
|
@body = body
|
11
|
-
@id = id || SecureRandom.uuid
|
12
10
|
@enqueued_at = enqueued_at || Time.now.utc.to_i
|
13
11
|
@nacked = false
|
14
12
|
end
|
15
13
|
|
16
|
-
def [](key)
|
17
|
-
@body[key]
|
18
|
-
end
|
19
|
-
|
20
|
-
def []=(key, value)
|
21
|
-
@body[key] = value
|
22
|
-
end
|
23
|
-
|
24
|
-
def key?(key)
|
25
|
-
@body.key?(key)
|
26
|
-
end
|
27
|
-
|
28
14
|
def nack
|
29
15
|
@nacked = true
|
30
16
|
end
|
@@ -32,19 +18,5 @@ module Upperkut
|
|
32
18
|
def nacked?
|
33
19
|
@nacked
|
34
20
|
end
|
35
|
-
|
36
|
-
def to_json
|
37
|
-
JSON.generate(
|
38
|
-
'id' => @id,
|
39
|
-
'body' => @body,
|
40
|
-
'enqueued_at' => @enqueued_at
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.from_json(item_json)
|
45
|
-
hash = JSON.parse(item_json)
|
46
|
-
id, body, enqueued_at = hash.values_at('id', 'body', 'enqueued_at')
|
47
|
-
new(id: id, body: body, enqueued_at: enqueued_at)
|
48
|
-
end
|
49
21
|
end
|
50
22
|
end
|
data/lib/upperkut/processor.rb
CHANGED
@@ -83,7 +83,7 @@ module Upperkut
|
|
83
83
|
return false if items.empty?
|
84
84
|
|
85
85
|
redis do |conn|
|
86
|
-
conn.rpush(key, items
|
86
|
+
conn.rpush(key, encode_json_items(items))
|
87
87
|
end
|
88
88
|
|
89
89
|
true
|
@@ -111,7 +111,7 @@ module Upperkut
|
|
111
111
|
redis do |conn|
|
112
112
|
conn.eval(ACK_ITEMS,
|
113
113
|
keys: [processing_key],
|
114
|
-
argv: items
|
114
|
+
argv: encode_json_items(items))
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -121,7 +121,7 @@ module Upperkut
|
|
121
121
|
redis do |conn|
|
122
122
|
conn.eval(NACK_ITEMS,
|
123
123
|
keys: [key, processing_key],
|
124
|
-
argv: items
|
124
|
+
argv: encode_json_items(items))
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -43,8 +43,9 @@ module Upperkut
|
|
43
43
|
|
44
44
|
redis do |conn|
|
45
45
|
items.each do |item|
|
46
|
-
ensure_timestamp_attr(item)
|
47
|
-
|
46
|
+
schedule_item = ensure_timestamp_attr(item)
|
47
|
+
timestamp = schedule_item.body['timestamp']
|
48
|
+
conn.zadd(key, timestamp, encode_json_items(schedule_item))
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
@@ -97,7 +98,13 @@ module Upperkut
|
|
97
98
|
end
|
98
99
|
|
99
100
|
def ensure_timestamp_attr(item)
|
100
|
-
item
|
101
|
+
return item if item.body.key?('timestamp')
|
102
|
+
|
103
|
+
Item.new(
|
104
|
+
id: item.id,
|
105
|
+
body: item.body.merge('timestamp' => Time.now.utc.to_i),
|
106
|
+
enqueued_at: item.enqueued_at
|
107
|
+
)
|
101
108
|
end
|
102
109
|
|
103
110
|
def pop_values(redis_client, args)
|
@@ -119,17 +126,16 @@ module Upperkut
|
|
119
126
|
|
120
127
|
def latency
|
121
128
|
now = Time.now.utc
|
122
|
-
|
123
|
-
job = nil
|
129
|
+
timestamp = now.to_f
|
124
130
|
|
125
|
-
redis do |conn|
|
126
|
-
|
127
|
-
|
131
|
+
item = redis do |conn|
|
132
|
+
item = conn.zrangebyscore(key, '-inf', timestamp.to_s, limit: [0, 1]).first
|
133
|
+
decode_json_items([item]).first
|
128
134
|
end
|
129
135
|
|
130
|
-
return
|
136
|
+
return timestamp - item.body['timestamp'].to_f if item
|
131
137
|
|
132
|
-
|
138
|
+
0
|
133
139
|
end
|
134
140
|
|
135
141
|
def redis
|
data/lib/upperkut/util.rb
CHANGED
@@ -4,7 +4,7 @@ require 'upperkut/item'
|
|
4
4
|
module Upperkut
|
5
5
|
module Util
|
6
6
|
def to_underscore(object)
|
7
|
-
klass_name = object
|
7
|
+
klass_name = object.dup
|
8
8
|
klass_name.gsub!(/::/, '_')
|
9
9
|
klass_name.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
10
10
|
klass_name.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
@@ -27,13 +27,29 @@ module Upperkut
|
|
27
27
|
items.map do |item|
|
28
28
|
next item if item.is_a?(Item)
|
29
29
|
|
30
|
-
Item.new(body: item)
|
30
|
+
Item.new(id: SecureRandom.uuid, body: item)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def encode_json_items(items)
|
35
|
+
items = [items] unless items.is_a?(Array)
|
36
|
+
|
37
|
+
items.map do |item|
|
38
|
+
JSON.generate(
|
39
|
+
'id' => item.id,
|
40
|
+
'body' => item.body,
|
41
|
+
'enqueued_at' => item.enqueued_at
|
42
|
+
)
|
31
43
|
end
|
32
44
|
end
|
33
45
|
|
34
46
|
def decode_json_items(items)
|
35
|
-
items.each_with_object([]) do |
|
36
|
-
|
47
|
+
items.each_with_object([]) do |item_json, memo|
|
48
|
+
next unless item_json
|
49
|
+
|
50
|
+
hash = JSON.parse(item_json)
|
51
|
+
id, body, enqueued_at = hash.values_at('id', 'body', 'enqueued_at')
|
52
|
+
memo << Item.new(id: id, body: body, enqueued_at: enqueued_at)
|
37
53
|
end
|
38
54
|
end
|
39
55
|
|
data/lib/upperkut/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upperkut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Sousa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -106,12 +106,15 @@ files:
|
|
106
106
|
- ".rspec"
|
107
107
|
- CHANGELOG.md
|
108
108
|
- CODE_OF_CONDUCT.md
|
109
|
+
- Dockerfile
|
109
110
|
- Gemfile
|
110
111
|
- Gemfile.lock
|
111
112
|
- LICENSE.txt
|
113
|
+
- Makefile
|
112
114
|
- README.md
|
113
115
|
- Rakefile
|
114
116
|
- bin/upperkut
|
117
|
+
- docker-compose.yml
|
115
118
|
- examples/basic.rb
|
116
119
|
- examples/priority_worker.rb
|
117
120
|
- examples/scheduled_worker.rb
|
@@ -152,11 +155,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
155
|
version: 2.2.2
|
153
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
157
|
requirements:
|
155
|
-
- - "
|
158
|
+
- - ">="
|
156
159
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
160
|
+
version: '0'
|
158
161
|
requirements: []
|
159
|
-
rubygems_version: 3.1.
|
162
|
+
rubygems_version: 3.1.4
|
160
163
|
signing_key:
|
161
164
|
specification_version: 4
|
162
165
|
summary: Batch background processing tool
|