aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Houston <robin@lenny.robin>2011-06-21 03:39:29 +0100
committerRobin Houston <robin@lenny.robin>2011-06-21 03:39:29 +0100
commitd1d4c88c33cb2170f26b27b8d34e2280a7b532ff (patch)
tree75875fdb0de7253bee7cf6f488101eea76581204
parent3b29b7c3f65e0c3153fbed0d27f864aaf624a36d (diff)
Add an option to make alert_tracks run continually, rather than just processing whichever alerts are due right now.
-rw-r--r--app/models/track_mailer.rb13
-rwxr-xr-xscript/alert-tracks8
2 files changed, 19 insertions, 2 deletions
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index 89a4f3cad..1b37709b9 100644
--- a/app/models/track_mailer.rb
+++ b/app/models/track_mailer.rb
@@ -101,6 +101,19 @@ class TrackMailer < ApplicationMailer
user.no_xapian_reindex = true
user.save!
end
+ return true
+ end
+
+ def self.alert_tracks_loop
+ # Run alert_tracks in an endless loop, sleeping when there is nothing to do
+ while true
+ sleep_seconds = 1
+ while !alert_tracks
+ sleep sleep_seconds
+ sleep_seconds *= 2
+ sleep_seconds = 300 if sleep_seconds > 300
+ end
+ end
end
end
diff --git a/script/alert-tracks b/script/alert-tracks
index 056a88078..117f7a406 100755
--- a/script/alert-tracks
+++ b/script/alert-tracks
@@ -2,6 +2,10 @@
LOC=`dirname $0`
-$LOC/runner 'TrackMailer.alert_tracks'
-
+if [ "$1" == "--loop" ]
+then
+ "$LOC/runner" 'TrackMailer.alert_tracks_loop'
+else
+ "$LOC/runner" 'TrackMailer.alert_tracks'
+fi