capistrano_sentinel 0.0.10 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -0
- data/README.md +40 -2
- data/lib/capistrano_sentinel/all.rb +2 -1
- data/lib/capistrano_sentinel/classes/configuration.rb +32 -0
- data/lib/capistrano_sentinel/classes/request_hooks.rb +5 -3
- data/lib/capistrano_sentinel/classes/request_worker.rb +1 -1
- data/lib/capistrano_sentinel/classes/websocket_client.rb +18 -24
- data/lib/capistrano_sentinel/version.rb +1 -1
- data/lib/capistrano_sentinel.rb +11 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e4d9c618056cbd81c8dee0e97618556667d96b5
|
4
|
+
data.tar.gz: ef5b1e1ca9665476e3fdb22d983fcbb9688c32f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c6022aec16df8834decd08a20323b3d79a1bb16ec196d4e5c81f5a387789af8d3aaed4dcaa7a3f9ec9d307d2e50a9e8a3b48655901308fb9e67cab9471623b
|
7
|
+
data.tar.gz: 8a9bb2c9224d2adb7824029d01dad477a2288e961044a67062f0a59737c98c5c9e23a6a77610cb4b0e0694dd54f0c97d380460087da0233670c00aac2a40fa14
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -6,9 +6,9 @@ Overview
|
|
6
6
|
|
7
7
|
CapistranoSentinel is a simple ruby implementation that allows you to emit websocket events before a task is invoked by Capistrano.
|
8
8
|
|
9
|
-
This gem only has the websocket client that emit events to a host
|
9
|
+
This gem only has the websocket client that emit events to a default host and port , see here more details: **[Configuration options](#configuration-options)**
|
10
10
|
|
11
|
-
|
11
|
+
You can change that configuration following the description below
|
12
12
|
|
13
13
|
Requirements
|
14
14
|
------------
|
@@ -39,6 +39,44 @@ Add the following to your Capfile
|
|
39
39
|
require 'capistrano_sentinel'
|
40
40
|
```
|
41
41
|
|
42
|
+
Configuration options
|
43
|
+
=====================
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
CapistranoSentinel.configure do |config|
|
47
|
+
|
48
|
+
# if the connection needs to be secure ( using port 443)
|
49
|
+
config.secure = false
|
50
|
+
|
51
|
+
# the host on which the server is listening to connections
|
52
|
+
config.host = '0.0.0.0'
|
53
|
+
|
54
|
+
# the port on which the server is listening to connections
|
55
|
+
config.port = 1234
|
56
|
+
|
57
|
+
# the path to which the server is listening to connections
|
58
|
+
config.path = '/ws'
|
59
|
+
|
60
|
+
# if it receives a ping message, does it need to respond automatically
|
61
|
+
config.auto_pong = true
|
62
|
+
|
63
|
+
# how many bites can it read from the connection
|
64
|
+
config.read_buffer_size = 2048
|
65
|
+
|
66
|
+
# if the conection can reconnect in case the connection was unsuccessful
|
67
|
+
config.reconnect = false
|
68
|
+
|
69
|
+
# how many times can retry the connection
|
70
|
+
config.retry_time = 0
|
71
|
+
|
72
|
+
# if this is enabled, the task will sleep until the socket receives a message back in this format
|
73
|
+
# {"action"=>"invoke", "task"=><task_name>, "job_id"=><job_id>, "approved"=>"yes"},
|
74
|
+
# where the task_name needs to be the task that is waiting for approval and
|
75
|
+
# the job_id needs to be set using ENV['multi_cap_job_id'], for parallel processing ( if the job id is missing , will be automatically generated with SecureRandom.uuid)
|
76
|
+
config.wait_execution = true
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
42
80
|
Usage Instructions
|
43
81
|
==================
|
44
82
|
|
@@ -13,6 +13,7 @@ require 'forwardable'
|
|
13
13
|
require 'thread'
|
14
14
|
require 'monitor'
|
15
15
|
require 'logger'
|
16
|
+
require 'securerandom'
|
16
17
|
|
17
18
|
require 'websocket'
|
18
19
|
require_relative './classes/gem_finder'
|
@@ -21,7 +22,7 @@ require_relative './classes/gem_finder'
|
|
21
22
|
Gem.find_files("#{CapistranoSentinel::GemFinder.get_current_gem_name}/#{folder_name}/**/*.rb").each { |path| require path }
|
22
23
|
end
|
23
24
|
|
24
|
-
if !CapistranoSentinel::GemFinder.value_blank?(
|
25
|
+
if !CapistranoSentinel::GemFinder.value_blank?(CapistranoSentinel::RequestHooks.job_id)
|
25
26
|
|
26
27
|
if CapistranoSentinel::GemFinder.fetch_gem_version('capistrano')
|
27
28
|
if CapistranoSentinel::GemFinder.capistrano_version_2?
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module CapistranoSentinel
|
2
|
+
class Configuration
|
3
|
+
SETTINGS = [:host, :port, :path, :secure, :auto_pong, :read_buffer_size,:reconnect, :retry_time, :wait_execution]
|
4
|
+
|
5
|
+
SETTINGS.each do |setting|
|
6
|
+
attr_reader setting
|
7
|
+
attr_accessor setting
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@secure = false
|
12
|
+
@host = '0.0.0.0'
|
13
|
+
@port = 1234
|
14
|
+
@path = '/ws'
|
15
|
+
@auto_pong = true
|
16
|
+
@read_buffer_size = 2048
|
17
|
+
@reconnect = false
|
18
|
+
@retry_time = 0
|
19
|
+
@wait_execution = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(settings_hash)
|
23
|
+
settings_hash.each do |setting, value|
|
24
|
+
unless SETTINGS.include? setting.to_sym
|
25
|
+
raise ArgumentError, "invalid setting: #{setting}"
|
26
|
+
end
|
27
|
+
|
28
|
+
self.public_send "#{setting}=", value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -6,7 +6,7 @@ module CapistranoSentinel
|
|
6
6
|
class RequestHooks
|
7
7
|
|
8
8
|
def self.job_id
|
9
|
-
ENV
|
9
|
+
@@job_id ||= ENV.fetch(CapistranoSentinel::RequestHooks::ENV_KEY_JOB_ID, nil) || SecureRandom.uuid
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.socket_client
|
@@ -28,7 +28,9 @@ module CapistranoSentinel
|
|
28
28
|
if job_id.present? && @task.present?
|
29
29
|
subscribed_already = defined?(@@socket_client)
|
30
30
|
actor_start_working(action: 'invoke', subscribed: subscribed_already)
|
31
|
-
|
31
|
+
if CapistranoSentinel.config.wait_execution
|
32
|
+
actor.wait_execution until actor.task_approved
|
33
|
+
end
|
32
34
|
actor_execute_block(&block)
|
33
35
|
else
|
34
36
|
block.call
|
@@ -49,7 +51,7 @@ module CapistranoSentinel
|
|
49
51
|
yield if block_given?
|
50
52
|
end
|
51
53
|
|
52
|
-
|
54
|
+
private
|
53
55
|
|
54
56
|
def actor
|
55
57
|
@actor ||= CapistranoSentinel::RequestWorker.new
|
@@ -4,20 +4,8 @@ module CapistranoSentinel
|
|
4
4
|
class WebsocketClient
|
5
5
|
include CapistranoSentinel::ApplicationHelper
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
PATH = '/ws'
|
10
|
-
|
11
|
-
DEFAULT_OPTS = {
|
12
|
-
auto_pong: true,
|
13
|
-
read_buffer_size: 2048,
|
14
|
-
reconnect: false,
|
15
|
-
secure: false,
|
16
|
-
retry_time: 0
|
17
|
-
}
|
18
|
-
|
19
|
-
attr_reader :socket, :read_thread, :protocol_version, :actor
|
20
|
-
attr_accessor :auto_pong, :on_ping, :on_error, :on_message, :actor
|
7
|
+
attr_reader :socket, :read_thread, :protocol_version, :actor, :read_buffer_size, :reconnect, :retry_time
|
8
|
+
attr_accessor :auto_pong, :on_ping, :on_error, :on_message, :actor, :read_buffer_size, :reconnect, :retry_time
|
21
9
|
|
22
10
|
##
|
23
11
|
# +host+:: Host of request. Required if no :url param was provided.
|
@@ -32,19 +20,25 @@ module CapistranoSentinel
|
|
32
20
|
def initialize(opts)
|
33
21
|
|
34
22
|
# Initializing with a single hash
|
35
|
-
@options =
|
36
|
-
|
23
|
+
@options = opts.symbolize_keys
|
24
|
+
|
25
|
+
@auto_pong = @options.fetch(:auto_pong, nil) || CapistranoSentinel.config.auto_pong
|
26
|
+
@read_buffer_size = @options.fetch(:read_buffer_size, nil) || CapistranoSentinel.config.read_buffer_size
|
27
|
+
@reconnect = @options.fetch(:reconnect, nil) || CapistranoSentinel.config.reconnect
|
28
|
+
@retry_time = @options.fetch(:retry_time, nil) || CapistranoSentinel.config.retry_time
|
29
|
+
|
30
|
+
|
31
|
+
@secure = @options.fetch(:secure, nil) || CapistranoSentinel.config.secure
|
37
32
|
|
38
|
-
@host = @options.fetch(:host, nil) || CapistranoSentinel
|
39
|
-
@port = @secure ? 443 : (@options.fetch(:port, nil) ||
|
40
|
-
@path = @options.fetch(:path, nil)
|
41
|
-
@query = @options.fetch(:query, nil)
|
33
|
+
@host = @options.fetch(:host, nil) || CapistranoSentinel.config.host
|
34
|
+
@port = @secure ? 443 : (@options.fetch(:port, nil) || CapistranoSentinel.config.port)
|
35
|
+
@path = @options.fetch(:path, nil) || CapistranoSentinel.config.path
|
36
|
+
@query = @options.fetch(:query, nil)
|
42
37
|
|
43
38
|
@actor ||= @options.fetch(:actor, nil)
|
44
39
|
@channel ||= @options.fetch(:channel, nil)
|
45
40
|
|
46
41
|
|
47
|
-
@auto_pong = @options.fetch(:auto_pong, true) || true
|
48
42
|
@closed = false
|
49
43
|
@opened = false
|
50
44
|
|
@@ -224,7 +218,7 @@ module CapistranoSentinel
|
|
224
218
|
connect
|
225
219
|
rescue ::Errno::ECONNREFUSED => e
|
226
220
|
log_to_file("#{self.class} got ECONNREFUSED #{e.inspect} ")
|
227
|
-
sleep @
|
221
|
+
sleep @retry_time
|
228
222
|
rescue => e
|
229
223
|
fire_on_error e
|
230
224
|
end
|
@@ -287,7 +281,7 @@ module CapistranoSentinel
|
|
287
281
|
frame = ::WebSocket::Frame::Incoming::Client.new(:version => @protocol_version)
|
288
282
|
loop do
|
289
283
|
begin
|
290
|
-
frame << @socket.readpartial(@
|
284
|
+
frame << @socket.readpartial(@read_buffer_size)
|
291
285
|
while message = frame.next
|
292
286
|
#"text", "binary", "ping", "pong" and "close" (according to websocket/base.rb)
|
293
287
|
determine_message_type(message)
|
@@ -362,7 +356,7 @@ module CapistranoSentinel
|
|
362
356
|
@on_close.call(message) if @on_close
|
363
357
|
@socket.close unless @socket.closed?
|
364
358
|
|
365
|
-
reconnect if @
|
359
|
+
reconnect if @reconnect
|
366
360
|
end
|
367
361
|
|
368
362
|
end # class
|
data/lib/capistrano_sentinel.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano_sentinel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bogdanRada
|
@@ -31,6 +31,7 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".travis.yml"
|
34
35
|
- Gemfile
|
35
36
|
- LICENSE.txt
|
36
37
|
- README.md
|
@@ -38,6 +39,7 @@ files:
|
|
38
39
|
- capistrano_sentinel.gemspec
|
39
40
|
- lib/capistrano_sentinel.rb
|
40
41
|
- lib/capistrano_sentinel/all.rb
|
42
|
+
- lib/capistrano_sentinel/classes/configuration.rb
|
41
43
|
- lib/capistrano_sentinel/classes/gem_finder.rb
|
42
44
|
- lib/capistrano_sentinel/classes/input_stream.rb
|
43
45
|
- lib/capistrano_sentinel/classes/output_stream.rb
|