ngauthier-active-listener 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +27 -0
- data/VERSION.yml +1 -1
- data/lib/active-listener.rb +1 -1
- metadata +4 -7
data/README.markdown
CHANGED
@@ -44,6 +44,33 @@ Create a file in the initializers directory, like RAILS_ROOT/config/initializers
|
|
44
44
|
|
45
45
|
This will use the config file "config/active-listener.yml". It will put the log file in "log/active-listener.log" and the pid file for tracking the process in "log/active-listener.pid".
|
46
46
|
|
47
|
+
### Special Handling of ActiveListener rake tasks that depend on the rails environment
|
48
|
+
The scheme devised in the previous sections will generate an infinite loop if your Active Listener rake task(s) depend(s) on the rails environment being loaded. This occurs because we have added the initializer code into config/initializers, which gets loaded every time the environment is loaded. In order to avoid this, we can set a global variable that is queried in the initializer, providing conditional load behavior. Now, our initializer looks like this:
|
49
|
+
|
50
|
+
if RAILS_ENV == "production" && !$active_listener_activated
|
51
|
+
require 'active-listener'
|
52
|
+
ActiveListener.autostart(
|
53
|
+
:config => File.join(RAILS_ROOT, 'config', 'active-listener.yml'),
|
54
|
+
:log_file => File.join(RAILS_ROOT, 'log', "active-listener-#{RAILS_ENV}.log"),
|
55
|
+
:pid_file => File.join(RAILS_ROOT, 'log', "active-listener-#{RAILS_ENV}.pid"),
|
56
|
+
:rake_root => File.join(RAILS_ROOT)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
And our Active Listener rake task (found in lib/tasks/active-listener.rake) looks like:
|
61
|
+
|
62
|
+
desc "Helper to preclude infinite loop when a listener task depends on the rails environment"
|
63
|
+
task :set_active_listener_active do
|
64
|
+
$active_listener_activated = true
|
65
|
+
end
|
66
|
+
|
67
|
+
namespace :listeners do
|
68
|
+
desc "Close games that have ended"
|
69
|
+
task :game_end => [:set_active_listener_active, :environment] do
|
70
|
+
# Logic as dictated by your app's needs
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
47
74
|
## Usage
|
48
75
|
|
49
76
|
Active Listener will automatically start whenever the rails environment is loaded. It will replace an existing instance of active-listener if the pid file is the same and there is one running.
|
data/VERSION.yml
CHANGED
data/lib/active-listener.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ngauthier-active-listener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Gauthier
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-02-08 00:00:00 -08:00
|
13
13
|
default_executable: active-listener
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,16 +22,13 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
- VERSION.yml
|
26
25
|
- README.markdown
|
26
|
+
- VERSION.yml
|
27
27
|
- bin/active-listener
|
28
|
-
- lib/activelistener
|
29
28
|
- lib/active-listener.rb
|
30
|
-
- test/test_helper.rb
|
31
|
-
- test/active_listener.log
|
32
|
-
- test/active_listener.pid
|
33
29
|
- test/active_listener.yml
|
34
30
|
- test/active_listener_test.rb
|
31
|
+
- test/test_helper.rb
|
35
32
|
has_rdoc: true
|
36
33
|
homepage: http://github.com/ngauthier/active-listener
|
37
34
|
post_install_message:
|