#949 replace other occurances of now() with LOCALTIMESTAMP

This commit is contained in:
Oliver Gorwits
2023-03-03 14:17:38 +00:00
parent 29402f0726
commit d9a384d1d0
15 changed files with 33 additions and 33 deletions

View File

@@ -52,7 +52,7 @@ register_worker({ phase => 'main' }, sub {
os => 'netdisco',
os_ver => pretty_version($App::Netdisco::VERSION, 3),
layers => '00000100',
last_discover => \'now()',
last_discover => \'LOCALTIMESTAMP',
is_pseudo => \'true',
});
return unless $device;

View File

@@ -24,7 +24,7 @@ register_worker({ phase => 'early',
my ($job, $workerconf) = @_;
my $device = $job->device;
# would be possible just to use now() on updated records, but by using this
# would be possible just to use LOCALTIMESTAMP on updated records, but by using this
# same value for them all, we can if we want add a job at the end to
# select and do something with the updated set (see set archive, below)
vars->{'timestamp'} = ($job->is_offline and $job->entered)

View File

@@ -28,7 +28,7 @@ my $clean = sub {
serial => $device->serial,
model => $device->model,
fru => \'false',
last_discover => \'now()',
last_discover => \'LOCALTIMESTAMP',
});
};
@@ -95,7 +95,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
serial => Encode::decode('UTF-8', $e_serial->{$entry}),
fru => $e_fru->{$entry},
description => Encode::decode('UTF-8', $e_descr->{$entry}),
last_discover => \'now()',
last_discover => \'LOCALTIMESTAMP',
};
}

View File

@@ -58,7 +58,7 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
$device->set_column( snmp_class => $snmp->class );
$device->set_column( snmp_engineid => unpack('H*', ($snmp->snmpEngineID || '')) );
$device->set_column( last_discover => \'now()' );
$device->set_column( last_discover => \'LOCALTIMESTAMP' );
# protection for failed SNMP gather
if ($device->in_storage and not $device->is_pseudo) {

View File

@@ -59,7 +59,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
native => $native,
egress_tag => 'f',
vlantype => $type,
last_discover => \'now()',
last_discover => \'LOCALTIMESTAMP',
};
++$this_port_vlans{$vlan};
@@ -78,7 +78,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
native => $native,
egress_tag => ($native eq 't' ? 'f' : 't'),
vlantype => $type,
last_discover => \'now()',
last_discover => \'LOCALTIMESTAMP',
};
++$this_port_vlans{$vlan};
@@ -109,7 +109,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
push @devicevlans, {
vlan => $vlan,
description => $v_name->{$entry},
last_discover => \'now()',
last_discover => \'LOCALTIMESTAMP',
};
}
@@ -120,7 +120,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
push @devicevlans, {
vlan => $vlan,
description => (sprintf "VLAN %d", $vlan),
last_discover => \'now()',
last_discover => \'LOCALTIMESTAMP',
};
}

View File

@@ -15,7 +15,7 @@ register_worker({ phase => 'main' }, sub {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Device')->search({
-or => [ 'vendor' => undef, 'vendor' => { '!=' => 'netdisco' }],
last_discover => \[q/< (now() - ?::interval)/,
last_discover => \[q/< (LOCALTIMESTAMP - ?::interval)/,
(setting('expire_devices') * 86400)],
})->delete();
});
@@ -27,12 +27,12 @@ register_worker({ phase => 'main' }, sub {
? setting('expire_nodeip_freshness') : setting('expire_nodes'));
if ($freshness) {
schema('netdisco')->resultset('NodeIp')->search({
time_last => \[q/< (now() - ?::interval)/, ($freshness * 86400)],
time_last => \[q/< (LOCALTIMESTAMP - ?::interval)/, ($freshness * 86400)],
})->delete();
}
schema('netdisco')->resultset('Node')->search({
time_last => \[q/< (now() - ?::interval)/,
time_last => \[q/< (LOCALTIMESTAMP - ?::interval)/,
(setting('expire_nodes') * 86400)],
})->delete();
});
@@ -44,13 +44,13 @@ register_worker({ phase => 'main' }, sub {
? setting('expire_nodeip_freshness') : setting('expire_nodes_archive'));
if ($freshness) {
schema('netdisco')->resultset('NodeIp')->search({
time_last => \[q/< (now() - ?::interval)/, ($freshness * 86400)],
time_last => \[q/< (LOCALTIMESTAMP - ?::interval)/, ($freshness * 86400)],
})->delete();
}
schema('netdisco')->resultset('Node')->search({
-not_bool => 'active',
time_last => \[q/< (now() - ?::interval)/,
time_last => \[q/< (LOCALTIMESTAMP - ?::interval)/,
(setting('expire_nodes_archive') * 86400)],
})->delete();
});
@@ -67,7 +67,7 @@ register_worker({ phase => 'main' }, sub {
if (setting('expire_jobs') and setting('expire_jobs') > 0) {
schema('netdisco')->txn_do_locked('admin', 'EXCLUSIVE', sub {
schema('netdisco')->resultset('Admin')->search({
entered => \[q/< (now() - ?::interval)/,
entered => \[q/< (LOCALTIMESTAMP - ?::interval)/,
(setting('expire_jobs') * 86400)],
})->delete();
});
@@ -76,7 +76,7 @@ register_worker({ phase => 'main' }, sub {
if (setting('expire_userlog') and setting('expire_userlog') > 0) {
schema('netdisco')->txn_do_locked('admin', 'EXCLUSIVE', sub {
schema('netdisco')->resultset('UserLog')->search({
creation => \[q/< (now() - ?::interval)/,
creation => \[q/< (LOCALTIMESTAMP - ?::interval)/,
(setting('expire_userlog') * 86400)],
})->delete();
});

View File

@@ -25,7 +25,7 @@ register_worker({ phase => 'early',
my ($job, $workerconf) = @_;
my $device = $job->device;
# would be possible just to use now() on updated records, but by using this
# would be possible just to use LOCALTIMESTAMP on updated records, but by using this
# same value for them all, we can if we want add a job at the end to
# select and do something with the updated set (see set archive, below)
vars->{'timestamp'} = ($job->is_offline and $job->entered)

View File

@@ -47,7 +47,7 @@ register_worker({ phase => 'main' }, sub {
my $devices = schema('netdisco')->resultset('Device')->search(undef, {
'+columns' => { old =>
\['age(now(), last_discover) > ?::interval', $down_age] },
\['age(LOCALTIMESTAMP, last_discover) > ?::interval', $down_age] },
});
$config->{groups} ||= { default => 'any' };