more spectre goodness, it almost runs!!
This commit is contained in:
parent
9ff0794746
commit
d9a80d9f6f
6 changed files with 78 additions and 43 deletions
|
|
@ -1,4 +1,20 @@
|
|||
# config-file-format: JSON 1
|
||||
|
||||
{
|
||||
|
||||
# Define a port for Spectre to run on between 1024 and 65000.
|
||||
port = 32133
|
||||
|
||||
"port" : 32133,
|
||||
|
||||
# How many Spectre workers should be allowed to be running at
|
||||
# one time. Keep in mind that workers use some of the resources
|
||||
# of your web site. If you're running only one server, you probably
|
||||
# shouldn't have more than 5 workers. If you're running load
|
||||
# balanced servers, you can probably have as many as 5 per server,
|
||||
# but depending upon the amount of editing and workflows you have
|
||||
# on your site, you may not need that many.
|
||||
|
||||
"maxWorkers" : 3
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ use strict;
|
|||
use POE;
|
||||
use POE::Component::IKC::Server;
|
||||
use POE::Component::IKC::Specifier;
|
||||
use Spectre::Cron;
|
||||
use Spectre::Workflow;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -33,7 +35,6 @@ sub _start {
|
|||
my $serviceName = "admin";
|
||||
$kernel->alias_set($serviceName);
|
||||
$kernel->call( IKC => publish => $serviceName, $publicEvents );
|
||||
my $configs = WebGUI::Config->readAllConfigs($self->{_webguiRoot});
|
||||
print "OK\n";
|
||||
}
|
||||
|
||||
|
|
@ -55,31 +56,31 @@ sub _stop {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( webguiRoot )
|
||||
=head2 new ( config )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 webguiRoot
|
||||
=head3 config
|
||||
|
||||
The path to the root of the WebGUI installation.
|
||||
A WebGUI::Config object that represents the spectre.conf file.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $webguiRoot = shift;
|
||||
my $self = {_webguiRoot=>$webguiRoot};
|
||||
my $config = shift;
|
||||
my $self = {_config=>$config};
|
||||
bless $self, $class;
|
||||
create_ikc_server(
|
||||
port => 32133,
|
||||
port => $config->get("port"),
|
||||
name => 'Spectre',
|
||||
);
|
||||
POE::Session->create(
|
||||
object_states => [ $self => {_start=>"_start", _stop=>"_stop", "shutdown"=>"_stop"} ],
|
||||
args=>[["shutdown"]]
|
||||
);
|
||||
$self->{_cron} = Spectre::Cron->new($webguiRoot);
|
||||
$self->{_workflow} = Spectre::Workflow->new($webguiRoot);
|
||||
$self->{_cron} = Spectre::Cron->new($config);
|
||||
$self->{_workflow} = Spectre::Workflow->new($config);
|
||||
POE::Kernel->run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ sub _start {
|
|||
my $serviceName = "scheduler";
|
||||
$kernel->alias_set($serviceName);
|
||||
$kernel->call( IKC => publish => $serviceName, $publicEvents );
|
||||
my $configs = WebGUI::Config->readAllConfigs($self->{_webguiRoot});
|
||||
my $configs = WebGUI::Config->readAllConfigs($self->{_config}->getWebguiRoot);
|
||||
foreach my $config (keys %{$configs}) {
|
||||
$kernel->yield("loadSchedule", $config);
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ The config filename for the site to load the schedule.
|
|||
|
||||
sub loadSchedule {
|
||||
my ($kernel, $self, $config) = @_[KERNEL, OBJECT, ARG0];
|
||||
my $session = WebGUI::Session->open($self->{_webguiRoot}, $config);
|
||||
my $session = WebGUI::Session->open($self->{_config}->getWebguiRoot, $config);
|
||||
my $result = $session->db->read("select * from WorkflowSchedule");
|
||||
while (my $data = $result->hashRef) {
|
||||
$kernel->yield("addJob",$config, $data);
|
||||
|
|
@ -170,24 +170,24 @@ sub loadSchedule {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( webguiRoot )
|
||||
=head2 new ( config )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 webguiRoot
|
||||
=head3 config
|
||||
|
||||
The path to the root of the WebGUI installation.
|
||||
A WebGUI::Config object that represents the spectre.conf file.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $webguiRoot = shift;
|
||||
my $self = {_webguiRoot=>$webguiRoot};
|
||||
my $config = shift;
|
||||
my $self = {_config=>$config};
|
||||
bless $self, $class;
|
||||
my @publicEvents = qw(addJob deleteJob);
|
||||
POE::Session->create(
|
||||
object_states => [ $self => [qw(_start _stop checkEvents checkEvent loadSchedule), @publicEvents] ],
|
||||
object_states => [ $self => [qw(_start _stop checkSchedules checkSchedule loadSchedule), @publicEvents] ],
|
||||
args=>[\@publicEvents]
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ sub _start {
|
|||
my $serviceName = "workflow";
|
||||
$kernel->alias_set($serviceName);
|
||||
$kernel->call( IKC => publish => $serviceName, $publicEvents );
|
||||
my $configs = WebGUI::Config->readAllConfigs($self->{_webguiRoot});
|
||||
my $configs = WebGUI::Config->readAllConfigs($self->{_config}->getWebguiRoot);
|
||||
foreach my $config (keys %{$configs}) {
|
||||
$kernel->yield("loadWorkflows", $config);
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ Checks to see if there are any open job slots available, and if there are assign
|
|||
|
||||
sub checkJobs {
|
||||
my ($kernel, $self) = @_[KERNEL, OBJECT];
|
||||
if ($self->countRunningJobs < 5) {
|
||||
if ($self->countRunningJobs < $self->{_config}->get("maxWorkers")) {
|
||||
my $job = $self->getNextJob;
|
||||
if (defined $job) {
|
||||
$job->{status} = "running";
|
||||
|
|
@ -163,7 +163,7 @@ sub getNextJob {
|
|||
|
||||
sub loadWorkflows {
|
||||
my ($kernel, $self, $config) = @_[KERNEL, OBJECT, ARG0];
|
||||
my $session = WebGUI::Session->open($self->{_webguiRoot}, $config);
|
||||
my $session = WebGUI::Session->open($self->{_config}->getWebguiRoot, $config);
|
||||
my $result = $session->db->read("select * from WorkflowInstance");
|
||||
while (my $data = $result->hashRef) {
|
||||
$kernel->yield("addJob", $config, $data);
|
||||
|
|
@ -173,11 +173,11 @@ sub loadWorkflows {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( webguiRoot )
|
||||
=head2 new ( config )
|
||||
|
||||
Constructor. Loads all active workflows from each WebGUI site and begins executing them.
|
||||
|
||||
=head3 webguiRoot
|
||||
=head3 config
|
||||
|
||||
The path to the root of the WebGUI installation.
|
||||
|
||||
|
|
@ -185,8 +185,8 @@ The path to the root of the WebGUI installation.
|
|||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $webguiRoot = shift;
|
||||
my $self = {_webguiRoot=>$webguiRoot};
|
||||
my $config = shift;
|
||||
my $self = {_config=>$config};
|
||||
bless $self, $class;
|
||||
my @publicEvents = qw(addJob deleteJob);
|
||||
POE::Session->create(
|
||||
|
|
|
|||
|
|
@ -32,10 +32,18 @@ This package parses the WebGUI config file.
|
|||
|
||||
use WebGUI::Config;
|
||||
|
||||
$hashRef = WebGUI::Config::getConfig($webguiRoot, $configFile);
|
||||
$hashRef = WebGUI::Config::readConfig($webguiRoot, $configFile);
|
||||
|
||||
WebGUI::Config::loadAllConfigs($webguiRoot);
|
||||
|
||||
my $configs = WebGUI::Config::readAllConfigs($webguiRoot);
|
||||
|
||||
my $config = WebGUI::Config->new($webguiRoot, $configFileName);
|
||||
|
||||
my $value = $config->get($param);
|
||||
$config->set($param,$value);
|
||||
$config->delete($param);
|
||||
|
||||
my $configFileName = $config->getFilename;
|
||||
my $webguiRoot = $config->getWebguiRoot;
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
|
|
@ -151,7 +159,7 @@ sub loadAllConfigs {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( webguiRoot , configFile )
|
||||
=head2 new ( webguiRoot , configFile [ , noCache ] )
|
||||
|
||||
Returns a hash reference containing the configuration data. It tries to get the data out of the memory cache first, but reads the config file directly if necessary.
|
||||
|
||||
|
|
@ -163,12 +171,17 @@ The path to the WebGUI installation.
|
|||
|
||||
The filename of the config file to read.
|
||||
|
||||
=head3 noCache
|
||||
|
||||
A boolean value that when set to true tells the config system not to store the config in an in memory cache, in case it's loaded again later. This is mostly used when loading utility configs, like spectre.conf.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $webguiPath = shift;
|
||||
my $filename = shift;
|
||||
my $noCache = shift;
|
||||
if (exists $config{$filename}) {
|
||||
return $config{$filename};
|
||||
} else {
|
||||
|
|
@ -181,7 +194,7 @@ sub new {
|
|||
my $conf = jsonToObj($json);
|
||||
my $self = {_webguiRoot=>$webguiPath, _configFile=>$filename, _config=>$conf};
|
||||
bless $self, $class;
|
||||
$config{$filename} = $self;
|
||||
$config{$filename} = $self unless $noCache;
|
||||
return $self;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,52 +11,57 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use lib '../lib';
|
||||
use Spectre::Admin;
|
||||
use Getopt::Long;
|
||||
use POE::Component::IKC::ClientLite;
|
||||
use Spectre::Admin;
|
||||
use WebGUI::Config;
|
||||
|
||||
$|=1; # disable output buffering
|
||||
my $help;
|
||||
my $shutdown;
|
||||
my $daemon;
|
||||
|
||||
GetOptions(
|
||||
'help'=>\$help,
|
||||
'shutdown'=>\$shutdown
|
||||
'shutdown'=>\$shutdown,
|
||||
'daemon'=>\$daemon
|
||||
);
|
||||
|
||||
if ($help) {
|
||||
if ($help || !($shutdown||$daemon)) {
|
||||
print <<STOP;
|
||||
|
||||
S.P.E.C.T.R.E. is the Supervisor of Perplexing Event-handling Contraptions for
|
||||
Triggering Relentless Executions. It handles WebGUI's workflow, mail sending,
|
||||
search engine indexing, and other background processes.
|
||||
|
||||
Usage:
|
||||
|
||||
perl spectre.pl
|
||||
Usage: perl spectre.pl [ options ]
|
||||
|
||||
|
||||
Options:
|
||||
|
||||
--daemon Starts the Spectre server.
|
||||
|
||||
--shutdown Stops the running Spectre server.
|
||||
|
||||
STOP
|
||||
exit;
|
||||
}
|
||||
|
||||
my $config = WebGUI::Config->new("..","spectre.conf",1);
|
||||
|
||||
if ($shutdown) {
|
||||
my $remote = create_ikc_client(
|
||||
port=>32133,
|
||||
port=>$config->get("port"),
|
||||
ip=>'127.0.0.1',
|
||||
name=>rand(100000),
|
||||
timeout=>10
|
||||
);
|
||||
die $POE::Component::IKC::ClientLite::error unless $remote;
|
||||
my $result = $remote->post('scheduler/shutdown');
|
||||
my $result = $remote->post('admin/shutdown');
|
||||
die $POE::Component::IKC::ClientLite::error unless defined $result;
|
||||
undef $remote;
|
||||
exit;
|
||||
} elsif ($daemon) {
|
||||
fork and exit;
|
||||
Spectre::Admin->new($config);
|
||||
}
|
||||
|
||||
fork and exit;
|
||||
|
||||
Spectre::Admin->new("/data/WebGUI");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue