@@ -146,6 +146,11 @@ ENABLE_SECOND_PRECISION_SCHEDULE=false |
||
| 146 | 146 |
# at the expense of time accuracy. |
| 147 | 147 |
#SCHEDULER_FREQUENCY=0.3 |
| 148 | 148 |
|
| 149 |
+# Specify whether events ages should be checked daily or frequently. |
|
| 150 |
+# A value of "normal" checks each day at midnight, while a value of |
|
| 151 |
+# "frequent" adds an option to keep events for 90 seconds and checks every 3 minutes |
|
| 152 |
+SCHEDULER_EXPIRATION_CHECK=normal |
|
| 153 |
+ |
|
| 149 | 154 |
# Use Graphviz for generating diagrams instead of using Google Chart |
| 150 | 155 |
# Tools. Specify a dot(1) command path built with SVG support |
| 151 | 156 |
# enabled. |
@@ -22,6 +22,9 @@ class Agent < ActiveRecord::Base |
||
| 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 | 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] })]
|
| 25 |
+ if ENV['SCHEDULER_EXPIRATION_CHECK'] == 'frequent' |
|
| 26 |
+ EVENT_RETENTION_SCHEDULES.push(["A minute", 60]) |
|
| 27 |
+ end |
|
| 25 | 28 |
|
| 26 | 29 |
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 | 30 |
|
@@ -129,12 +132,18 @@ class Agent < ActiveRecord::Base |
||
| 129 | 132 |
end |
| 130 | 133 |
|
| 131 | 134 |
def new_event_expiration_date |
| 132 |
- keep_events_for > 0 ? keep_events_for.days.from_now : nil |
|
| 135 |
+ if keep_events_for == 60 |
|
| 136 |
+ 90.seconds.from_now |
|
| 137 |
+ else |
|
| 138 |
+ keep_events_for > 0 ? keep_events_for.days.from_now : nil |
|
| 139 |
+ end |
|
| 133 | 140 |
end |
| 134 | 141 |
|
| 135 | 142 |
def update_event_expirations! |
| 136 | 143 |
if keep_events_for == 0 |
| 137 | 144 |
events.update_all :expires_at => nil |
| 145 |
+ elsif keep_events_for == 60 |
|
| 146 |
+ events.update_all "expires_at = " + rdbms_date_add("created_at", "SECOND", 90)
|
|
| 138 | 147 |
else |
| 139 | 148 |
events.update_all "expires_at = " + rdbms_date_add("created_at", "DAY", keep_events_for.to_i)
|
| 140 | 149 |
end |
@@ -114,8 +114,14 @@ class HuginnScheduler |
||
| 114 | 114 |
end |
| 115 | 115 |
|
| 116 | 116 |
# Schedule event cleanup. |
| 117 |
- @rufus_scheduler.cron "0 0 * * * " + tzinfo_friendly_timezone do |
|
| 118 |
- cleanup_expired_events! |
|
| 117 |
+ if ENV['SCHEDULER_EXPIRATION_CHECK'] == 'normal' |
|
| 118 |
+ @rufus_scheduler.cron "0 0 * * * " + tzinfo_friendly_timezone do |
|
| 119 |
+ cleanup_expired_events! |
|
| 120 |
+ end |
|
| 121 |
+ elsif ENV['SCHEDULER_EXPIRATION_CHECK'] == 'frequent' |
|
| 122 |
+ @rufus_scheduler.every '3m' do |
|
| 123 |
+ cleanup_expired_events! |
|
| 124 |
+ end |
|
| 119 | 125 |
end |
| 120 | 126 |
|
| 121 | 127 |
# Schedule failed job cleanup. |