| 1 | package XAS::Apps::Spooler::Process; | ||
| 2 | |||
| 3 | our $VERSION = '0.01'; | ||
| 4 | |||
| 5 | 1 | ▶ | use XAS::Spooler::Connector; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | use XAS::Spooler::Processor; | ||
| 7 | |||
| 8 | use XAS::Class | ||
| 9 | debug => 0, | ||
| 10 | version => $VERSION, | ||
| 11 | base => 'XAS::Lib::App::Service', | ||
| 12 | mixin => 'XAS::Lib::Mixins::Configs', | ||
| 13 | utils => 'dotid trim', | ||
| 14 | accessors => 'host port cfg', | ||
| 15 | vars => { | ||
| 16 | SERVICE_NAME => 'XAS_Spooler', | ||
| 17 | SERVICE_DISPLAY_NAME => 'XAS Spooler', | ||
| 18 | SERVICE_DESCRIPTION => 'The XAS Spooler', | ||
| 19 | } | ||
| 20 | ; | ||
| 21 | |||
| 22 | # ---------------------------------------------------------------------- | ||
| 23 | # Public Methods | ||
| 24 | # ---------------------------------------------------------------------- | ||
| 25 | |||
| 26 | sub setup { | ||
| 27 | my $self = shift; | ||
| 28 | |||
| 29 | my @sections = $self->cfg->Sections(); | ||
| 30 | my $connector = XAS::Spooler::Connector->new( | ||
| 31 | -alias => 'connector', | ||
| 32 | -host => $self->host, | ||
| 33 | -port => $self->port, | ||
| 34 | -tcp_keepalive => 1, | ||
| 35 | -retry_reconnect => 1, | ||
| 36 | -hostname => $self->env->host, | ||
| 37 | ); | ||
| 38 | |||
| 39 | $self->service->register('connector'); | ||
| 40 | |||
| 41 | foreach my $section (@sections) { | ||
| 42 | |||
| 43 | next if ($section !~ /^spooler:/); | ||
| 44 | |||
| 45 | my ($alias) = $section =~ /^spooler:(.*)/; | ||
| 46 | $alias = trim($alias); | ||
| 47 | |||
| 48 | my $processor = XAS::Spooler::Processor->new( | ||
| 49 | -connector => 'connector', | ||
| 50 | -alias => $alias, | ||
| 51 | -tasks => $self->cfg->val($section, 'tasks', 1), | ||
| 52 | -queue => $self->cfg->val($section, 'queue', ''), | ||
| 53 | -directory => $self->cfg->val($section, 'directory', ''), | ||
| 54 | -schedule => $self->cfg->val($section, 'schedule', '*/1 * * * *'), | ||
| 55 | -packet_type => $self->cfg->val($section, 'packet-type', 'unknown'), | ||
| 56 | ); | ||
| 57 | |||
| 58 | $self->service->register($alias); | ||
| 59 | |||
| 60 | } | ||
| 61 | |||
| 62 | } | ||
| 63 | |||
| 64 | sub main { | ||
| 65 | my $self = shift; | ||
| 66 | |||
| 67 | $self->setup(); | ||
| 68 | |||
| 69 | $self->log->info_msg('startup'); | ||
| 70 | |||
| 71 | $self->service->run(); | ||
| 72 | |||
| 73 | $self->log->info_msg('shutdown'); | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | sub options { | ||
| 78 | my $self = shift; | ||
| 79 | |||
| 80 | $self->{'host'} = $self->env->mqserver; | ||
| 81 | $self->{'port'} = $self->env->mqport; | ||
| 82 | |||
| 83 | return { | ||
| 84 | 'host=s' => \$self->{'host'}, | ||
| 85 | 'port=s' => \$self->{'port'} | ||
| 86 | }; | ||
| 87 | |||
| 88 | } | ||
| 89 | |||
| 90 | # ---------------------------------------------------------------------- | ||
| 91 | # Private Methods | ||
| 92 | # ---------------------------------------------------------------------- | ||
| 93 | |||
| 94 | sub init { | ||
| 95 | my $class = shift; | ||
| 96 | |||
| 97 | my $self = $class->SUPER::init(@_); | ||
| 98 | |||
| 99 | $self->load_config(); | ||
| 100 | |||
| 101 | return $self; | ||
| 102 | |||
| 103 | } | ||
| 104 | |||
| 105 | 1; | ||
| 106 | |||
| 107 | __END__ | ||
| 108 | |||
| 109 | =head1 NAME | ||
| 110 | |||
| 111 | XAS::Apps::Spooler::Process - Process spool files | ||
| 112 | |||
| 113 | =head1 SYNOPSIS | ||
| 114 | |||
| 115 | use XAS::Apps::Spooler::Process; | ||
| 116 | |||
| 117 | my $app = XAS::Apps::Spooler::Process->new( | ||
| 118 | -throws => 'xas-spooler', | ||
| 119 | ); | ||
| 120 | |||
| 121 | exit $app->run(); | ||
| 122 | |||
| 123 | =head1 DESCRIPTION | ||
| 124 | |||
| 125 | This method will process a set of spoool directories and send the contents | ||
| 126 | to a STOMP based message queue server. | ||
| 127 | |||
| 128 | =head1 CONFIGURATION | ||
| 129 | |||
| 130 | The configuration file uses the familiar Windows .ini format. It has the | ||
| 131 | following stanza. | ||
| 132 | |||
| 133 | [spooler: logs] | ||
| 134 | directory = logs | ||
| 135 | schedule = */1 * * * * | ||
| 136 | queue = /queue/logs | ||
| 137 | packet-type = xas-logs | ||
| 138 | tasks = 6 | ||
| 139 | |||
| 140 | Where the section header "spooler:" may have addtional qualifiers and repeated | ||
| 141 | as many times as needed. The following properties may be used. | ||
| 142 | |||
| 143 | =over 4 | ||
| 144 | |||
| 145 | =item B<directory> | ||
| 146 | |||
| 147 | The directory to scan for files. If this is a relative directory it is | ||
| 148 | referenced from $XAS_SPOOL. | ||
| 149 | |||
| 150 | =item B<schedule> | ||
| 151 | |||
| 152 | The schedule to run the directory scan. It uses cron semantics. This defaults | ||
| 153 | to "*/1 * * * *" | ||
| 154 | |||
| 155 | =item B<queue> | ||
| 156 | |||
| 157 | The queue to use on the message queue server. | ||
| 158 | |||
| 159 | =item B<packet-type> | ||
| 160 | |||
| 161 | The type of packet. | ||
| 162 | |||
| 163 | =item B<tasks> | ||
| 164 | |||
| 165 | The number of internal processing tasks to use. Adding more tasks | ||
| 166 | may speed up processing. This defaults to 1. | ||
| 167 | |||
| 168 | =back | ||
| 169 | |||
| 170 | =head1 METHODS | ||
| 171 | |||
| 172 | =head2 setup | ||
| 173 | |||
| 174 | This method will process the config file. | ||
| 175 | |||
| 176 | =head2 main | ||
| 177 | |||
| 178 | This method will start the processing. | ||
| 179 | |||
| 180 | =head2 options | ||
| 181 | |||
| 182 | This method defines these additional command line options. | ||
| 183 | |||
| 184 | =over 4 | ||
| 185 | |||
| 186 | =item B<--host> | ||
| 187 | |||
| 188 | The host that the message queue server resides on. | ||
| 189 | |||
| 190 | =item B<--port> | ||
| 191 | |||
| 192 | The port that the message queue server is listening too. | ||
| 193 | |||
| 194 | =back | ||
| 195 | |||
| 196 | =head1 SEE ALSO | ||
| 197 | |||
| 198 | =over 4 | ||
| 199 | |||
| 200 | =item L<XAS::Spooler::Connector|XAS::Spooler::Connector> | ||
| 201 | |||
| 202 | =item L<XAS::Spooler::Processor|XAS::Spooler::Processor> | ||
| 203 | |||
| 204 | =item L<XAS::Spooler|XAS::Spooler> | ||
| 205 | |||
| 206 | =item L<XAS|XAS> | ||
| 207 | |||
| 208 | =back | ||
| 209 | |||
| 210 | =head1 AUTHOR | ||
| 211 | |||
| 212 | Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> | ||
| 213 | |||
| 214 | =head1 COPYRIGHT AND LICENSE | ||
| 215 | |||
| 216 | Copyright (c) 2101-2015 Kevin L. Esteb | ||
| 217 | |||
| 218 | This is free software; you can redistribute it and/or modify it under | ||
| 219 | the terms of the Artistic License 2.0. For details, see the full text | ||
| 220 | of the license at http://www.perlfoundation.org/artistic_license_2_0. | ||
| 221 | |||
| 222 | =cut | ||