cangrejo 0.0.2 → 0.0.3

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: f828edd2bbf18691852e6df23d67090f8c0d20f2
4
- data.tar.gz: 0ca8abeeaa9517af061b316825043b39a6f4ffc2
3
+ metadata.gz: ae3ceddcc75aa3488d8b945009a725259487023d
4
+ data.tar.gz: 4f0fc0a1386cdf9af7f9eaa362d5e884255bea19
5
5
  SHA512:
6
- metadata.gz: d45dfc802d608466a0ef26ae519ca0b65150980e013eaac69f17363e7d121e0ae503bba201aee6c3c7f6775b216cb9b9c44b2c0778960339d535b8bc9267dafe
7
- data.tar.gz: e9173a0c7cbc3f52132ff8c40d2a4d616efc954728189e09af2a2ec2b13c75190742f7be8fbd690e064e1d7d32a660f537b0949eec7de1e8860e8547e4207db8
6
+ metadata.gz: 3d5296989ab3ec15c8a190d46736fb518e16feac5caecfdedf06ccbbb71d2e7f5f9cf139dcd5269b500fb2074dbe9c9e42374bee53787100c108e4391a5d6d5c
7
+ data.tar.gz: 2d43b279a9c7a37b7fbc60e28c6c10979d219a54c661c7f8a97ccc364295fdfa36f6bbbdf7ef80ed706672a094e3235a6d96e24e22788fc195c62acae589e6ae
@@ -16,7 +16,7 @@ module Cangrejo
16
16
  end
17
17
 
18
18
  def release
19
- @launcher.kill
19
+ @launcher.kill unless @launcher.nil?
20
20
  end
21
21
 
22
22
  private
@@ -1,3 +1,5 @@
1
+ require 'net/http'
2
+
1
3
  module Net
2
4
  # Overrides the connect method to simply connect to a unix domain socket.
3
5
  class SocketHttp < HTTP
@@ -3,7 +3,9 @@ require "ostruct"
3
3
  module Cangrejo
4
4
  class Session
5
5
 
6
- attr_reader :doc
6
+ WAIT_STEP = 45.0 # Ruby sockets automatically timeout after 60 secs
7
+
8
+ attr_reader :doc, :state_name, :state_params
7
9
 
8
10
  def initialize(_name, _options={})
9
11
  @name = _name
@@ -18,12 +20,8 @@ module Cangrejo
18
20
  self
19
21
  end
20
22
 
21
- def state_name
22
- @rest.name
23
- end
24
-
25
- def state_params
26
- @rest.params
23
+ def elapsed
24
+ @rest.elapsed
27
25
  end
28
26
 
29
27
  def raw_doc
@@ -32,8 +30,16 @@ module Cangrejo
32
30
 
33
31
  def crawl(_state, _params={})
34
32
  raise ConfigurationError.new 'Session not started' if @rest.nil?
35
- @rest.put(name: _state, params: _params)
36
- @doc = OpenStruct.new @rest.doc
33
+
34
+ params = add_timestamp(_params)
35
+
36
+ while_times_out do
37
+ @rest.put(name: _state, params: params, wait: WAIT_STEP)
38
+ @state_name = _state
39
+ @state_params = _params
40
+ end
41
+
42
+ wrap_response_doc
37
43
  self
38
44
  end
39
45
 
@@ -44,8 +50,31 @@ module Cangrejo
44
50
 
45
51
  private
46
52
 
53
+ def add_timestamp(_params)
54
+ _params.merge({
55
+ '_ts' => DateTime.now.strftime('%Q')
56
+ })
57
+ end
58
+
59
+ def while_times_out
60
+ loop do
61
+ begin
62
+ yield
63
+ break
64
+ rescue RestClient::RequestTimeout
65
+ # retry on timeout
66
+ end
67
+ end
68
+ end
69
+
70
+ def wrap_response_doc
71
+ @doc = OpenStruct.new @rest.doc
72
+ end
73
+
47
74
  def select_mode(_options)
48
- @mode = if _options.has_key? :path
75
+ @mode = if _options.has_key? :mode
76
+ _options[:mode]
77
+ elsif _options.has_key? :path
49
78
  require "cangrejo/modes/local"
50
79
  Modes::Local.new _options[:path]
51
80
  elsif _options.has_key? :git_remote
@@ -14,7 +14,7 @@ module Cangrejo
14
14
  def launch
15
15
  gem_path = File.join(@path, 'Gemfile')
16
16
  # TODO: for some reason, the gemfile path must be specified here, maybe because of rbenv?
17
- @pid = Process.spawn({ 'BUNDLE_GEMFILE' => gem_path }, "bin/crabfarm s --host #{host}", chdir: @path)
17
+ @pid = Process.spawn({ 'BUNDLE_GEMFILE' => gem_path }, "bin/crabfarm s --host #{host} --no-reload", chdir: @path)
18
18
  wait_for_socket
19
19
  end
20
20
 
@@ -1,3 +1,3 @@
1
1
  module Cangrejo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cangrejo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client