ngauthier-active-listener 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +46 -6
- data/VERSION.yml +1 -1
- data/lib/active-listener.rb +5 -2
- metadata +1 -1
data/README.markdown
CHANGED
@@ -3,22 +3,62 @@
|
|
3
3
|
## Description
|
4
4
|
This gem allows you to define tasks that can be run at specific time intervals. In the future, we plan to allow event listening and firing.
|
5
5
|
|
6
|
-
## Configuration
|
7
|
-
|
8
|
-
### Add a config file
|
9
|
-
|
10
|
-
### Include in your boot
|
11
|
-
|
12
6
|
## Installation
|
13
7
|
|
14
8
|
### Latest Stable
|
9
|
+
|
15
10
|
sudo gem install ngauthier-active-listener
|
16
11
|
|
17
12
|
### Cutting Edge
|
13
|
+
|
18
14
|
git clone git@github.com:ngauthier/active-listener.git active-listener
|
19
15
|
cd active-listener
|
20
16
|
rake gem install
|
21
17
|
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
### Add a config file
|
21
|
+
In your rails project, add a config file like this:
|
22
|
+
|
23
|
+
|
24
|
+
---
|
25
|
+
tasks:
|
26
|
+
- task: my:rake:task
|
27
|
+
period: 5
|
28
|
+
|
29
|
+
|
30
|
+
This instructs active-listener to run "rake my:rake:task" every 5 seconds.
|
31
|
+
|
32
|
+
Usually, these config files go in RAILS_ROOT/config/active-listener.yml.
|
33
|
+
|
34
|
+
### Include an initializer
|
35
|
+
Create a file in the initializers directory, like RAILS_ROOT/config/initializers/active-listener.rb that has this in it:
|
36
|
+
|
37
|
+
require 'active-listener'
|
38
|
+
ActiveListener.autostart(
|
39
|
+
:config => File.join(RAILS_ROOT, 'config', 'active-listener.yml'),
|
40
|
+
:log_file => File.join(RAILS_ROOT, 'log', 'active-listener-'+RAILS_ENV+'.log'),
|
41
|
+
:pid_file => File.join(RAILS_ROOT, 'log', 'active-listener-'+RAILS_ENV+'.pid'),
|
42
|
+
:rake_root => File.join(RAILS_ROOT)
|
43
|
+
)
|
44
|
+
|
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
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
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.
|
50
|
+
|
51
|
+
So, you don't need to run the executable, it will "autostart" thanks to the initializer. Keep in mind this means that it will be running during your tests, development server, production, and any other environments you have. If you run your tests, the daemon keeps going after the tests are done. It doesn't stop when the server stops.
|
52
|
+
|
53
|
+
If you run your tests and you run the app in dev mode, there will be two instances running simultaneously and they'll both be running the tasks (but in the appropriate environment).
|
54
|
+
|
55
|
+
If you want to stop active-listener, run:
|
56
|
+
|
57
|
+
active-listener --stop log/active-listener.pid
|
58
|
+
|
59
|
+
Make sure to point it to your pid file.
|
60
|
+
|
61
|
+
|
22
62
|
## Other notes
|
23
63
|
This gem uses Jeweler.
|
24
64
|
|
data/VERSION.yml
CHANGED
data/lib/active-listener.rb
CHANGED
@@ -79,8 +79,11 @@ class ActiveListener
|
|
79
79
|
def fire(opts = {})
|
80
80
|
self.last_fire = Time.now.to_f
|
81
81
|
Dir.chdir(opts[:rake_root]) if opts[:rake_root]
|
82
|
-
|
83
|
-
|
82
|
+
begin
|
83
|
+
`RAILS_ENV=#{RAILS_ENV} rake #{task}`
|
84
|
+
rescue
|
85
|
+
`rake #{task}`
|
86
|
+
end
|
84
87
|
end
|
85
88
|
|
86
89
|
private
|