App-Netdisco
view release on metacpan or search on metacpan
lib/App/Netdisco/Web/API/Queue.pm view on Meta::CPAN
use App::Netdisco::JobQueue 'jq_insert';
use Try::Tiny;
swagger_path {
tags => ['Queue'],
path => (setting('api_base') || '').'/queue/backends',
description => 'Return list of currently active backend names (usually FQDN)',
responses => { default => {} },
}, get '/api/v1/queue/backends' => require_role api_admin => sub {
# from 1d988bbf7 this always returns an entry
my @names = schema(vars->{'tenant'})->resultset('DeviceSkip')
->get_distinct_col('backend');
return to_json \@names;
};
swagger_path {
tags => ['Queue'],
path => (setting('api_base') || '').'/queue/jobs',
description => 'Return jobs in the queue, optionally filtered by fields',
parameters => [
limit => {
description => 'Maximum number of Jobs to return',
type => 'integer',
default => (setting('jobs_qdepth') || 50),
},
device => {
description => 'IP address field of the Job',
},
port => {
description => 'Port field of the Job',
},
action => {
description => 'Action field of the Job',
},
status => {
description => 'Status field of the Job',
},
username => {
description => 'Username of the Job submitter',
},
userip => {
description => 'IP address of the Job submitter',
},
backend => {
description => 'Backend instance assigned the Job',
},
],
responses => { default => {} },
}, get '/api/v1/queue/jobs' => require_role api_admin => sub {
my @set = schema(vars->{'tenant'})->resultset('Admin')->search({
( param('device') ? ( device => param('device') ) : () ),
( param('port') ? ( port => param('port') ) : () ),
( param('action') ? ( action => param('action') ) : () ),
( param('status') ? ( status => param('status') ) : () ),
( param('username') ? ( username => param('username') ) : () ),
( param('userip') ? ( userip => param('userip') ) : () ),
( param('backend') ? ( backend => param('backend') ) : () ),
-or => [
{ 'log' => undef },
{ 'log' => { '-not_like' => 'duplicate of %' } },
],
}, {
order_by => { -desc => [qw/entered device action/] },
rows => (param('limit') || setting('jobs_qdepth') || 50),
})->with_times->hri->all;
return to_json \@set;
};
swagger_path {
tags => ['Queue'],
path => (setting('api_base') || '').'/queue/jobs',
description => 'Delete jobs and skiplist entries, optionally filtered by fields',
parameters => [
device => {
description => 'IP address field of the Job',
},
port => {
description => 'Port field of the Job',
},
action => {
description => 'Action field of the Job',
},
status => {
description => 'Status field of the Job',
},
username => {
description => 'Username of the Job submitter',
},
userip => {
description => 'IP address of the Job submitter',
},
backend => {
description => 'Backend instance assigned the Job',
},
],
responses => { default => {} },
}, del '/api/v1/queue/jobs' => require_role api_admin => sub {
my $gone = schema(vars->{'tenant'})->resultset('Admin')->search({
( param('device') ? ( device => param('device') ) : () ),
( param('port') ? ( port => param('port') ) : () ),
( param('action') ? ( action => param('action') ) : () ),
( param('status') ? ( status => param('status') ) : () ),
( param('username') ? ( username => param('username') ) : () ),
( param('userip') ? ( userip => param('userip') ) : () ),
( param('backend') ? ( backend => param('backend') ) : () ),
})->delete;
schema(vars->{'tenant'})->resultset('DeviceSkip')->search({
( param('device') ? ( device => param('device') ) : () ),
( param('action') ? ( actionset => { '&&' => \[ 'ARRAY[?]', param('action') ] } ) : () ),
( param('backend') ? ( backend => param('backend') ) : () ),
})->delete;
return to_json { deleted => ($gone || 0)};
};
swagger_path {
tags => ['Queue'],
path => (setting('api_base') || '').'/queue/jobs',
( run in 2.509 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )