add refresh poller job
This commit is contained in:
		| @@ -2,13 +2,14 @@ package App::Netdisco::Daemon::Worker::Poller; | ||||
|  | ||||
| use Dancer qw/:moose :syntax :script/; | ||||
| use Dancer::Plugin::DBIC 'schema'; | ||||
|  | ||||
| use Try::Tiny; | ||||
|  | ||||
| use Role::Tiny; | ||||
| use namespace::clean; | ||||
|  | ||||
| # add dispatch methods for poller tasks | ||||
| # with 'App::Netdisco::Daemon::Worker::Poller::Discover'; | ||||
| with 'App::Netdisco::Daemon::Worker::Poller::Discover'; | ||||
|  | ||||
| sub worker_body { | ||||
|   my $self = shift; | ||||
| @@ -26,7 +27,6 @@ sub worker_body { | ||||
|                       ->new_result($candidate); | ||||
|           my $jid = $job->job; | ||||
|  | ||||
|           my $target = 'set_'. $job->action; | ||||
|           next unless $self->can($target); | ||||
|           debug "poll ($wid): can ${target}() for job $jid"; | ||||
|  | ||||
|   | ||||
							
								
								
									
										34
									
								
								Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| package App::Netdisco::Daemon::Worker::Poller::Discover; | ||||
|  | ||||
| use Dancer qw/:moose :syntax :script/; | ||||
| use Dancer::Plugin::DBIC 'schema'; | ||||
|  | ||||
| use App::Netdisco::Util::SNMP ':all'; | ||||
| use App::Netdisco::Daemon::Worker::Interactive::Util ':all'; | ||||
|  | ||||
| use Role::Tiny; | ||||
| use namespace::clean; | ||||
|  | ||||
| # queue a discover job for all devices known to Netdisco | ||||
| sub refresh { | ||||
|   my ($self, $job) = @_; | ||||
|  | ||||
|   my $devices = schema('netdisco')->resultset('Device')->get_column('ip'); | ||||
|  | ||||
|   schema('netdisco')->resultset('Admin')->populate([ | ||||
|     map {{ | ||||
|         device => $_, | ||||
|         action => 'discover', | ||||
|         status => 'queued', | ||||
|     }} ($devices->all) | ||||
|   ]); | ||||
|  | ||||
|   return done("Queued discover job for all devices"); | ||||
| } | ||||
|  | ||||
| sub discover { | ||||
|   my ($self, $job) = @_; | ||||
|  | ||||
| } | ||||
|  | ||||
| 1; | ||||
		Reference in New Issue
	
	Block a user