From 275e01ff59a95e068ee250001a259254ff65a83a Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 6 Jun 2017 07:56:50 +0100 Subject: [PATCH] include last_defer timestamp when deferring a job --- lib/App/Netdisco/DB.pm | 2 +- lib/App/Netdisco/DB/Result/DeviceSkip.pm | 9 +++++++-- .../schema_versions/App-Netdisco-DB-42-43-PostgreSQL.sql | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 share/schema_versions/App-Netdisco-DB-42-43-PostgreSQL.sql diff --git a/lib/App/Netdisco/DB.pm b/lib/App/Netdisco/DB.pm index a6272a1e..3bc1c06b 100644 --- a/lib/App/Netdisco/DB.pm +++ b/lib/App/Netdisco/DB.pm @@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces( ); our # try to hide from kwalitee - $VERSION = 42; # schema version used for upgrades, keep as integer + $VERSION = 43; # schema version used for upgrades, keep as integer use Path::Class; use File::ShareDir 'dist_dir'; diff --git a/lib/App/Netdisco/DB/Result/DeviceSkip.pm b/lib/App/Netdisco/DB/Result/DeviceSkip.pm index bed6f17b..fc4385e8 100644 --- a/lib/App/Netdisco/DB/Result/DeviceSkip.pm +++ b/lib/App/Netdisco/DB/Result/DeviceSkip.pm @@ -14,9 +14,11 @@ __PACKAGE__->add_columns( "device", { data_type => "inet", is_nullable => 0 }, "actionset", - { data_type => "text[]", is_nullable => 0, default_value => '{}' }, + { data_type => "text[]", is_nullable => 1, default_value => '{}' }, "deferrals", { data_type => "integer", is_nullable => 1, default_value => '0' }, + "last_defer", + { data_type => "timestamp", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("backend", "device"); @@ -36,7 +38,10 @@ There is a race in the update, but this is not worrying for now. sub increment_deferrals { my $row = shift; return unless $row->in_storage; - return $row->update({ deferrals => (($row->deferrals || 0) + 1) }); + return $row->update({ + deferrals => (($row->deferrals || 0) + 1), + last_defer => \'now()', + }); } =head2 add_to_actionset diff --git a/share/schema_versions/App-Netdisco-DB-42-43-PostgreSQL.sql b/share/schema_versions/App-Netdisco-DB-42-43-PostgreSQL.sql new file mode 100644 index 00000000..a723fea8 --- /dev/null +++ b/share/schema_versions/App-Netdisco-DB-42-43-PostgreSQL.sql @@ -0,0 +1,5 @@ +BEGIN; + +ALTER TABLE "device_skip" ADD "last_defer" timestamp; + +COMMIT;