capistrano_sentinel 0.0.10 → 0.0.12

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: 5a1e41110f550198e8926d85040fbb9d0f0b38d0
4
- data.tar.gz: 07873dc3a8d1b6af8a55ab057f311e39d2d4aeaa
3
+ metadata.gz: 4e4d9c618056cbd81c8dee0e97618556667d96b5
4
+ data.tar.gz: ef5b1e1ca9665476e3fdb22d983fcbb9688c32f9
5
5
  SHA512:
6
- metadata.gz: b8f644fd6adf08e70b9144b07ba6f78c500284c1ffa268d86566c8dbac0b99504a3eb794ea853763199a44c384abf262e448a75b9cf9d835b485c5a37cda9826
7
- data.tar.gz: f4e8d7168145b03a75e45d0bf6a5ad93e1cc22988893d9796615c18f4445bb202cdbb4cfdf4b8eb44dad703df591276f40edc41a512ab1d48338c5d8f562c7f4
6
+ metadata.gz: 29c6022aec16df8834decd08a20323b3d79a1bb16ec196d4e5c81f5a387789af8d3aaed4dcaa7a3f9ec9d307d2e50a9e8a3b48655901308fb9e67cab9471623b
7
+ data.tar.gz: 8a9bb2c9224d2adb7824029d01dad477a2288e961044a67062f0a59737c98c5c9e23a6a77610cb4b0e0694dd54f0c97d380460087da0233670c00aac2a40fa14
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ before_install:
3
+ - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
4
+ - gem install bundler
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1.5
8
+ - 2.2.3
9
+ - 2.2.4
10
+ - 2.3.0
11
+ - 2.3.1
12
+ env:
13
+ - RAILS_ENV=test RACK_ENV=test
14
+ notifications:
15
+ email: false
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 (default 0.0.0.0 port 1234 and path /ws)
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
- Currently there is no posibility to change the default configuration becasue this was just released few days ago, but this will be added soon
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?(ENV[CapistranoSentinel::RequestHooks::ENV_KEY_JOB_ID])
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[CapistranoSentinel::RequestHooks::ENV_KEY_JOB_ID]
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
- actor.wait_execution until actor.task_approved
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
- private
54
+ private
53
55
 
54
56
  def actor
55
57
  @actor ||= CapistranoSentinel::RequestWorker.new
@@ -122,7 +122,7 @@ module CapistranoSentinel
122
122
  question: question,
123
123
  default: default.present? ? default.delete('()') : '',
124
124
  job_id: @job_id)
125
- wait_for_stdin_input
125
+ wait_for_stdin_input if CapistranoSentinel.config.wait_execution
126
126
  end
127
127
  end
128
128
  end
@@ -4,20 +4,8 @@ module CapistranoSentinel
4
4
  class WebsocketClient
5
5
  include CapistranoSentinel::ApplicationHelper
6
6
 
7
- HOST = '0.0.0.0'
8
- PORT = 1234
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 = CapistranoSentinel::WebsocketClient::DEFAULT_OPTS.merge(opts).symbolize_keys
36
- @secure = @options.delete :secure
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::WebsocketClient::HOST
39
- @port = @secure ? 443 : (@options.fetch(:port, nil) || CapistranoSentinel::WebsocketClient::PORT)
40
- @path = @options.fetch(:path, nil).to_s || CapistranoSentinel::WebsocketClient::PATH
41
- @query = @options.fetch(:query, nil).to_s
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 @options[:retry_time]
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(@options[:read_buffer_size])
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 @options[:reconnect]
359
+ reconnect if @reconnect
366
360
  end
367
361
 
368
362
  end # class
@@ -17,7 +17,7 @@ module CapistranoSentinel
17
17
  # minor release version
18
18
  MINOR = 0
19
19
  # tiny release version
20
- TINY = 10
20
+ TINY = 12
21
21
  # prelease version ( set this only if it is a prelease)
22
22
  PRE = nil
23
23
 
@@ -1 +1,12 @@
1
1
  require 'capistrano_sentinel/all'
2
+
3
+ module CapistranoSentinel
4
+
5
+ def self.configure
6
+ yield config
7
+ end
8
+
9
+ def self.config
10
+ @config ||= CapistranoSentinel::Configuration.new
11
+ end
12
+ end
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.10
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