activehook-server 0.1.1 → 0.1.2

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: 201412c43f9227345cee75c377792a9fc8f8d961
4
- data.tar.gz: c5c69be1f47a5f1ddd5892f0d68eb4762d4e5a72
3
+ metadata.gz: 1219a4526cb89c42d1458f392368e300921856d3
4
+ data.tar.gz: fef1df8b61a5bff797a1f677dc63c107e39bb5b4
5
5
  SHA512:
6
- metadata.gz: 61643d860e6d5f1c4a029a7735fe456bb40e4c765d9e3cc86baf3b62013ce514cf2c5304b9db37f1cff1ee727c8df616825fa523f7c728644ae9ad399103e080
7
- data.tar.gz: edb11abbb40d1caf937a8a3207117378086ee7c299c0a713bd85aa8d6695b39264bb49f6d89d9f153ed2e91bf2d2a36662c23779a466083bd7380adeeb344732
6
+ metadata.gz: a52a21c85a679d5cd622848f821d9d8e47e98313f4b6e205e4b5c54db902f1bfce37ec4a9ad089151a16732134cc476c78cf5cc96e1685cb09335bac8e721242
7
+ data.tar.gz: 54bce1a19600d8f6be8031bcc162589ad31e067b6abe19e25d298eaa3b1e0326369c137137bebc2dba8abca779bf36f0e4a8a056c50214da16c5d2bf6d046e27
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'activehook/server/version'
4
3
  require 'activehook/server'
5
4
 
6
5
  server = ActiveHook::Server::Launcher.new(ARGV)
@@ -5,7 +5,8 @@ require 'uri'
5
5
  require 'net/http'
6
6
  require 'openssl'
7
7
  require 'connection_pool'
8
- require 'activehook/server/hook'
8
+ require 'activehook/server/version'
9
+ require 'activehook/server/message'
9
10
  require 'activehook/server/config'
10
11
  require 'activehook/server/redis'
11
12
  require 'activehook/server/errors'
@@ -2,7 +2,7 @@ module ActiveHook
2
2
  module Server
3
3
  module Errors
4
4
  class Config < StandardError; end
5
- class Hook < StandardError; end
5
+ class Message < StandardError; end
6
6
  class HTTP < StandardError; end
7
7
  class Send < StandardError; end
8
8
  class Server < StandardError; end
@@ -1,6 +1,6 @@
1
1
  module ActiveHook
2
2
  module Server
3
- class Hook
3
+ class Message
4
4
  attr_accessor :token, :uri, :id, :key, :retry_max, :retry_time, :created_at
5
5
  attr_reader :errors, :payload
6
6
 
@@ -16,7 +16,7 @@ module ActiveHook
16
16
  end
17
17
 
18
18
  def save!
19
- raise Errors::Hook, 'Hook is invalid' unless valid?
19
+ raise Errors::Message, 'Message is invalid' unless valid?
20
20
  save_hook
21
21
  end
22
22
 
@@ -58,10 +58,9 @@ module ActiveHook
58
58
  end
59
59
 
60
60
  def final_payload
61
- { hook_id: @id,
62
- hook_key: @key,
63
- hook_time: @created_at,
64
- hook_signature: ActiveHook.config.signature_header,
61
+ { id: @id,
62
+ key: @key,
63
+ created_at: @created_at,
65
64
  payload: @payload }.to_json
66
65
  end
67
66
 
@@ -76,7 +75,7 @@ module ActiveHook
76
75
 
77
76
  private
78
77
 
79
- def save_hook
78
+ def save_message
80
79
  ActiveHook::Server.redis.with do |conn|
81
80
  @id = conn.incr('ah:total_queued')
82
81
  conn.lpush('ah:queue', to_json)
@@ -1,7 +1,7 @@
1
1
  module ActiveHook
2
2
  module Server
3
- # The Queue object processes any hooks that are queued into our Redis server.
4
- # It will perform a 'blocking pop' on our hook list until one is added.
3
+ # The Queue object processes any messages that are queued into our Redis server.
4
+ # It will perform a 'blocking pop' on our message list until one is added.
5
5
  #
6
6
  class Queue
7
7
  def initialize
@@ -12,8 +12,8 @@ module ActiveHook
12
12
  #
13
13
  def start
14
14
  until @done
15
- json = retrieve_hook
16
- HookRunner.new(json) if json
15
+ json = retrieve_message
16
+ MessageRunner.new(json) if json
17
17
  end
18
18
  end
19
19
 
@@ -27,35 +27,36 @@ module ActiveHook
27
27
 
28
28
  # Performs a 'blocking pop' on our redis queue list.
29
29
  #
30
- def retrieve_hook
30
+ def retrieve_message
31
31
  json = ActiveHook::Server.redis.with { |c| c.brpop('ah:queue') }
32
32
  json.last if json
33
33
  end
34
34
  end
35
35
 
36
- class HookRunner
36
+ class MessageRunner
37
37
  def initialize(json)
38
- @hook = Hook.new(JSON.parse(json))
39
- @post = Send.new(hook: @hook)
38
+ @message = Message.new(JSON.parse(json))
39
+ @post = Send.new(message: @message)
40
40
  start
41
41
  end
42
42
 
43
43
  def start
44
44
  @post.start
45
45
  ActiveHook::Server.redis.with do |conn|
46
- @post.success? ? hook_success(conn) : hook_failed(conn)
46
+ @post.success? ? message_success(conn) : message_failed(conn)
47
47
  end
48
48
  end
49
49
 
50
50
  private
51
51
 
52
- def hook_success(conn)
52
+ def message_success(conn)
53
53
  conn.incr('ah:total_success')
54
54
  end
55
55
 
56
- def hook_failed(conn)
57
- conn.zadd('ah:retry', @hook.retry_at, @hook.to_json) if @hook.retry?
56
+ def message_failed(conn)
58
57
  conn.incr('ah:total_failed')
58
+ return unless @message.retry?
59
+ conn.zadd('ah:retry', @message.retry_at, @message.to_json)
59
60
  end
60
61
  end
61
62
  end
@@ -7,7 +7,7 @@ module ActiveHook
7
7
  "User-Agent" => "ActiveHook/#{ActiveHook::Server::VERSION}"
8
8
  }.freeze
9
9
 
10
- attr_accessor :hook
10
+ attr_accessor :message
11
11
  attr_reader :response_time, :status, :response
12
12
 
13
13
  def initialize(options = {})
@@ -15,12 +15,12 @@ module ActiveHook
15
15
  end
16
16
 
17
17
  def start
18
- @status = post_hook
18
+ @status = post_message
19
19
  log_status
20
20
  end
21
21
 
22
22
  def uri
23
- @uri ||= URI.parse(@hook.uri)
23
+ @uri ||= URI.parse(@message.uri)
24
24
  end
25
25
 
26
26
  def success?
@@ -29,10 +29,10 @@ module ActiveHook
29
29
 
30
30
  private
31
31
 
32
- def post_hook
32
+ def post_message
33
33
  http = Net::HTTP.new(uri.host, uri.port)
34
34
  measure_response_time do
35
- @response = http.post(uri.path, @hook.final_payload, final_headers)
35
+ @response = http.post(uri.path, @message.final_payload, final_headers)
36
36
  end
37
37
  response_status(@response)
38
38
  rescue
@@ -67,7 +67,7 @@ module ActiveHook
67
67
  end
68
68
 
69
69
  def final_headers
70
- { "X-Hook-Signature" => @hook.signature }.merge(REQUEST_HEADERS)
70
+ { "X-Hook-Signature" => @message.signature }.merge(REQUEST_HEADERS)
71
71
  end
72
72
  end
73
73
  end
@@ -1,6 +1,6 @@
1
1
  module ActiveHook
2
2
  module Server
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  CODENAME = 'Fat Sparrow'
5
5
  end
6
6
  end
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.1
4
+ version: 0.1.2
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-06-29 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -159,10 +159,10 @@ files:
159
159
  - lib/activehook/server.rb
160
160
  - lib/activehook/server/config.rb
161
161
  - lib/activehook/server/errors.rb
162
- - lib/activehook/server/hook.rb
163
162
  - lib/activehook/server/launcher.rb
164
163
  - lib/activehook/server/log.rb
165
164
  - lib/activehook/server/manager.rb
165
+ - lib/activehook/server/message.rb
166
166
  - lib/activehook/server/queue.rb
167
167
  - lib/activehook/server/redis.rb
168
168
  - lib/activehook/server/retry.rb