serfx 0.0.8 → 0.0.9

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: 93d9b356f7f57d5d478e7029cfd102ba0f4df9c9
4
- data.tar.gz: 56328c5f96c7b274a1b1e9cafd3e6d34cf0ee989
3
+ metadata.gz: 2dd4d0d83c82dae09204307da9088059768c893f
4
+ data.tar.gz: 09a78e804e6b5067ea17b7cc46e493eb7de24935
5
5
  SHA512:
6
- metadata.gz: d00717242ab33e17855a25952e4d75c820e9cfc4b13aa6a3cabde733701bb6736abf00dcf0d15964398c3eba954fdf14135279e4c1196d023e5a12a22d0c63e6
7
- data.tar.gz: b2244787a7fa11cd352b44d74f4ee44dc6b75e47f285fcee053ff1c9e12c448f78d8e1866f3fb63008605a32897fb3b6039e5fa6cdffcca1e0c9327c4884942b
6
+ metadata.gz: cc00a2d6c5c365ceda4699e36824a16713bba12cc72ce3662b19f6fe993f77280e13482ae7312c5d85062c55c6b994c16c0ce6cca1ed57d0c1fa69d626bcdde7
7
+ data.tar.gz: 84791215060afa1b18980f66a9fbb335e9bc536b14f952e2e8ca5ef73558c306a55d6cd036947d9acf99b5c120ae06159ba44a69cd878c912f2c40f15fc65359
@@ -2,7 +2,6 @@ before_install:
2
2
  - bash download_serf
3
3
  - bundle install --path .bundle
4
4
  rvm:
5
- - 1.9.3
6
5
  - 2.0.0
7
6
  - 2.1.0
8
7
  branches:
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 buildng serf handlers that involve long running commands.
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 spawing
19
- # the long ranning task(state='invoking'), during the lon running task
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 porvide four methods to manage jobs. AsyncJob#start will
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] || fail(ArgumentError, 'Specify state file')
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 backgroun process
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 json
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 statefile of a finished task
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 json in the state_file
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
- File.open(state_file, 'w') do |f|
213
- f.write(JSON.generate(state))
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
@@ -2,5 +2,5 @@
2
2
  #
3
3
  # Provides version as a contsant for the serf gem
4
4
  module Serfx
5
- VERSION = '0.0.8'
5
+ VERSION = '0.0.9'
6
6
  end
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.8
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: 2014-10-07 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack