activehook-server 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1daf2a4c8b361684d24c4e94d847d061cca55d56
4
- data.tar.gz: 88589eb56d60ef9bf609073600a7082d54f7dea6
3
+ metadata.gz: bba88b92233e06762c2fdbfb9d5137fc26127301
4
+ data.tar.gz: 71cba3618ff76f7e930a93a4a7506326d3397a31
5
5
  SHA512:
6
- metadata.gz: a73d98636cd3caaa1bb66ecf21efdc9656195c736ab43de0559393f4c99f5b3b61536bbbd649b6c004c50dcc6ef6fd1d600e09453d577adf0d4f56091f576e2b
7
- data.tar.gz: b56f6cb493a59947ff4e0d740f9384b1e72f030e87f3de306f2a07e73b89df8744652395518d4cc8bcfd0f978aece63818818d22a0ca5df29ef7dacff5f57d44
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-Webhook-Signature'
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
- ActiveHook::Server.log.info('ActiveHook Server starting!')
22
- ActiveHook::Server.log.info("* Version #{ActiveHook::Server::VERSION}, codename: #{ActiveHook::Server::CODENAME}")
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
- ActiveHook::Server.log.info("* Server config: #{arg}")
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(ActiveHook::Server.config.manager_options)
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
- ActiveHook::Server.log.info("* Workers: #{@workers}")
52
- ActiveHook::Server.log.info("* Threads: #{@options[:queue_threads]} queue, #{@options[:retry_threads]} retry")
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
- ActiveHook::Server.redis.with { |c| c.ping && c.quit }
65
+ Server.redis.with { |c| c.ping && c.quit }
66
66
  rescue
67
- msg = 'Cound not connect to Redis.'
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
- msg = 'Workers must be an Integer.'
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
- save_hook
15
+ save_message
16
16
  end
17
17
 
18
18
  def save!
19
19
  raise Errors::Message, 'Message is invalid' unless valid?
20
- save_hook
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
- ActiveHook::Server.redis.with do |conn|
80
- @id = conn.incr('ah:total_queued')
81
- conn.lpush('ah:queue', to_json)
82
- conn.zadd('ah:validation', @id, @key)
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 = ActiveHook::Server.redis.with { |c| c.brpop('ah:queue') }
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
- ActiveHook::Server.redis.with do |conn|
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('ah:total_success')
55
+ conn.incr("#{Server.config.queue_namespace}:success")
54
56
  end
55
57
 
56
58
  def message_failed(conn)
57
- conn.incr('ah:total_failed')
59
+ conn.incr("#{Server.config.queue_namespace}:failed")
58
60
  return unless @message.retry?
59
- conn.zadd('ah:retry', @message.retry_at, @message.to_json)
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: ActiveHook::Server.config.redis_pool) do
14
- Redis.new(url: ActiveHook::Server.config.redis_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
- ActiveHook::Server.redis.with do |conn|
11
- conn.watch('ah:retry') do
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('ah:retry', 0, Time.now.to_i)
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('ah:total_retries', retries.count)
34
- multi.zrem('ah:retry', retries)
35
- multi.lpush('ah:queue', retries)
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/#{ActiveHook::Server::VERSION}"
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
- ActiveHook::Server.log.info(msg)
63
+ Server.log.info(msg)
64
64
  else
65
- ActiveHook::Server.log.err(msg)
65
+ Server.log.err(msg)
66
66
  end
67
67
  end
68
68
 
@@ -1,6 +1,6 @@
1
1
  module ActiveHook
2
2
  module Server
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
  CODENAME = 'Fat Sparrow'
5
5
  end
6
6
  end
@@ -58,13 +58,13 @@ module ActiveHook
58
58
  # Information about the start process
59
59
  #
60
60
  def start_message
61
- ActiveHook::Server.log.info("* Worker #{@id} started, pid: #{@pid}")
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
- ActiveHook::Server.log.info("* Worker #{@id} shutdown, pid: #{@pid}")
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.5
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-06 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis