From 8e154325172f8a1018a9032b6ea65822d65f2f28 Mon Sep 17 00:00:00 2001 From: Marcel Hild Date: Mon, 13 Mar 2017 17:44:24 +0100 Subject: [PATCH 1/2] always pass valid date format --- .../shared/automation_manager/event_catcher/stream.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/event_catcher/stream.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/event_catcher/stream.rb index 95cd34a1164..8c81bf07ad7 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/event_catcher/stream.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/event_catcher/stream.rb @@ -30,9 +30,10 @@ def poll private def filter + timestamp = @last_activity ? Time.zone.parse(@last_activity.timestamp) : 1.minute.ago { :order_by => 'timestamp', - :timestamp__gt => @last_activity ? @last_activity.timestamp : 1.minute.ago.to_s(:db) + :timestamp__gt => timestamp.to_s(:db) } end end From f068c8320e792c71312cf1fec1d6881ebc8a341d Mon Sep 17 00:00:00 2001 From: Marcel Hild Date: Fri, 17 Mar 2017 19:45:14 +0100 Subject: [PATCH 2/2] added specs for timestamp conversion --- .../automation_manager/event_catcher/stream.rb | 2 +- .../automation_manager/event_catcher/stream.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/event_catcher/stream.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/event_catcher/stream.rb index 8c81bf07ad7..41bc830c3bd 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/event_catcher/stream.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/event_catcher/stream.rb @@ -30,7 +30,7 @@ def poll private def filter - timestamp = @last_activity ? Time.zone.parse(@last_activity.timestamp) : 1.minute.ago + timestamp = @last_activity ? Time.zone.parse(@last_activity.timestamp.to_s) : 1.minute.ago { :order_by => 'timestamp', :timestamp__gt => timestamp.to_s(:db) diff --git a/spec/support/ansible_shared/automation_manager/event_catcher/stream.rb b/spec/support/ansible_shared/automation_manager/event_catcher/stream.rb index ca26b273dfe..c00d20682f3 100644 --- a/spec/support/ansible_shared/automation_manager/event_catcher/stream.rb +++ b/spec/support/ansible_shared/automation_manager/event_catcher/stream.rb @@ -66,4 +66,19 @@ end end end + + context ".filter" do + it "converts timestamp to correct timeformat" do + # It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] + timestamps = { + '2016-01-01 01:00:00' => '2016-01-01 01:00:00', + '2017-03-10 19%3A31%3A26' => '2017-03-10 00:00:00', + Time.zone.parse('1975-12-31 01:01:01') => '1975-12-31 01:01:01', + } + timestamps.each do |input, converted| + subject.instance_variable_set(:@last_activity, OpenStruct.new(:timestamp => input)) + expect(subject.send(:filter)[:timestamp__gt]).to eq(converted) + end + end + end end