more work on cleanup time

stvnrlly 9 years ago
parent
commit
0d7069adbf
3 changed files with 5 additions and 11 deletions
  1. 1 1
      .env.example
  2. 3 9
      app/models/agent.rb
  3. 1 1
      lib/huginn_scheduler.rb

+ 1 - 1
.env.example

@@ -148,7 +148,7 @@ ENABLE_SECOND_PRECISION_SCHEDULE=false
148 148
 
149 149
 # Specify the frequency with which the scheduler checks for event expiration.
150 150
 # You can use `m` for minutes, `h` for hours, and `d` for days.
151
-EVENT_EXPIRATION_CHECK="3h"
151
+EVENT_EXPIRATION_CHECK=3h
152 152
 
153 153
 # Use Graphviz for generating diagrams instead of using Google Chart
154 154
 # Tools.  Specify a dot(1) command path built with SVG support

+ 3 - 9
app/models/agent.rb

@@ -21,7 +21,7 @@ class Agent < ActiveRecord::Base
21 21
   SCHEDULES = %w[every_1m every_2m every_5m every_10m every_30m every_1h every_2h every_5h every_12h every_1d every_2d every_7d
22 22
                  midnight 1am 2am 3am 4am 5am 6am 7am 8am 9am 10am 11am noon 1pm 2pm 3pm 4pm 5pm 6pm 7pm 8pm 9pm 10pm 11pm never]
23 23
 
24
-  EVENT_RETENTION_SCHEDULES = [["Forever", 0], ["1 day", 1], *([2, 3, 4, 5, 7, 14, 21, 30, 45, 90, 180, 365].map {|n| ["#{n} days", n] })]
24
+  EVENT_RETENTION_SCHEDULES = [["Forever", 0], ['1 hour', 1.hour], ['6 hours', 6.hours], ["1 day", 1.day], *([2, 3, 4, 5, 7, 14, 21, 30, 45, 90, 180, 365].map {|n| ["#{n} days", n.days] })]
25 25
 
26 26
   attr_accessible :options, :memory, :name, :type, :schedule, :controller_ids, :control_target_ids, :disabled, :source_ids, :scenario_ids, :keep_events_for, :propagate_immediately, :drop_pending_events
27 27
 
@@ -129,20 +129,14 @@ class Agent < ActiveRecord::Base
129 129
   end
130 130
 
131 131
   def new_event_expiration_date
132
-    if keep_events_for == 60
133
-      90.seconds.from_now
134
-    else
135
-      keep_events_for > 0 ? keep_events_for.days.from_now : nil
136
-    end
132
+    keep_events_for > 0 ? keep_events_for.seconds.from_now : nil
137 133
   end
138 134
 
139 135
   def update_event_expirations!
140 136
     if keep_events_for == 0
141 137
       events.update_all :expires_at => nil
142
-    elsif keep_events_for == 60
143
-      events.update_all "expires_at = " + rdbms_date_add("created_at", "SECOND", 90)
144 138
     else
145
-      events.update_all "expires_at = " + rdbms_date_add("created_at", "DAY", keep_events_for.to_i)
139
+      events.update_all "expires_at = " + rdbms_date_add("created_at", "SECOND", keep_events_for.to_i)
146 140
     end
147 141
   end
148 142
 

+ 1 - 1
lib/huginn_scheduler.rb

@@ -114,7 +114,7 @@ class HuginnScheduler
114 114
     end
115 115
 
116 116
     # Schedule event cleanup.
117
-    @rufus_scheduler.every ENV['EVENT_EXPIRATION_CHECK'] do
117
+    @rufus_scheduler.every ENV['EVENT_EXPIRATION_CHECK'].presence || '6h' do
118 118
       cleanup_expired_events!
119 119
     end
120 120