climax 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -127,9 +127,9 @@ your `main` method completes, any existing events in the queue are processed. Y
127
127
  then called again. This process goes on until the `main` method returns a value other than nil or
128
128
  an `:exit` or `:quit` event is placed in the event queue.
129
129
 
130
- Your application can send events to the climax event queue with the `send_event` method. You must
131
- pass `send_event` the event type (e.g., `:exit` or `:start_remote_debugger`) and you may also
132
- optionally pass a payload (i.e., extra data) as a second parameter.
130
+ Your application can send events to the climax event queue with the `climax_send_event` method. You
131
+ must pass `climax_send_event` the event type (e.g., `:exit` or `:start_remote_debugger`) and you may
132
+ also optionally pass a payload (i.e., extra data) as a second parameter.
133
133
 
134
134
  For example, if you wish for your application to exit in an orderly fashion **after** the current
135
135
  iteration of `main` has had a chance to finish, you can accomplish this by placing an `:exit` event
@@ -143,7 +143,7 @@ off of the queue it will call your `post_main` method and perform other cleanup
143
143
  include Climax::Application
144
144
 
145
145
  def main
146
- send_event(:exit) if about_to_meet_work_quota?
146
+ climax_send_event(:exit) if about_to_meet_work_quota?
147
147
  work = get_some_work
148
148
  do_work(work)
149
149
  return nil
@@ -163,6 +163,9 @@ This is excellent for stopping a long running process without interrupting its w
163
163
  :exit or :quit event, whether through the Control DRb or from your application itself, your
164
164
  application will be allowed to finish processing its current unit of work before exiting.
165
165
 
166
+ For your convenience there is also a 'climax_has_event?' method that returns true only if there are
167
+ events waiting on the event queue.
168
+
166
169
  Generating a New Application
167
170
  ============================
168
171
 
@@ -32,7 +32,7 @@ module Climax
32
32
 
33
33
  def _post_main
34
34
  log.debug "Stopping Control DRb"
35
- @control_drb.stop_service
35
+ DRb.stop_service
36
36
  end
37
37
 
38
38
  def _parse_options
@@ -169,7 +169,7 @@ module Climax
169
169
  unless event.nil?
170
170
  case event.type
171
171
  when :set_log_level then log_level = event.payload
172
- when :stop_control_drb then @control_drb && @control_drb.stop_service
172
+ when :stop_control_drb then DRb.stop_service
173
173
  when :start_remote_debugger then binding.remote_pry rescue nil
174
174
  when :quit, :exit then return 0
175
175
  end
@@ -181,12 +181,18 @@ module Climax
181
181
  end
182
182
  end
183
183
 
184
- def send_event (type, payload=nil)
184
+ def climax_send_event (type, payload=nil)
185
185
  _events_mutex.synchronize {
186
186
  _events.unshift OpenStruct.new(:type => type, :payload => payload)
187
187
  }
188
188
  end
189
189
 
190
+ def climax_has_event?
191
+ _events_mutex.synchronize {
192
+ _events.count > 1
193
+ }
194
+ end
195
+
190
196
  def _events
191
197
  @_events ||= []
192
198
  end
@@ -11,11 +11,11 @@ module Climax
11
11
  end
12
12
 
13
13
  def log_level= (level)
14
- @app.send_event(:set_log_level, level)
14
+ @app.climax_send_event(:set_log_level, level)
15
15
  end
16
16
 
17
17
  def start_debugger
18
- @app.send_event(:start_remote_debugger)
18
+ @app.climax_send_event(:start_remote_debugger)
19
19
  end
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module Climax
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -3,4 +3,16 @@
3
3
  $:.unshift File.expand_path("../../lib", __FILE__)
4
4
  require "rubygems" rescue nil
5
5
  require "<%= name %>"
6
- <%= module_string %>::Application.new(ARGV).run
6
+ app = <%= module_string %>::Application.new(ARGV)
7
+ received_ctrlc = false
8
+ trap("INT") do
9
+ if received_ctrlc == false
10
+ app.log.info "Received Interrupt. Attempting to exit safely. Send Interrupt again to quit abruptly."
11
+ app.climax_send_event(:quit)
12
+ received_ctrlc = true
13
+ else
14
+ app.log.fatal "Aborting!"
15
+ exit 1
16
+ end
17
+ end
18
+ app.run
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: climax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry