« blib/lib/App/Netdisco/Worker/Plugin/Expire.pm
↑ Summary
blib/lib/App/Netdisco/Worker/Plugin/GetAPIKey.pm »
| 1 | package App::Netdisco::Worker::Plugin::ExpireNodes; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use App::Netdisco::Worker::Plugin; | ||
| 5 | use aliased 'App::Netdisco::Worker::Status'; | ||
| 6 | |||
| 7 | use Dancer::Plugin::DBIC 'schema'; | ||
| 8 | |||
| 9 | register_worker({ phase => 'check' }, sub { | ||
| 10 | return Status->error('Missing device (-d).') | ||
| 11 | unless defined shift->device; | ||
| 12 | return Status->done('ExpireNodes is able to run'); | ||
| 13 | }); | ||
| 14 | |||
| 15 | register_worker({ phase => 'main' }, sub { | ||
| 16 | my ($job, $workerconf) = @_; | ||
| 17 | |||
| 18 | schema('netdisco')->txn_do(sub { | ||
| 19 | schema('netdisco')->resultset('Node')->search({ | ||
| 20 | switch => $job->device->ip, | ||
| 21 | ($job->port ? (port => $job->port) : ()), | ||
| 22 | })->delete( | ||
| 23 | ($job->extra ? () : ({ archive_nodes => 1 })) | ||
| 24 | ); | ||
| 25 | }); | ||
| 26 | |||
| 27 | return Status->done('Expired nodes for '. $job->device->ip); | ||
| 28 | }); | ||
| 29 | |||
| 30 | true; |