activehook-server 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activehook/server/config.rb +5 -2
- data/lib/activehook/server/launcher.rb +4 -4
- data/lib/activehook/server/manager.rb +5 -8
- data/lib/activehook/server/message.rb +6 -6
- data/lib/activehook/server/queue.rb +7 -5
- data/lib/activehook/server/redis.rb +2 -2
- data/lib/activehook/server/retry.rb +6 -6
- data/lib/activehook/server/send.rb +3 -3
- data/lib/activehook/server/version.rb +1 -1
- data/lib/activehook/server/worker.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bba88b92233e06762c2fdbfb9d5137fc26127301
|
4
|
+
data.tar.gz: 71cba3618ff76f7e930a93a4a7506326d3397a31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 001d1161226e3f924e35321f133649f424df54f166e9b48330bdbf83d3595969ef9d8d934f5da946796874f03eacaee95baf8789abd9c3f80749d8c6913249f0
|
7
|
+
data.tar.gz: eecd5b4a4863ca3aeb7dde16b3327e4a6403be391a32970f7f115ac8e469721e59326a030f00eaa75d569ded33168d3f35155ad7a5512f4bde67e8dc738eb027
|
@@ -23,11 +23,14 @@ module ActiveHook
|
|
23
23
|
retry_threads: 1,
|
24
24
|
redis_url: ENV['REDIS_URL'],
|
25
25
|
redis_pool: 5,
|
26
|
-
signature_header: 'X-
|
26
|
+
signature_header: 'X-Message-Signature',
|
27
|
+
queue_namespace: 'ah:v1:queue',
|
28
|
+
retry_namespace: 'ah:v1:retry'
|
27
29
|
}.freeze
|
28
30
|
|
29
31
|
attr_accessor :workers, :queue_threads, :retry_threads,
|
30
|
-
:redis_url, :redis_pool, :signature_header
|
32
|
+
:redis_url, :redis_pool, :signature_header,
|
33
|
+
:queue_namespace, :retry_namespace
|
31
34
|
|
32
35
|
def initialize
|
33
36
|
DEFAULTS.each { |key, value| send("#{key}=", value) }
|
@@ -18,8 +18,8 @@ module ActiveHook
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def start_message
|
21
|
-
|
22
|
-
|
21
|
+
Server.log.info('ActiveHook Server starting!')
|
22
|
+
Server.log.info("* Version #{Server::VERSION}, codename: #{Server::CODENAME}")
|
23
23
|
end
|
24
24
|
|
25
25
|
# Parses the arguments passed through the command line.
|
@@ -30,7 +30,7 @@ module ActiveHook
|
|
30
30
|
|
31
31
|
o.on('-c', '--config PATH', 'Load PATH for config file') do |arg|
|
32
32
|
load(arg)
|
33
|
-
|
33
|
+
Server.log.info("* Server config: #{arg}")
|
34
34
|
end
|
35
35
|
|
36
36
|
o.on('-h', '--help', 'Prints this help') { puts o && exit }
|
@@ -39,7 +39,7 @@ module ActiveHook
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def boot_manager
|
42
|
-
manager = Manager.new(
|
42
|
+
manager = Manager.new(Server.config.manager_options)
|
43
43
|
manager.start
|
44
44
|
end
|
45
45
|
end
|
@@ -48,8 +48,8 @@ module ActiveHook
|
|
48
48
|
# Information about the start process
|
49
49
|
#
|
50
50
|
def start_messages
|
51
|
-
|
52
|
-
|
51
|
+
Server.log.info("* Workers: #{@workers}")
|
52
|
+
Server.log.info("* Threads: #{@options[:queue_threads]} queue, #{@options[:retry_threads]} retry")
|
53
53
|
end
|
54
54
|
|
55
55
|
# Validates our data before starting our Workers. Also instantiates our
|
@@ -62,17 +62,14 @@ module ActiveHook
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def validate_redis
|
65
|
-
|
65
|
+
Server.redis.with { |c| c.ping && c.quit }
|
66
66
|
rescue
|
67
|
-
|
68
|
-
ActiveHook::Server.log.err(msg)
|
69
|
-
raise Errors::Manager, msg
|
67
|
+
raise Errors::Manager, 'Cound not connect to Redis.'
|
70
68
|
end
|
71
69
|
|
72
70
|
def validate_workers
|
73
71
|
return if @workers.is_a?(Integer)
|
74
|
-
|
75
|
-
raise Errors::Manager, msg
|
72
|
+
raise Errors::Manager, 'Workers must be an Integer.'
|
76
73
|
end
|
77
74
|
|
78
75
|
def validate_options
|
@@ -12,12 +12,12 @@ module ActiveHook
|
|
12
12
|
|
13
13
|
def save
|
14
14
|
return false unless valid?
|
15
|
-
|
15
|
+
save_message
|
16
16
|
end
|
17
17
|
|
18
18
|
def save!
|
19
19
|
raise Errors::Message, 'Message is invalid' unless valid?
|
20
|
-
|
20
|
+
save_message
|
21
21
|
end
|
22
22
|
|
23
23
|
def payload=(payload)
|
@@ -76,10 +76,10 @@ module ActiveHook
|
|
76
76
|
private
|
77
77
|
|
78
78
|
def save_message
|
79
|
-
|
80
|
-
@id = conn.incr(
|
81
|
-
conn.lpush(
|
82
|
-
conn.zadd(
|
79
|
+
Server.redis.with do |conn|
|
80
|
+
@id = conn.incr("#{Server.config.queue_namespace}:total")
|
81
|
+
conn.lpush(Server.config.queue_namespace, to_json)
|
82
|
+
conn.zadd("#{Server.config.queue_namespace}:validations", @id, @key)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -28,7 +28,9 @@ module ActiveHook
|
|
28
28
|
# Performs a 'blocking pop' on our redis queue list.
|
29
29
|
#
|
30
30
|
def retrieve_message
|
31
|
-
json =
|
31
|
+
json = Server.redis.with do |c|
|
32
|
+
c.brpop(Server.config.queue_namespace)
|
33
|
+
end
|
32
34
|
json.last if json
|
33
35
|
end
|
34
36
|
end
|
@@ -42,7 +44,7 @@ module ActiveHook
|
|
42
44
|
|
43
45
|
def start
|
44
46
|
@post.start
|
45
|
-
|
47
|
+
Server.redis.with do |conn|
|
46
48
|
@post.success? ? message_success(conn) : message_failed(conn)
|
47
49
|
end
|
48
50
|
end
|
@@ -50,13 +52,13 @@ module ActiveHook
|
|
50
52
|
private
|
51
53
|
|
52
54
|
def message_success(conn)
|
53
|
-
conn.incr(
|
55
|
+
conn.incr("#{Server.config.queue_namespace}:success")
|
54
56
|
end
|
55
57
|
|
56
58
|
def message_failed(conn)
|
57
|
-
conn.incr(
|
59
|
+
conn.incr("#{Server.config.queue_namespace}:failed")
|
58
60
|
return unless @message.retry?
|
59
|
-
conn.zadd(
|
61
|
+
conn.zadd(Server.config.retry_namespace, @message.retry_at, @message.to_json)
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -10,8 +10,8 @@ module ActiveHook
|
|
10
10
|
|
11
11
|
class ConnectionPool
|
12
12
|
def self.create
|
13
|
-
::ConnectionPool.new(size:
|
14
|
-
Redis.new(url:
|
13
|
+
::ConnectionPool.new(size: Server.config.redis_pool) do
|
14
|
+
Redis.new(url: Server.config.redis_url)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -7,8 +7,8 @@ module ActiveHook
|
|
7
7
|
|
8
8
|
def start
|
9
9
|
until @done
|
10
|
-
|
11
|
-
conn.watch(
|
10
|
+
Server.redis.with do |conn|
|
11
|
+
conn.watch(Server.config.retry_namespace) do
|
12
12
|
retries = retrieve_retries(conn)
|
13
13
|
update_retries(conn, retries)
|
14
14
|
end
|
@@ -24,15 +24,15 @@ module ActiveHook
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def retrieve_retries(conn)
|
27
|
-
conn.zrangebyscore(
|
27
|
+
conn.zrangebyscore(Server.config.retry_namespace, 0, Time.now.to_i)
|
28
28
|
end
|
29
29
|
|
30
30
|
def update_retries(conn, retries)
|
31
31
|
if retries.any?
|
32
32
|
conn.multi do |multi|
|
33
|
-
multi.incrby(
|
34
|
-
multi.zrem(
|
35
|
-
multi.lpush(
|
33
|
+
multi.incrby("#{Server.config.retry_namespace}:total", retries.count)
|
34
|
+
multi.zrem(Server.config.retry_namespace, retries)
|
35
|
+
multi.lpush(Server.config.queue_namespace, retries)
|
36
36
|
end
|
37
37
|
else
|
38
38
|
conn.unwatch
|
@@ -4,7 +4,7 @@ module ActiveHook
|
|
4
4
|
REQUEST_HEADERS = {
|
5
5
|
"Content-Type" => "application/json",
|
6
6
|
"Accept" => "application/json",
|
7
|
-
"User-Agent" => "ActiveHook/#{
|
7
|
+
"User-Agent" => "ActiveHook/#{Server::VERSION}"
|
8
8
|
}.freeze
|
9
9
|
|
10
10
|
attr_accessor :message
|
@@ -60,9 +60,9 @@ module ActiveHook
|
|
60
60
|
def log_status
|
61
61
|
msg = "POST | #{uri} | #{status.upcase} #{response_time}"
|
62
62
|
if status == :success
|
63
|
-
|
63
|
+
Server.log.info(msg)
|
64
64
|
else
|
65
|
-
|
65
|
+
Server.log.err(msg)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -58,13 +58,13 @@ module ActiveHook
|
|
58
58
|
# Information about the start process
|
59
59
|
#
|
60
60
|
def start_message
|
61
|
-
|
61
|
+
Server.log.info("* Worker #{@id} started, pid: #{@pid}")
|
62
62
|
end
|
63
63
|
|
64
64
|
# Information about the shutdown process
|
65
65
|
#
|
66
66
|
def shutdown_message
|
67
|
-
|
67
|
+
Server.log.info("* Worker #{@id} shutdown, pid: #{@pid}")
|
68
68
|
end
|
69
69
|
|
70
70
|
# Validates our data before starting the worker.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activehook-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Sweeting
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|