- Simplified Spectre's initial data load, and reduced memory footprint in the

process.
This commit is contained in:
JT Smith 2007-02-01 18:48:23 +00:00
parent f140fdead4
commit b19bf14389
8 changed files with 159 additions and 73 deletions

View file

@ -219,6 +219,7 @@ sub getOperations {
'editSettings' => 'WebGUI::Operation::Settings',
'saveSettings' => 'WebGUI::Operation::Settings',
'spectreGetSiteData' => 'WebGUI::Operation::Spectre',
'spectreTest' => 'WebGUI::Operation::Spectre',
'viewStatistics' => 'WebGUI::Operation::Statistics',

View file

@ -11,8 +11,11 @@ package WebGUI::Operation::Spectre;
#-------------------------------------------------------------------
use strict;
use WebGUI::Utility;
use JSON;
use POE::Component::IKC::ClientLite;
use WebGUI::Utility;
use WebGUI::Workflow::Cron;
use WebGUI::Workflow::Instance;
=head1 NAME
@ -26,6 +29,60 @@ Operations for Spectre.
#-------------------------------------------------------------------
=head2 www_spectreGetSiteData ( )
Checks to ensure the requestor is who we think it is, and then returns a JSON string with worklfow and cron data. We do it in one payload for efficiency.
=cut
sub www_spectreGetSiteData {
my $session = shift;
$session->http->setMimeType("text/json");
$session->http->setCacheControl("none");
my %siteData = ();
if (!isInSubnet($session->env->get("REMOTE_ADDR"), $session->config->get("spectreSubnets"))) {
$session->errorHandler->security("make a Spectre workflow data load request, but we're only allowed to accept requests from "
.join(",",@{$session->config->get("spectreSubnets")}).".");
}
else {
my $sitename = $session->config->get("sitename")->[0];
my $gateway = $session->config->get("gateway");
my $cookieName = $session->config->getCookieName;
my @instances = ();
foreach my $instance (@{WebGUI::Workflow::Instance->getAllInstances($session)}) {
next unless $instance->getWorkflow->get("enabled");
push(@instances, {
instanceId => $instance->getId,
priority => $instance->get("priority"),
cookieName => $cookieName,
gateway => $gateway,
sitename => $sitename,
});
}
$siteData{workflow} = \@instances;
my @schedules = ();
foreach my $task (@{WebGUI::Workflow::Cron->getAllTasks($session)}) {
next unless $task->get("enabled");
push(@schedules, {
taskId => $task->getId,
cookieName => $cookieName,
gateway => $gateway,
sitename => $sitename,
minuteOfHour => $task->get('minuteOfHour'),
hourOfDay => $task->get('hourOfDay'),
dayOfMonth => $task->get('dayOfMonth'),
monthOfYear => $task->get('monthOfYear'),
dayOfWeek => $task->get('dayOfWeek'),
runOnce => $task->get('runOnce'),
});
}
$siteData{cron} = \@schedules;
}
return JSON::objToJson(\%siteData);
}
#-------------------------------------------------------------------
=head2 www_spectreTest ( )
Spectre executes this function to see if WebGUI connectivity is working.

View file

@ -122,6 +122,26 @@ sub get {
return $self->{_data}{$name};
}
#-------------------------------------------------------------------
=head2 getAllTasks ( session )
Returns an array reference of all the schedule objects defined in this system. A class method.
=cut
sub getAllTasks {
my $class = shift;
my $session = shift;
my @schedules = ();
my $rs = $session->db->read("SELECT taskId FROM WorkflowSchedule");
while (my ($taskId) = $rs->array) {
push(@schedules, WebGUI::Workflow::Cron->new($session, $taskId));
}
return \@schedules;
}
#-------------------------------------------------------------------
=head2 getId ( )

View file

@ -142,6 +142,27 @@ sub get {
return $self->{_data}{$name};
}
#-------------------------------------------------------------------
=head2 getAllInstances ( session )
Returns an array reference of all the instance objects defined in this system. A class method.
=cut
sub getAllInstances {
my $class = shift;
my $session = shift;
my @instances = ();
my $rs = $session->db->read("SELECT instanceId FROM WorkflowInstance");
while (my ($instanceId) = $rs->array) {
push(@instances, WebGUI::Workflow::Instance->new($session, $instanceId));
}
return \@instances;
}
#-------------------------------------------------------------------
=head2 getId ( )