serfx 0.0.8 → 0.0.9
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 +4 -4
- data/.travis.yml +0 -1
- data/README.md +11 -1
- data/lib/serfx/utils/async_job.rb +19 -12
- data/lib/serfx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dd4d0d83c82dae09204307da9088059768c893f
|
4
|
+
data.tar.gz: 09a78e804e6b5067ea17b7cc46e493eb7de24935
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc00a2d6c5c365ceda4699e36824a16713bba12cc72ce3662b19f6fe993f77280e13482ae7312c5d85062c55c6b994c16c0ce6cca1ed57d0c1fa69d626bcdde7
|
7
|
+
data.tar.gz: 84791215060afa1b18980f66a9fbb335e9bc536b14f952e2e8ca5ef73558c306a55d6cd036947d9acf99b5c120ae06159ba44a69cd878c912f2c40f15fc65359
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -154,11 +154,21 @@ Serfx.client(host: 'serf1.example.com', port: 7373, authkey: 'secret')
|
|
154
154
|
[Detailed api documentation][api-doc] is accessible via rubydoc.
|
155
155
|
[api-doc]: http://rubydoc.info/gems/serfx
|
156
156
|
|
157
|
+
## Note
|
158
|
+
Currently the response of `members` RPC method returns the ipaddress of cluster members as byte array. You can use `unpack` method to convert it to string.
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
Serfx.client(host: 'serf1.example.com') do |conn|
|
162
|
+
response = conn.members
|
163
|
+
puts response.body['Members'].first['Addr'] # first member's IP in bytes
|
164
|
+
puts response.body['Members'].first['Addr'].unpack('CCCC').join('.') # Same as string
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
157
168
|
## Supported ruby versions
|
158
169
|
|
159
170
|
Serfx aims to support and is [tested against][serfx-travis] the following Ruby implementations:
|
160
171
|
|
161
|
-
* *Ruby 1.9.2*
|
162
172
|
* *Ruby 1.9.3*
|
163
173
|
* *Ruby 2.0.0*
|
164
174
|
* *Ruby 2.1.0*
|
@@ -8,20 +8,20 @@ module Serfx
|
|
8
8
|
# in progress. Due to this, long running tasks should not be
|
9
9
|
# invoked as serf handler directly.
|
10
10
|
#
|
11
|
-
# AsyncJob helps
|
11
|
+
# AsyncJob helps building serf handlers that involve long running commands.
|
12
12
|
# It starts the command in background, allowing handler code to
|
13
13
|
# return immediately. It does double fork where the first child process is
|
14
14
|
# detached (attached to init as parent process) and and the target long
|
15
15
|
# running task is spawned as a second child process. This allows the first
|
16
16
|
# child process to wait and reap the output of actual long running task.
|
17
17
|
#
|
18
|
-
# The first child process updates a state file before
|
19
|
-
# the long ranning task(state='invoking'), during the
|
18
|
+
# The first child process updates a state file before spawning
|
19
|
+
# the long ranning task(state='invoking'), during the long running task
|
20
20
|
# execution (state='running') and after the spawned process' return
|
21
21
|
# (state='finished'). This state file provides a convenient way to
|
22
22
|
# query the current state of an AsyncJob.
|
23
23
|
#
|
24
|
-
# AsyncJob
|
24
|
+
# AsyncJob provides four methods to manage jobs. AsyncJob#start will
|
25
25
|
# start the task. Once started, AyncJob#state_info can be used to check
|
26
26
|
# whether the job is still running or finished. One started a job can be
|
27
27
|
# either in 'running' state or in 'finished' state. AsyncJob#reap
|
@@ -30,6 +30,10 @@ module Serfx
|
|
30
30
|
# AsyncJob#kill method. A new AyncJob can not be started unless previous
|
31
31
|
# AsyncJob with same name/state file is reaped.
|
32
32
|
#
|
33
|
+
# If the state file is nil, no state will be persisted for the job.
|
34
|
+
# As such, AsyncJob#state_info, AsyncJob#kill, and AsyncJob#reap will
|
35
|
+
# be a NO-OP.
|
36
|
+
#
|
33
37
|
# Following is an example of writing a serf handler using AsyncJob.
|
34
38
|
#
|
35
39
|
# @example
|
@@ -86,7 +90,7 @@ module Serfx
|
|
86
90
|
# @option opts [Symbol] :environment a hash containing environment variables
|
87
91
|
# @option opts [Symbol] :cwd a string (directory path) containing current directory of the command
|
88
92
|
def initialize(opts = {})
|
89
|
-
@state_file = opts[:state]
|
93
|
+
@state_file = opts[:state]
|
90
94
|
@command = opts[:command]
|
91
95
|
@stdout_file = opts[:stdout] || File::NULL
|
92
96
|
@stderr_file = opts[:stderr] || File::NULL
|
@@ -96,12 +100,13 @@ module Serfx
|
|
96
100
|
|
97
101
|
# kill an already running task
|
98
102
|
#
|
99
|
-
# @param sig [String] kill signal that will sent to the
|
103
|
+
# @param sig [String] kill signal that will sent to the background process
|
100
104
|
# @return [TrueClass,FalseClass] true on success, false on failure
|
101
105
|
def kill(sig = 'KILL')
|
102
106
|
if running?
|
103
107
|
begin
|
104
108
|
Process.kill(sig, stateinfo['pid'].to_i)
|
109
|
+
File.unlink(state_file) if File.exist?(state_file)
|
105
110
|
'success'
|
106
111
|
rescue Exception
|
107
112
|
'failed'
|
@@ -111,7 +116,7 @@ module Serfx
|
|
111
116
|
end
|
112
117
|
end
|
113
118
|
|
114
|
-
# obtain current state information about the task as
|
119
|
+
# obtain current state information about the task as JSON
|
115
120
|
#
|
116
121
|
# @return [String] JSON string representing current state of the task
|
117
122
|
def state_info
|
@@ -129,7 +134,7 @@ module Serfx
|
|
129
134
|
JSON.parse(state_info)
|
130
135
|
end
|
131
136
|
|
132
|
-
# delete the
|
137
|
+
# delete the state file of a finished task
|
133
138
|
#
|
134
139
|
# @return [String] 'success' if the task is reaped, 'failed' otherwise
|
135
140
|
def reap
|
@@ -203,14 +208,16 @@ module Serfx
|
|
203
208
|
#
|
204
209
|
# @return [TrueClass, FalseClass] true if the task exists, else false
|
205
210
|
def exists?
|
206
|
-
File.exist?(state_file)
|
211
|
+
state_file.nil? ? false : File.exist?(state_file)
|
207
212
|
end
|
208
213
|
|
209
|
-
# writes a hash as
|
214
|
+
# writes a hash as JSON in the state_file
|
210
215
|
# @param [Hash] state represented as a hash, to be written
|
211
216
|
def write_state(state)
|
212
|
-
|
213
|
-
|
217
|
+
if state_file
|
218
|
+
File.open(state_file, 'w') do |f|
|
219
|
+
f.write(JSON.generate(state))
|
220
|
+
end
|
214
221
|
end
|
215
222
|
end
|
216
223
|
end
|
data/lib/serfx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serfx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rnjib Dey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|