| 1 | package App::Netdisco::JobQueue; | ||
| 2 | |||
| 3 | use Dancer qw/:moose :syntax :script/; | ||
| 4 | |||
| 5 | BEGIN { | ||
| 6 | $ENV{ND_QUEUE_ENGINE} ||= | ||
| 7 | setting('workers') ? setting('workers')->{queue} : 'PostgreSQL'; | ||
| 8 | } | ||
| 9 | |||
| 10 | use Module::Load (); | ||
| 11 | Module::Load::load | ||
| 12 | 'App::Netdisco::JobQueue::' . $ENV{ND_QUEUE_ENGINE} => ':all'; | ||
| 13 | |||
| 14 | use base 'Exporter'; | ||
| 15 | our @EXPORT = (); | ||
| 16 | our @EXPORT_OK = qw/ | ||
| 17 | jq_warm_thrusters | ||
| 18 | jq_getsome | ||
| 19 | jq_locked | ||
| 20 | jq_queued | ||
| 21 | jq_lock | ||
| 22 | jq_defer | ||
| 23 | jq_complete | ||
| 24 | jq_log | ||
| 25 | jq_userlog | ||
| 26 | jq_insert | ||
| 27 | jq_delete | ||
| 28 | /; | ||
| 29 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | App::Netdisco::JobQueue | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | Interface for Netdisco job queue. | ||
| 38 | |||
| 39 | There are no default exports, however the C<:all> tag will export all | ||
| 40 | subroutines. | ||
| 41 | |||
| 42 | =head1 EXPORT_OK | ||
| 43 | |||
| 44 | =head2 jq_getsome( $num, [ actions => \@actions, only => 1 ] ) | ||
| 45 | |||
| 46 | Returns a list of randomly selected queued jobs, at most C<$num> of them. Jobs | ||
| 47 | are returned as objects which implement the Netdisco job instance interface | ||
| 48 | (see below). | ||
| 49 | |||
| 50 | With C<actions>, jobs for those actions are left out. With C<only> as well, | ||
| 51 | only jobs for those actions are returned. This is how the backend gives each | ||
| 52 | of its worker queues (see C<workers.queues>) its own jobs. | ||
| 53 | |||
| 54 | =head2 jq_locked() | ||
| 55 | |||
| 56 | Returns the list of jobs currently booked out to this processing node (denoted | ||
| 57 | by the local hostname). Jobs are returned as objects which implement the | ||
| 58 | Netdisco job instance interface (see below). | ||
| 59 | |||
| 60 | =head2 jq_queued( $job_type ) | ||
| 61 | |||
| 62 | Returns a list of IP addresses of devices which currently have a job of the | ||
| 63 | given C<$job_type> queued (e.g. C<discover>, C<arpnip>, etc). | ||
| 64 | |||
| 65 | =head2 jq_warm_thrusters() | ||
| 66 | |||
| 67 | Performs initialisation of the Job Queue backend. | ||
| 68 | |||
| 69 | =head2 jq_log() | ||
| 70 | |||
| 71 | Returns a list of the most recent jobs as defined in C<jobs_qdepth> from the | ||
| 72 | queue. Jobs are returned as objects which implement the Netdisco job instance | ||
| 73 | interface (see below). | ||
| 74 | |||
| 75 | =head2 jq_userlog( $user ) | ||
| 76 | |||
| 77 | Returns a list of jobs which have been entered into the queue by the passed | ||
| 78 | C<$user>. Jobs are returned as objects which implement the Netdisco job | ||
| 79 | instance interface (see below). | ||
| 80 | |||
| 81 | =head2 jq_lock( $job ) | ||
| 82 | |||
| 83 | Marks a job in the queue as booked out to this processing node (denoted by the | ||
| 84 | local hostname). The C<$job> parameter must be an object which implements the | ||
| 85 | Netdisco job instance interface (see below). | ||
| 86 | |||
| 87 | Returns true if successful else returns false. | ||
| 88 | |||
| 89 | =head2 jq_defer( $job ) | ||
| 90 | |||
| 91 | Marks a job in the queue as available for taking. This is usually done after a | ||
| 92 | job is booked but the processing node changes its mind and decides to return | ||
| 93 | the job to the queue. The C<$job> parameter must be an object which implements | ||
| 94 | the Netdisco job instance interface (see below). | ||
| 95 | |||
| 96 | Returns true if successful else returns false. | ||
| 97 | |||
| 98 | =head2 jq_complete( $job ) | ||
| 99 | |||
| 100 | Marks a job as complete. The C<$job> parameter must be an object which | ||
| 101 | implements the Netdisco job instance interface (see below). The queue item's | ||
| 102 | status, log and finished fields will be updated from the passed C<$job>. | ||
| 103 | |||
| 104 | Returns true if successful else returns false. | ||
| 105 | |||
| 106 | =head2 jq_insert( \%job | [ \%job, \%job ...] ) | ||
| 107 | |||
| 108 | Adds the passed jobs to the queue. | ||
| 109 | |||
| 110 | =head2 jq_delete( $id? ) | ||
| 111 | |||
| 112 | If passed the ID of a job, deletes it from the queue. Otherwise deletes ALL | ||
| 113 | jobs from the queue. | ||
| 114 | |||
| 115 | =head1 Job Instance Interface | ||
| 116 | |||
| 117 | =head2 id (auto) | ||
| 118 | |||
| 119 | =head2 entered | ||
| 120 | |||
| 121 | =head2 started | ||
| 122 | |||
| 123 | =head2 finished | ||
| 124 | |||
| 125 | =head2 device | ||
| 126 | |||
| 127 | =head2 port | ||
| 128 | |||
| 129 | =head2 action | ||
| 130 | |||
| 131 | =head2 subaction or extra | ||
| 132 | |||
| 133 | =head2 status | ||
| 134 | |||
| 135 | =head2 username | ||
| 136 | |||
| 137 | =head2 userip | ||
| 138 | |||
| 139 | =head2 log | ||
| 140 | |||
| 141 | =head2 debug | ||
| 142 | |||
| 143 | =cut | ||
| 144 | |||
| 145 | true; |