Support for message queue in application.

This commit is contained in:
Chris 2012-08-09 15:52:11 +01:00
parent 28b14acb48
commit dd22f7bf29
2 changed files with 13 additions and 4 deletions

View File

@ -54,6 +54,7 @@ use Logger;
use Template; use Template;
use SessionHandler; use SessionHandler;
use Modules; use Modules;
use Message::Queue;
use Utils qw(path_join is_defined_numeric get_proc_size); use Utils qw(path_join is_defined_numeric get_proc_size);
our $errstr; our $errstr;
@ -138,6 +139,12 @@ sub run {
# Start doing logging if needed # Start doing logging if needed
$self -> {"logger"} -> start_log($self -> {"settings"} -> {"config"} -> {"logfile"}) if($self -> {"settings"} -> {"config"} -> {"logfile"}); $self -> {"logger"} -> start_log($self -> {"settings"} -> {"config"} -> {"logfile"}) if($self -> {"settings"} -> {"config"} -> {"logfile"});
# Message queue handling
$self -> {"messages"} = Message::Queue -> new(logger => $self -> {"logger"},
dbh => $self -> {"dbh"},
settings => $self -> {"settings"})
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create message handler: ".$SystemModule::errstr);
# Create the template handler object # Create the template handler object
$self -> {"template"} = Template -> new(logger => $self -> {"logger"}, $self -> {"template"} = Template -> new(logger => $self -> {"logger"},
basedir => $self -> {"settings"} -> {"config"} -> {"template_dir"} || "templates", basedir => $self -> {"settings"} -> {"config"} -> {"template_dir"} || "templates",
@ -206,7 +213,8 @@ sub run {
session => $self -> {"session"}, session => $self -> {"session"},
phpbb => $self -> {"phpbb"}, # this will handily be undef if phpbb mode is disabled phpbb => $self -> {"phpbb"}, # this will handily be undef if phpbb mode is disabled
blockdir => $self -> {"settings"} -> {"paths"} -> {"blocks"} || "blocks", blockdir => $self -> {"settings"} -> {"paths"} -> {"blocks"} || "blocks",
system => $self -> {"system"}) system => $self -> {"system"},
messages => $self -> {"messages"})
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create module handling object: ".$Modules::errstr); or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create module handling object: ".$Modules::errstr);
if($self -> {"system"}) { if($self -> {"system"}) {
@ -217,7 +225,8 @@ sub run {
template => $self -> {"template"}, template => $self -> {"template"},
session => $self -> {"session"}, session => $self -> {"session"},
phpbb => $self -> {"phpbb"}, phpbb => $self -> {"phpbb"},
modules => $self -> {"modules"}) modules => $self -> {"modules"},
messages => $self -> {"messages"})
or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create system object: ".$self -> {"system"} -> {"errstr"}); or $self -> {"logger"} -> die_log($self -> {"cgi"} -> remote_host(), "Application: Unable to create system object: ".$self -> {"system"} -> {"errstr"});
$self -> {"appuser"} -> set_system($self -> {"system"}) if($self -> {"appuser"}); $self -> {"appuser"} -> set_system($self -> {"system"}) if($self -> {"appuser"});

View File

@ -85,7 +85,7 @@ sub add_message {
$args -> {"send_at"} += $args -> {"delay"} if($args -> {"delay"}); $args -> {"send_at"} += $args -> {"delay"} if($args -> {"delay"});
# FUTURE: potentially support other formats here. See also: https://www.youtube.com/watch?v=JENdgiAPD6c however. # FUTURE: potentially support other formats here. See also: https://www.youtube.com/watch?v=JENdgiAPD6c however.
my $format = "plain"; my $args -> {"format"} = "plain";
# Force required fields # Force required fields
return $self -> self_error("Email subject not specified") unless($args -> {"subject"}); return $self -> self_error("Email subject not specified") unless($args -> {"subject"});
@ -168,7 +168,7 @@ sub _queue_message {
my $newh = $self -> {"dbh"} -> prepare("INSERT INTO `".$self -> {"settings"} -> {"database"} -> {"message_queue"}."` my $newh = $self -> {"dbh"} -> prepare("INSERT INTO `".$self -> {"settings"} -> {"database"} -> {"message_queue"}."`
(created, creator_id, message_ident, subject, body, format, send_after) (created, creator_id, message_ident, subject, body, format, send_after)
VALUES(?, ?, ?, ?, ?, ?, ?)"); VALUES(?, ?, ?, ?, ?, ?, ?)");
my $result = $newh -> execute($args -> {"now"}, $args -> {"userid"}, $args -> {"ident"}, $args -> {"subject"}, $args -> {"message"}, $format, $args -> {"send_after"}); my $result = $newh -> execute($args -> {"now"}, $args -> {"userid"}, $args -> {"ident"}, $args -> {"subject"}, $args -> {"message"}, $args -> {"format"}, $args -> {"send_after"});
return $self -> self_error("Unable to perform message insert: ". $self -> {"dbh"} -> errstr) if(!$result); return $self -> self_error("Unable to perform message insert: ". $self -> {"dbh"} -> errstr) if(!$result);
return $self -> self_error("Message insert failed, no rows inserted") if($result eq "0E0"); return $self -> self_error("Message insert failed, no rows inserted") if($result eq "0E0");