capistrano_sentinel 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63fcb2c5390ee0635ba551de92f6c76e30fe91a6
|
4
|
+
data.tar.gz: 927e880f797908adde7bf04661b007bdb7bd64c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f56cc17119271efc5284be61cec30a2e5bb0bbeb3e3a0560a358d74853e516112403e921f30ead635b11cfbf12a8d44a0a97a68c6e055197c104e3ffd446ae88
|
7
|
+
data.tar.gz: 31226b6fc03cbb04cf43694b5d82c5fbd6baf5ebcf05280cdd690e534906c615bbc89ed4ed4fccef35f81695b07587da25ee361f4662a737eca520a2108d6cc4
|
@@ -5,6 +5,14 @@ module CapistranoSentinel
|
|
5
5
|
# class used to handle the rake worker and sets all the hooks before and after running the worker
|
6
6
|
class RequestHooks
|
7
7
|
|
8
|
+
def self.job_id
|
9
|
+
ENV[CapistranoSentinel::RequestHooks::ENV_KEY_JOB_ID]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.socket_client
|
13
|
+
@@socket_client ||= CapistranoSentinel::WebsocketClient.new(actor: nil, enable_debug: ENV.fetch('debug_websocket', false), channel: "#{CapistranoSentinel::RequestHooks::SUBSCRIPTION_PREFIX}#{job_id}", log_file_path: ENV.fetch('websocket_log_file_path', nil))
|
14
|
+
end
|
15
|
+
|
8
16
|
ENV_KEY_JOB_ID = 'multi_cap_job_id'
|
9
17
|
SUBSCRIPTION_PREFIX ="rake_worker_"
|
10
18
|
PUBLISHER_PREFIX ="celluloid_worker_"
|
@@ -12,13 +20,14 @@ module CapistranoSentinel
|
|
12
20
|
attr_accessor :job_id, :task
|
13
21
|
|
14
22
|
def initialize(task = nil)
|
15
|
-
@job_id =
|
23
|
+
@job_id = CapistranoSentinel::RequestHooks.job_id
|
16
24
|
@task = task.respond_to?(:fully_qualified_name) ? task.fully_qualified_name : task
|
17
25
|
end
|
18
26
|
|
19
27
|
def automatic_hooks(&block)
|
20
28
|
if job_id.present? && @task.present?
|
21
|
-
|
29
|
+
subscribed_already = defined?(@@socket_client)
|
30
|
+
actor_start_working(action: 'invoke', subscribed: subscribed_already)
|
22
31
|
actor.wait_execution until actor.task_approved
|
23
32
|
actor_execute_block(&block)
|
24
33
|
else
|
@@ -12,7 +12,8 @@ module CapistranoSentinel
|
|
12
12
|
def work(options = {})
|
13
13
|
@options = options.stringify_keys
|
14
14
|
default_settings
|
15
|
-
socket_client.
|
15
|
+
socket_client.actor = self
|
16
|
+
publish_to_worker(task_data) if options['subscribed'].present?
|
16
17
|
end
|
17
18
|
|
18
19
|
def wait_execution(name = task_name, time = 0.1)
|
@@ -28,7 +29,7 @@ module CapistranoSentinel
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def socket_client
|
31
|
-
@socket_client = CapistranoSentinel::
|
32
|
+
@socket_client = CapistranoSentinel::RequestHooks.socket_client
|
32
33
|
end
|
33
34
|
|
34
35
|
def default_settings
|
@@ -52,6 +53,7 @@ module CapistranoSentinel
|
|
52
53
|
end
|
53
54
|
|
54
55
|
def publish_to_worker(data)
|
56
|
+
log_to_file("RakeWorker #{@job_id} tries to publish #{data.inspect}")
|
55
57
|
socket_client.publish("#{CapistranoSentinel::RequestHooks::PUBLISHER_PREFIX}#{@job_id}", data)
|
56
58
|
end
|
57
59
|
|
@@ -101,10 +103,11 @@ module CapistranoSentinel
|
|
101
103
|
def task_approval(message)
|
102
104
|
return if !message_is_about_a_task?(message)
|
103
105
|
log_to_file("RakeWorker #{@job_id} #{task_name} task_approval : #{message.inspect}")
|
104
|
-
if @job_id.to_s == message['job_id'].to_s && message['task'] && message['approved'] == 'yes'
|
106
|
+
if @job_id.to_s == message['job_id'].to_s && message['task'].to_s == task_name.to_s && message['approved'] == 'yes'
|
107
|
+
show_warning "#{self.inspect} got #{message} and approved"
|
105
108
|
@task_approved = true
|
106
109
|
else
|
107
|
-
show_warning "unknown task_approval #{message} #{task_data}"
|
110
|
+
show_warning "#{self.inspect} got unknown task_approval #{message} #{task_data}"
|
108
111
|
end
|
109
112
|
end
|
110
113
|
|
@@ -16,8 +16,8 @@ module CapistranoSentinel
|
|
16
16
|
retry_time: 0
|
17
17
|
}
|
18
18
|
|
19
|
-
attr_reader :socket, :read_thread, :protocol_version
|
20
|
-
attr_accessor :auto_pong, :on_ping, :on_error, :on_message
|
19
|
+
attr_reader :socket, :read_thread, :protocol_version, :actor
|
20
|
+
attr_accessor :auto_pong, :on_ping, :on_error, :on_message, :actor
|
21
21
|
|
22
22
|
##
|
23
23
|
# +host+:: Host of request. Required if no :url param was provided.
|
@@ -42,7 +42,6 @@ module CapistranoSentinel
|
|
42
42
|
|
43
43
|
@actor ||= @options.fetch(:actor, nil)
|
44
44
|
@channel ||= @options.fetch(:channel, nil)
|
45
|
-
raise "#{self}: Please provide an actor in the options list!!!" if @actor.blank?
|
46
45
|
|
47
46
|
|
48
47
|
@auto_pong = @options.fetch(:auto_pong, true) || true
|
@@ -56,7 +55,7 @@ module CapistranoSentinel
|
|
56
55
|
|
57
56
|
@on_close = lambda { |message|
|
58
57
|
log_to_file("native websocket client received on_close #{message.inspect}")
|
59
|
-
if @actor.respond_to?(:on_close)
|
58
|
+
if @actor.present? && @actor.respond_to?(:on_close)
|
60
59
|
if @actor.respond_to?(:async)
|
61
60
|
@actor.async.on_close(message)
|
62
61
|
else
|
@@ -67,7 +66,7 @@ module CapistranoSentinel
|
|
67
66
|
|
68
67
|
@on_ping = lambda { |message|
|
69
68
|
log_to_file("native websocket client received PING #{message.inspect}")
|
70
|
-
if @actor.respond_to?(:on_ping)
|
69
|
+
if @actor.present? && @actor.respond_to?(:on_ping)
|
71
70
|
if @actor.respond_to?(:async)
|
72
71
|
@actor.async.on_ping(message)
|
73
72
|
else
|
@@ -78,7 +77,7 @@ module CapistranoSentinel
|
|
78
77
|
|
79
78
|
@on_error = lambda { |error|
|
80
79
|
log_to_file("native websocket client received ERROR #{error.inspect} #{error.backtrace}")
|
81
|
-
if @actor.respond_to?(:on_error)
|
80
|
+
if @actor.present? && @actor.respond_to?(:on_error)
|
82
81
|
if @actor.respond_to?(:async)
|
83
82
|
@actor.async.on_error(error)
|
84
83
|
else
|
@@ -89,8 +88,8 @@ module CapistranoSentinel
|
|
89
88
|
|
90
89
|
@on_message = lambda { |message|
|
91
90
|
message = parse_json(message)
|
92
|
-
log_to_file("
|
93
|
-
if @actor.respond_to?(:async)
|
91
|
+
log_to_file("#{@actor.inspect} websocket client received JSON #{message}")
|
92
|
+
if @actor.present? && @actor.respond_to?(:async)
|
94
93
|
@actor.async.on_message(message)
|
95
94
|
else
|
96
95
|
@actor.on_message(message)
|
@@ -184,7 +183,7 @@ module CapistranoSentinel
|
|
184
183
|
final_message = JSON.dump(action: 'message', message: message)
|
185
184
|
end
|
186
185
|
log_to_file("#{@actor.class} sends JSON #{final_message}")
|
187
|
-
|
186
|
+
send_data(final_message)
|
188
187
|
end
|
189
188
|
|
190
189
|
##
|
@@ -193,9 +192,9 @@ module CapistranoSentinel
|
|
193
192
|
#if on windows fork won't be attempted.
|
194
193
|
#+data+:: the data to send
|
195
194
|
#+type+:: :text or :binary, defaults to :text
|
196
|
-
def
|
195
|
+
def send_data(data, type = :text)
|
197
196
|
pid = Thread.new do
|
198
|
-
log_to_file("#{@actor.
|
197
|
+
log_to_file("#{@actor.inspect} calls send: #{data}")
|
199
198
|
do_send(data, type)
|
200
199
|
end
|
201
200
|
end
|
@@ -232,6 +231,8 @@ module CapistranoSentinel
|
|
232
231
|
end
|
233
232
|
end
|
234
233
|
|
234
|
+
|
235
|
+
|
235
236
|
def perform_handshake
|
236
237
|
handshake = ::WebSocket::Handshake::Client.new({
|
237
238
|
:host => @host,
|
@@ -310,7 +311,7 @@ module CapistranoSentinel
|
|
310
311
|
when :binary, :text
|
311
312
|
fire_on_message(message.data)
|
312
313
|
when :ping
|
313
|
-
|
314
|
+
send_data(message.data, :pong) if @auto_pong
|
314
315
|
fire_on_ping(message)
|
315
316
|
when :pong
|
316
317
|
fire_on_error(CapistranoSentinel::WsProtocolError.new('Invalid type pong received'))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bogdanRada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket
|