/usr/share/doc/ledgersmb/examples/utils/process_queue/process_queue.pl is in ledgersmb 1.3.40-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #!/usr/bin/perl
# TODO: Add POD -CT
require "config.pl";
use DBI;
# TODO: Convert config.pl to namespace so we can use strict.
my $cycle_delay;
my $dbh = db_init();
# Basic db connection setup routines
my $sth;
while (1) { # loop infinitely
if ( $dbh->func('pg_notifies') ) {
on_notify();
}
sleep $cycle_delay;
}
sub on_notify {
my $job_id = 1;
while ($job_id){
($job_id) = $dbh->selectrow_array(
"SELECT id from pending_job
WHERE completed_at IS NULL
ORDER BY id LIMIT 1
FOR UPDATE"
);
if ($job_id){
$job_id = $dbh->quote($job_id);
my ($job_class) = $dbh->selectrow_array(
"select class from batch_class where id =
(select batch_class from pending_job where id = $job_id)"
);
# Right now, we assume that every pending job has a batch id.
# Longer-run we may need to use a template handle as well. -CT
$dbh->do('SELECT ' .
$dbh->quote_identifier("job__process_$job_class") . "($job_id)"
);
my $errstr = $dbh->errstr;
if (!$dbh->commit){ # Note error and clean up
# Note that this does not clean up the queue holding tables.
# This is a feature, not a bug, as it allows someone to review
# the actual data and then delete if required separately -CT
$dbh->do(
"UPDATE pending_job
SET completed_at = now(),
success = false,
error_condition = " . $dbh->quote($errstr) . "
WHERE id = $job_id"
);
$dbh->commit;
}
# The line below is necessary because the job process functions
# use set session authorization so one must reconnect to reset
# administrative permissions. -CT
$dbh->disconnect;
$dbh = db_init();
}
}
}
sub db_init {
my $dsn = "dbi:Pg:dbname=$database";
my $dbh = DBI->connect(
$dsn, $db_user,
$db_passwd,
{
AutoCommit => 0,
PrintError => 0,
RaiseError => 1,
}
);
$dbh->{pg_enable_utf8} = 1;
($cycle_delay) = $dbh->selectrow_array(
"SELECT value FROM defaults
WHERE setting_key = 'poll_frequency'"
);
if (!$cycle_delay){
die "No Polling Frequency Set Up!";
}
$dbh->do("LISTEN job_entered");
$dbh->commit;
return $dbh;
}
|