View | Details | Raw Unified | Return to bug 15529
Collapse All | Expand All

(-)a/misc/cronjobs/process_message_queue.pl (-32 / +39 lines)
Lines 38-48 my $help = 0; Link Here
38
my $verbose = 0;
38
my $verbose = 0;
39
my $type = q{};
39
my $type = q{};
40
40
41
use MIME::Lite;
42
use Mail::Sendmail;
43
use Encode;
44
use Net::SMTP;
45
46
use Fcntl ':flock';
41
use Fcntl ':flock';
47
42
48
43
Lines 76-121 This script has the following parameters : Link Here
76
    -l --limit: The maximum number of messages to process for this run
71
    -l --limit: The maximum number of messages to process for this run
77
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
72
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
78
    -h --help: this message
73
    -h --help: this message
79
    -v --verbose: provides verbose output to STDOUT, if verbose is set then emails will be sent upon duplicate execution of this cronjob
74
    -v --verbose: provides verbose output to STDOUT.
75
                  Also useful for testing duplicate runs. Make sure the KohaAdminEmailAddress preference is set.
80
ENDUSAGE
76
ENDUSAGE
81
77
82
die $usage if $help;
78
die $usage if $help;
83
79
84
cronlogaction();
80
cronlogaction();
85
81
86
print "start of program\n";
82
if ($verbose) { print "start of program\n"; }
87
my $logdir = C4::Context->config('logdir');
83
my $logdir = C4::Context->config('logdir');
88
84
89
chomp $logdir;
85
chomp $logdir;
90
my $instancemessagequeuefile = $logdir . "/messagequeue.lock";
86
my $instancemessagequeuefile = $logdir . "/messagequeue.lock";
91
open(FOO, ">> $instancemessagequeuefile") or die "Cannot write to $instancemessagequeuefile: $!";
87
my $fh;
88
open $fh, '>>', $instancemessagequeuefile or die "Cannot write to $instancemessagequeuefile: $!";
92
89
93
print "Getting the lock\n";
90
my $letter_code = '';
94
unless (flock ( FOO, LOCK_EX|LOCK_NB )) {
91
if ($verbose) { print "Getting the lock\n"; }
92
unless (flock ( $fh, LOCK_EX|LOCK_NB )) {
95
93
96
    print "$0 is already running. Exiting.\n";
94
    print STDERR "$0 is already running!\n";
97
    #If verbose is set send email to inform administrator another process_message_queue.pl cron was attempted to run whilst previous execution of the file is taking place.
95
    #If verbose is set send email to inform administrator another process_message_queue.pl cron was attempted to run whilst previous execution of the file is taking place.
98
    # Configure accordingly
96
    # Configure accordingly
99
97
100
    if ($verbose) {
98
    my $null_borrower = undef;
101
        MIME::Lite->send( 'smtp', '');
99
    my $is_queued = C4::Letters::EnqueueLetter( {
102
        my $email = MIME::Lite->new(
100
        borrowernumber         => $null_borrower,                                   #borrowernumber
103
            To => ' ',
101
        letter => {
104
            From => ' ',
102
            title          => 'process_message_queue.pl cron is already running',   #subject
105
            Type => 'TEXT',
103
            content        => 'process_message_queue.pl cron is already running',   #content
106
            Subject => 'process_message_queue.pl cron is already running',
104
            metadata       => '',                                                   #metadata
107
            Data => 'process_message_queue.pl cron is already running',
105
            code           => 'DUPLICATE_PROCESS_MESSAGE_QUEUE',                    #letter_code
108
        );
106
            'content-type' => 'text/plain; charset="UTF-8"',                        #content_type
109
107
        },
110
        $email->attach(
108
        message_transport_type => 'email',                                          #message_transport_type
111
            Type => 'Text',
109
        to_address             => C4::Context->preference('KohaAdminEmailAddress'), #to_address
112
            Data => 'process_message_queue.pl cron is already running',
110
        from_address           => C4::Context->preference('KohaAdminEmailAddress'), #from_address
113
        );
111
    } );
114
        $email->send();
112
    $letter_code = 'DUPLICATE_PROCESS_MESSAGE_QUEUE';
115
        exit(1);
116
    }
117
}
113
}
118
114
119
C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } );
115
C4::Letters::SendQueuedMessages(
120
sleep(15);
116
    {
121
print "End of process_message_queue.pl cron process";
117
        verbose  => $verbose,
118
        username => $username,
119
        password => $password,
120
        method   => $method,
121
        limit    => $limit,
122
        type     => $type,
123
        letter_code => $letter_code,
124
    }
125
);
126
if ($verbose) {
127
    sleep(15);
128
    print "End of process_message_queue.pl cron process";
129
}
122
- 

Return to bug 15529