adding delays and more debug

This commit is contained in:
JT Smith 2006-03-17 02:07:50 +00:00
parent 71b2634741
commit df0d073120
2 changed files with 26 additions and 6 deletions

View file

@ -20,7 +20,20 @@
# but depending upon the amount of editing and workflows you have
# on your site, you may not need that many.
"maxWorkers" : 3
"maxWorkers" : 3,
# How many seconds should Spectre wait between spawning jobs. This
# can help avoid creating a denial of service attack on overworked
# or underpowered servers.
"timeBetweenJobs" : 5,
# The number of seconds that Spectre should wait after an activity
# has been suspended before it should start it back up again. An
# activity may be suspended if it's waiting on user input, or
# if it returns an error.
"delayAfterSuspension" : 500
}

View file

@ -106,6 +106,7 @@ sub checkJobs {
$kernel->yield("runWorker",$job);
}
}
$kernel->delay_set("checkJobs",$self->config->get("timeBetweenJobs"));
}
#-------------------------------------------------------------------
@ -186,6 +187,10 @@ sub getNextJob {
$self->debug("Looking for a workflow instance to execute.");
foreach my $priority (1..3) {
foreach my $job (@{$self->{"_priority".$priority}}) {
if (time() > $job->{statusDelay} & $job->{status}) {
delete $job->{statusDelay};
$job->{status} eq "waiting";
}
if ($job->{status} eq "waiting") {
$self->debug("Looks like ".$job->{instanceId}." would be a good workflow instance to run.");
return $job;
@ -288,7 +293,8 @@ sub suspendJob {
my $self = shift;
my $instanceId = shift;
$self->debug("Suspending workflow instance ".$instanceId.".");
$self->{_jobs}{$instanceId}{status} = "waiting";
$self->{_jobs}{$instanceId}{status} = "delay";
$self->{_jobs}{$instanceId}{statusDelay} = $self->config->get("delayAfterSuspension") + time();
for (my $i=0; $i < scalar(@{$self->{_runningJobs}}); $i++) {
if ($self->{_runningJobs}[$i]{instanceId} eq $instanceId) {
splice(@{$self->{_runningJobs}}, $i, 1);
@ -323,9 +329,10 @@ sub workerResponse {
my $state = $payload->{state};
if ($state eq "waiting") {
$self->debug("Was told to wait on $jobId because we're still waiting on some external event.");
$self->suspendJob($jobId, $self->config->get("waitTime"));
$self->suspendJob($jobId);
} elsif ($state eq "complete") {
$self->debug("Workflow instance $jobId ran one of it's activities successfully.");
$self->suspendJob($jobId);
} elsif ($state eq "disabled") {
$self->debug("Workflow instance $jobId is disabled.");
$self->deleteJob($jobId);
@ -334,10 +341,10 @@ sub workerResponse {
$self->deleteJob($jobId);
} elsif ($state eq "error") {
$self->debug("Got an error for $jobId.");
$self->suspendJob($jobId, $self->config->get("waitTime"));
$self->suspendJob($jobId);
} else {
$self->debug("Something bad happened on the return of $jobId, so we're suspending it's run for a while.");
$self->suspendJob($jobId, $self->config->get("waitTime"));
$self->debug("Something bad happened on the return of $jobId.");
$self->suspendJob($jobId);
# something bad happened
}
} elsif ($response->is_redirect) {