Squashed commit of the following: commit39b438aa4bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:40:11 2017 +0100 add release notes commitca4ea90d35Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:32:06 2017 +0100 update distmeta commit4e35b904b0Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:30:22 2017 +0100 rename files from Daemon to Backend commit86a605ba68Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:26:43 2017 +0100 rename daemon to backend in code commitffe8fc180fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:15:57 2017 +0100 add daemon files which exec to backend equivalents commit53e041594eAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 15:32:49 2017 +0100 rename netdisco-daemon to netdisco-backend
		
			
				
	
	
		
			74 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
package App::Netdisco::Backend::Worker::Poller::Expiry;
 | 
						|
 | 
						|
use Dancer qw/:moose :syntax :script/;
 | 
						|
use Dancer::Plugin::DBIC 'schema';
 | 
						|
 | 
						|
use App::Netdisco::Backend::Util ':all';
 | 
						|
 | 
						|
use Role::Tiny;
 | 
						|
use namespace::clean;
 | 
						|
 | 
						|
# expire devices and nodes according to config
 | 
						|
sub expire {
 | 
						|
  my ($self, $job) = @_;
 | 
						|
 | 
						|
  if (setting('expire_devices') and setting('expire_devices') > 0) {
 | 
						|
      schema('netdisco')->txn_do(sub {
 | 
						|
        schema('netdisco')->resultset('Device')->search({
 | 
						|
          last_discover => \[q/< (now() - ?::interval)/,
 | 
						|
              (setting('expire_devices') * 86400)],
 | 
						|
        })->delete();
 | 
						|
      });
 | 
						|
  }
 | 
						|
 | 
						|
  if (setting('expire_nodes') and setting('expire_nodes') > 0) {
 | 
						|
      schema('netdisco')->txn_do(sub {
 | 
						|
        schema('netdisco')->resultset('Node')->search({
 | 
						|
          time_last => \[q/< (now() - ?::interval)/,
 | 
						|
              (setting('expire_nodes') * 86400)],
 | 
						|
        })->delete();
 | 
						|
      });
 | 
						|
  }
 | 
						|
 | 
						|
  if (setting('expire_nodes_archive') and setting('expire_nodes_archive') > 0) {
 | 
						|
      schema('netdisco')->txn_do(sub {
 | 
						|
        schema('netdisco')->resultset('Node')->search({
 | 
						|
          -not_bool => 'active',
 | 
						|
          time_last => \[q/< (now() - ?::interval)/,
 | 
						|
              (setting('expire_nodes_archive') * 86400)],
 | 
						|
        })->delete();
 | 
						|
      });
 | 
						|
  }
 | 
						|
 | 
						|
  if (setting('expire_jobs') and setting('expire_jobs') > 0) {
 | 
						|
      schema('netdisco')->txn_do(sub {
 | 
						|
        schema('netdisco')->resultset('Admin')->search({
 | 
						|
          entered => \[q/< (now() - ?::interval)/,
 | 
						|
              (setting('expire_jobs') * 86400)],
 | 
						|
        })->delete();
 | 
						|
      });
 | 
						|
  }
 | 
						|
 | 
						|
  return job_done("Checked expiry for all Devices and Nodes");
 | 
						|
}
 | 
						|
 | 
						|
# expire nodes for a specific device
 | 
						|
sub expirenodes {
 | 
						|
  my ($self, $job) = @_;
 | 
						|
 | 
						|
  return job_error('Missing device') unless $job->device;
 | 
						|
 | 
						|
  schema('netdisco')->txn_do(sub {
 | 
						|
    schema('netdisco')->resultset('Node')->search({
 | 
						|
      switch => $job->device->ip,
 | 
						|
      ($job->port ? (port => $job->port) : ()),
 | 
						|
    })->delete(
 | 
						|
      ($job->extra ? () : ({ archive_nodes => 1 }))
 | 
						|
    );
 | 
						|
  });
 | 
						|
 | 
						|
  return job_done("Expired nodes for ". $job->device->ip);
 | 
						|
}
 | 
						|
 | 
						|
1;
 |