diff options
author | Alex Legler <alex@a3li.li> | 2014-04-17 18:41:16 +0200 |
---|---|---|
committer | Alex Legler <alex@a3li.li> | 2014-04-17 18:41:16 +0200 |
commit | cd5e000195d4afaadaa227e9d6b92580d1573fed (patch) | |
tree | 1db74cf812c756ae515fcbc513e2610281723fdd /lib | |
parent | Set <title> when displaying a notice (diff) | |
download | infra-status-cd5e000195d4afaadaa227e9d6b92580d1573fed.tar.gz infra-status-cd5e000195d4afaadaa227e9d6b92580d1573fed.tar.bz2 infra-status-cd5e000195d4afaadaa227e9d6b92580d1573fed.zip |
Implement starts_at
start_at marks the date when an event (maintenance usually) described in the notice starts.
This is then the date when effects like force_state are applied.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/helpers.rb | 11 | ||||
-rw-r--r-- | lib/notice_store.rb | 20 |
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/helpers.rb b/lib/helpers.rb index aaaf632..ec65b37 100644 --- a/lib/helpers.rb +++ b/lib/helpers.rb @@ -20,7 +20,7 @@ helpers do def service_info(service) content = '' - active_notices = NoticeStore.instance.active_notices_for(service) + active_notices = NoticeStore.instance.visible_notices_for(service) unless (forced_state = get_forced_state(active_notices)) == nil content << status_icon(forced_state) @@ -87,4 +87,13 @@ helpers do date.rfc2822 end end + + def humanize(secs) + [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name| + if secs > 0 + secs, n = secs.divmod(count) + "#{n.to_i} #{name}" unless name == :seconds + end + }.compact.reverse.join(' ') + end end
\ No newline at end of file diff --git a/lib/notice_store.rb b/lib/notice_store.rb index 1d29fdd..c3c7093 100644 --- a/lib/notice_store.rb +++ b/lib/notice_store.rb @@ -34,11 +34,23 @@ class NoticeStore @notices end + def visible_notices + notices.select do |notice| + is_active = notice['active'] + is_active &= notice['expire_at'] >= DateTime.now if notice.has_key? 'expire_at' + is_active &= notice['created_at'] <= DateTime.now if notice.has_key? 'created_at' + + is_active + end + + end + def active_notices notices.select do |notice| is_active = notice['active'] is_active &= notice['expire_at'] >= DateTime.now if notice.has_key? 'expire_at' is_active &= notice['created_at'] <= DateTime.now if notice.has_key? 'created_at' + is_active &= notice['starts_at'] <= DateTime.now if notice.has_key? 'starts_at' is_active end @@ -50,6 +62,12 @@ class NoticeStore end end + def visible_notices_for(service) + visible_notices.select do |notice| + notice.has_key? 'affects' and notice['affects'].include? service + end + end + def notice(id) notices.each do |notice| return notice if notice['id'] == id @@ -95,7 +113,7 @@ class Notice def initialize(id, metadata, content) @metadata = metadata - %w[created_at eta expire_at].each do |key| + %w[created_at eta expire_at starts_at].each do |key| @metadata[key] = DateTime.parse(@metadata[key]) if @metadata.has_key? key end |