crabfarm 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c6a40d52475ec34390f4dca75207062dfdae26b
4
- data.tar.gz: 9b298a6d3b4eb50d42eb153c274b638dff02ed63
3
+ metadata.gz: bb3be13182df3bfb8b36dbf9561680f76b0a8c4a
4
+ data.tar.gz: f2dfc98fd27fc4523ea715ec8dd811a98977237d
5
5
  SHA512:
6
- metadata.gz: f2ecc793d6ec88e0dba2cbd806195fc1c94785cefcea02a4384ca0a7a2e5fd5df983e35bf9a1488b8383251122191a30d6222f2a5796f259bcdf009bd3a4a8ef
7
- data.tar.gz: 65763873d5038ad0eacb535732c9f0e395f91959b5328eb1726d3bd3e4aa7ee3af77bd5d6f93e398b4a60406f099a89e5952e61ff49e7d7d133524551e67a274
6
+ metadata.gz: db1a6932c2ff5645f3dfe8c77c3e092a39fd9c43ad52293098180cff4f5732cc1b7cd71eb5460556fcb56de456d11592a2ba04d5681bad4e198552fab12aa71d
7
+ data.tar.gz: 81b972f5cec55ba61d90ec943944ad17524b20fc199dbab37fad746a26de62631f18680efcc6f67cc12c03f1b383ca9ce800aa91f8d44df300e4579a57e1bdb3
data/lib/crabfarm/cli.rb CHANGED
@@ -32,6 +32,9 @@ module Crabfarm
32
32
  c.desc "Set the server min and max threads, defaults to 0:16"
33
33
  c.flag [:t,:threads]
34
34
 
35
+ c.desc "Start the server in verbose mode"
36
+ c.switch :verbose, :default_value => false
37
+
35
38
  c.desc "Activate code reload before every request"
36
39
  c.switch :reload, :default_value => true
37
40
 
@@ -45,6 +48,7 @@ module Crabfarm
45
48
  server_options[:Host] = options[:host] unless options[:host].nil?
46
49
  server_options[:Port] = options[:port] || 3100
47
50
  server_options[:Threads] = options[:threads] unless options[:threads].nil?
51
+ server_options[:Verbose] = options[:verbose]
48
52
 
49
53
  ActiveSupport::Dependencies.mechanism = :require unless options[:reload]
50
54
  Crabfarm.config.set Support::GLI.parse_options options
@@ -21,13 +21,18 @@ module Crabfarm
21
21
 
22
22
  def change_state(_name, _params={}, _wait=nil)
23
23
  @lock.synchronize {
24
- raise StillWorkingError.new if @working
25
- # TODO: test class reloading here?
26
- @next_state_name = _name
27
- @next_state_params = _params
28
- @working = true
24
+ if @working
25
+ raise StillWorkingError.new unless matches_next_state? _name, _params
26
+ wait_and_load_struct _wait
27
+ elsif matches_current_state? _name, _params
28
+ state_as_struct
29
+ else
30
+ @next_state_name = _name
31
+ @next_state_params = _params
32
+ @working = true
29
33
 
30
- wait_and_load_struct _wait
34
+ wait_and_load_struct _wait
35
+ end
31
36
  }
32
37
  end
33
38
 
@@ -50,6 +55,14 @@ module Crabfarm
50
55
 
51
56
  private
52
57
 
58
+ def matches_current_state?(_name, _params)
59
+ _name == @state_name and _params == @state_params
60
+ end
61
+
62
+ def matches_next_state?(_name, _params)
63
+ _name == @next_state_name and _params == @next_state_params
64
+ end
65
+
53
66
  def wait_and_load_struct(_wait)
54
67
  # need to use this method because mutex are not reentrant and monitors are slow.
55
68
  wait_while_working _wait unless _wait.nil?
@@ -90,9 +103,11 @@ module Crabfarm
90
103
  end
91
104
  end.real
92
105
 
93
- @state_name = @next_state_name
94
- @state_params = @next_state_params
95
- @working = false
106
+ @lock.synchronize {
107
+ @state_name = @next_state_name
108
+ @state_params = @next_state_params
109
+ @working = false
110
+ }
96
111
  else sleep 0.2 end
97
112
  end
98
113
  end
@@ -37,7 +37,7 @@ module Crabfarm
37
37
  {
38
38
  exception: @exc,
39
39
  backtrace: @trace
40
- }
40
+ }.to_json
41
41
  end
42
42
  end
43
43
 
@@ -18,7 +18,7 @@ module Crabfarm
18
18
  end
19
19
 
20
20
  rescue_from Crabfarm::ApiError do |e|
21
- rack_response(e.to_json.to_json, e.code)
21
+ rack_response(e.to_json, e.code)
22
22
  end
23
23
 
24
24
  helpers do
@@ -1,3 +1,3 @@
1
1
  module Crabfarm
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crabfarm
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
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 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: jbuilder