| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings 'all'; | ||
| 5 | use forks; | ||
| 6 | use Email::Blaster::Throttled; | ||
| 7 | |||
| 8 | my $blaster = Email::Blaster::Throttled->new( ); | ||
| 9 | |||
| 10 | $blaster->handle_event( type => 'server_startup' ); | ||
| 11 | |||
| 12 | my @workers = ( ); | ||
| 13 | |||
| 14 | foreach my $throttled ( $blaster->config->throttled ) | ||
| 15 | { | ||
| 16 | push @workers, threads->create(sub { | ||
| 17 | my ($throttled) = @{$_[0]}; | ||
| 18 | |||
| 19 | warn "Throttled Server for @{[ $throttled->domain ]} (@{[ $throttled->hourly_limit ]}/hour) starting up...\n"; | ||
| 20 | |||
| 21 | local $SIG{INT} = $SIG{TERM} = sub { | ||
| 22 | # Quitting: | ||
| 23 | warn "Throttled Server for @{[ $throttled->domain ]} (@{[ $throttled->hourly_limit ]}/hour) shutting down...\n"; | ||
| 24 | $blaster->handle_event( type => 'server_shutdown' ); | ||
| 25 | exit; | ||
| 26 | }; | ||
| 27 | use Email::Blaster::Transmission; | ||
| 28 | use My::TransmissionInitHandler; | ||
| 29 | use My::Contact; | ||
| 30 | |||
| 31 | $blaster->run( $throttled->domain, $throttled->hourly_limit ); | ||
| 32 | }, [ $throttled ]); | ||
| 33 | }# end foreach() | ||
| 34 | |||
| 35 | map { $_->join() } @workers; | ||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 |