<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -122,7 +122,19 @@ Background tasks in Ruby On Rails made dead simple.
     run &quot;RAILS_ENV=production ruby #{current_path}/script/daemons stop&quot;
     run &quot;RAILS_ENV=production ruby #{current_path}/script/daemons start&quot;
   end
+
+== CONFIGURATION:
+
+  By default, completed background jobs that are more than one week old
+  will be cleaned out of the database on application startup, and the daemon
+  will check for queued background jobs every 5 seconds.
   
+  To override these settings, modify your config/daemons.yml file:
+  
+  background_fu:
+    cleanup_interval: :on_startup # :on_startup | :continuous
+    monitor_interval: 5           # Check every x seconds
+
 == BONUS FEATURES:
 
 There are bonus features available if you set</diff>
      <filename>README.txt</filename>
    </modified>
    <modified>
      <diff>@@ -4,19 +4,20 @@ require File.dirname(__FILE__) + &quot;/../../config/environment&quot;
 
 Signal.trap(&quot;TERM&quot;) { exit }
 
-if Job.included_modules.include?(Job::BonusFeatures)
-  RAILS_DEFAULT_LOGGER.info(&quot;BackgroundFu: Starting daemon (bonus features enabled).&quot;)
-else
-  RAILS_DEFAULT_LOGGER.info(&quot;BackgroundFu: Starting daemon (bonus features disabled).&quot;)
+RAILS_DEFAULT_LOGGER.info(&quot;BackgroundFu: Starting daemon (bonus features #{Job.included_modules.include?(Job::BonusFeatures) ? &quot;enabled&quot; : &quot;disabled&quot;}).&quot;)
+
+BackgroundFu::CONFIG.each do |k,v| 
+  RAILS_DEFAULT_LOGGER.info &quot;BackgroundFu: #{k}: #{v.to_s}&quot;
 end
 
+Job.cleanup_finished_jobs if BackgroundFu::CONFIG['cleanup_interval'] == :at_start
+
 loop do
   if job = Job.find(:first, :conditions =&gt; [&quot;state='pending' and start_at &lt;= ?&quot;, Time.now], :order =&gt; &quot;priority desc, start_at asc&quot;)
     job.get_done!
   else
     RAILS_DEFAULT_LOGGER.info(&quot;BackgroundFu: Waiting for jobs...&quot;)
-    sleep 5
+    sleep BackgroundFu::CONFIG['monitor_interval']
   end
-  
-  Job.destroy_all([&quot;state='finished' and updated_at &lt; ?&quot;, 1.week.ago])
+  Job.cleanup_finished_jobs if BackgroundFu::CONFIG['cleanup_interval'] == :continuous
 end</diff>
      <filename>generators/background/templates/background.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,3 +3,6 @@ dir: ../../log
 multiple: false
 backtrace: true
 monitor: true
+background_fu:
+  cleanup_interval: :on_startup # :on_startup or :continuous
+  monitor_interval: 5           # seconds between checks for queued jobs</diff>
      <filename>generators/background/templates/daemons.yml</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,8 @@
 module BackgroundFu
   
   VERSION = &quot;1.0.10&quot;
+  CONFIG = YAML::load(File.open(&quot;#{RAILS_ROOT}/config/daemons.yml&quot;))['background_fu'] || {}
+  CONFIG['cleanup_interval'] ||= :on_startup
+  CONFIG['monitor_interval'] ||= 10
   
 end</diff>
      <filename>lib/background_fu.rb</filename>
    </modified>
    <modified>
      <diff>@@ -76,6 +76,12 @@ class Job &lt; ActiveRecord::Base
     logger.info(&quot;BackgroundFu: Race condition handled (It's OK). Job(id: #{id}).&quot;)
   end
 
+  # Delete finished jobs that are more than a week old.
+  def self.cleanup_finished_jobs
+    logger.info &quot;BackgroundFu: Cleaning up finished jobs.&quot;
+    Job.destroy_all([&quot;state='finished' and updated_at &lt; ?&quot;, 1.week.ago])
+  end
+  
   def self.generate_state_helpers
     states.each do |state_name|
       define_method(&quot;#{state_name}?&quot;) do</diff>
      <filename>lib/job.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f3753bb751a366f8b1844c17da80235fe04a986a</id>
    </parent>
  </parents>
  <author>
    <name>Corey</name>
    <email>corey@seologic.com</email>
  </author>
  <url>http://github.com/ncr/background-fu/commit/f16070c4232c03efaaf75a777a17afd8d5161fed</url>
  <id>f16070c4232c03efaaf75a777a17afd8d5161fed</id>
  <committed-date>2009-03-04T23:40:32-08:00</committed-date>
  <authored-date>2009-03-04T21:02:13-08:00</authored-date>
  <message>Added ability to configure job check and job cleanup intervals through settings in config/daemons.yml. Updated README.txt includes instructions for overriding these defaults. Judicious use of these settings allows for reduction in number of ongoing database calls.

Signed-off-by: Jacek Becela &lt;jacek.becela@gmail.com&gt;</message>
  <tree>9bdec4ced4ff2c214cd04a040621da5ffa5e2a6b</tree>
  <committer>
    <name>Jacek Becela</name>
    <email>jacek.becela@gmail.com</email>
  </committer>
</commit>
