diff --git a/lib/Spectre/Workflow.pm b/lib/Spectre/Workflow.pm index 9ec63394a..67924b43f 100644 --- a/lib/Spectre/Workflow.pm +++ b/lib/Spectre/Workflow.pm @@ -274,7 +274,7 @@ sub getJsonStatus { my ($sitename, $rsvp) = @$request; # only return this site's info - return $kernel->call(IKC=>post=>$rsvp, '{}') unless $sitename; + #return $kernel->call(IKC=>post=>$rsvp, '{}') unless $sitename; my %queues = (); tie %queues, 'Tie::IxHash'; @@ -283,17 +283,26 @@ sub getJsonStatus { Waiting => $self->getWaitingQueue, Running => $self->getRunningQueue, ); + my %output = (); - foreach my $queueName (keys %queues) { + for my $queueName (keys %queues) { my $queue = $queues{$queueName}; my $count = $queue->get_item_count; - my @instances; if ($count > 0) { - foreach my $itemAref ($queue->peek_items(sub { shift()->{sitename} eq $sitename })) { - push @instances, $itemAref; + for my $queueItem ($queue->peek_items(sub {1})) { + my($priority, $id, $instance) = @{$queueItem}; + # it's not a hash ref, we haven't seen it yet + if(ref $output{$instance->{sitename}} ne 'HASH') { + $output{$instance->{sitename}} = {}; + } + # it's not an array ref, we haven't seen it yet + if(ref $output{$instance->{sitename}}{$queueName} ne 'ARRAY') { + $output{$instance->{sitename}}{$queueName} = []; + } + $instance->{originalPriority} = ($instance->{priority} - 1) * 10; + push @{$output{$instance->{sitename}}{$queueName}}, $instance; } } - $output{$queueName} = \@instances; } $kernel->call(IKC=>post=>$rsvp, objToJson(\%output)); diff --git a/t/Spectre/Workflow.t b/t/Spectre/Workflow.t new file mode 100755 index 000000000..1ed17538f --- /dev/null +++ b/t/Spectre/Workflow.t @@ -0,0 +1,85 @@ +# vim: syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2006 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib", "/data/wre/lib"; +use WebGUI::Test; +use WebGUI::Session; +use Spectre::Admin; +use WebGUI::Config; +use WebGUI::Workflow::Cron; +use WebGUI::Workflow::Instance; +use WRE::Config; +use WRE::Modperl; +use WRE::Modproxy; +use WRE::Spectre; + +use POE::Component::IKC::ClientLite; +use JSON; +use Config::JSON; +use Data::Dumper; + +use Test::More tests => 10; # increment this value for each test you create + +$|++; + +my $session = WebGUI::Test->session; +my $wreConfig = WRE::Config->new; +my $isModPerlRunning = WRE::Modperl->new ( wreConfig=>$wreConfig)->ping; +my $isModProxyRunning = WRE::Modproxy->new( wreConfig=>$wreConfig)->ping; +my $isSpectreRunning = WRE::Spectre->new ( wreConfig=>$wreConfig)->ping; +my $spectreConfigFile = WebGUI::Test->root . '/etc/spectre.conf'; +my $spectreConfig = Config::JSON->new($spectreConfigFile); +my $ip = $spectreConfig->get('ip'); +my $port = $spectreConfig->get('port'); + +# put your tests here + +SKIP: { + skip "need modperl, modproxy, and spectre running to test", 10 unless ($isModPerlRunning && $isModProxyRunning && $isSpectreRunning); + # XXX kinda evil kludge to put an activity in the scheduler so that the + # below calls return data; suggestions on a better way to do this welcomed. + my $taskId = 'pbcron0000000000000001'; # hopefully people don't delete daily maintenance + my $task = WebGUI::Workflow::Cron->new($session, $taskId); + # just in case they did... + skip "need daily maintenance task for test", 10 unless defined $task; + my $instance = WebGUI::Workflow::Instance->create($session, { + workflowId => $task->get('workflowId'), + className => $task->get('className'), + methodName => $task->get('methodName'), + parameters => $task->get('parameters'), + priority => $task->get('priority'), + }, + ); + my $remote = create_ikc_client( + port => $port, + ip => $ip, + name => rand(100000), + timeout => 10 + ); + my $result = $remote->post_respond('workflow/getJsonStatus'); + ok(defined $result, 'can call getJsonStatus'); + $remote->disconnect; + undef $remote; + my $structure; + ok($structure = jsonToObj($result), 'workflow/getJsonStatus returns a proper JSON data structure'); + diag(Dumper $structure); + cmp_ok(ref $structure, 'eq', 'HASH', 'workflow/getJsonStatus returns a JSON structure parseable into a Perl hashref'); + my $sitename = $session->config->get('sitename')->[0]; + ok(exists $structure->{$sitename}, "$sitename exists in returned structure"); + for my $key(qw/Suspended Waiting Running/) { + ok(exists $structure->{$sitename}{$key}, "$key exists for $sitename"); + cmp_ok(ref $structure->{$sitename}{$key}, 'eq', 'HASH', "$key is a hashref in the $sitename hash"); + } + + +}