Export a method from Workflow::Activity for timeouts and use it in all current Workflows

This commit is contained in:
Colin Kuskie 2008-08-30 20:34:52 +00:00
parent 85ecaa9a09
commit 726bd5ee05
12 changed files with 36 additions and 12 deletions

View file

@ -265,6 +265,19 @@ sub getName {
#-------------------------------------------------------------------
=head2 getTTL ( )
Returns the maximum amount of time, in seconds, that a Workflow
Activity should run. Currently 55 seconds.
=cut
sub getTTL {
return 55;
}
#-------------------------------------------------------------------
=head2 new ( session, activityId )
Constructor.

View file

@ -354,8 +354,9 @@ sub execute {
}
}
}
my $ttl = $self->getTTL;
while (@$eventList) {
if ($startTime + 55 < time()) {
if ($startTime + $ttl < time()) {
$instance->setScratch('events', encode_json($eventList));
$instance->setScratch('feeds', encode_json($feedList));
return $self->WAITING;

View file

@ -70,7 +70,7 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute {
my $self = shift;
my $versionTag = shift;
my $completion = $versionTag->commit({timeout=>55});
my $completion = $versionTag->commit({timeout => $self->getTTL});
if ($completion == 1) {
return $self->COMPLETE;
} elsif ($completion == 2) {

View file

@ -70,13 +70,14 @@ sub execute {
my $self = shift;
my $sth = $self->session->db->read("select sessionId from userSession where expires<?",[time()]);
my $time = time();
my $ttl = $self->getTTL;
while (my ($sessionId) = $sth->array) {
my $session = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename, undef, undef, $sessionId, 1);
if (defined $session) {
$session->var->end;
$session->close;
}
if ((time() - $time) > 55) {
if ((time() - $time) > $ttl) {
$sth->finish;
return $self->WAITING;
}

View file

@ -93,18 +93,20 @@ sub execute {
my @files = @$filesRef;
my @dirs = @{$instance->getScratch(PRUNE_DIRS_SCRATCH) || []};
my $ttl = $self->getTTL;
while (defined(my $filename = shift @files)) {
my $cfilename = $self->_canonExportPath($filename);
unlink $cfilename or $self->session->errorHandler->warn("DeleteExportedFiles: Couldn't unlink $filename: $!"), next;
push @dirs, $self->_pruneOfFile($filename);
goto pause if (time - $time > 55);
goto pause if (time - $time > $ttl);
}
my $ttl = $self->getTTL;
while (defined(my $dirname = shift @dirs)) {
my $cdirname = $self->_canonExportPath($dirname);
rmdir $cdirname or $self->session->errorHandler->warn("DeleteExportedFiles: couldn't rmdir $dirname: $!"), next;
push @dirs, $self->_pruneOfFile($dirname);
goto pause if (time - $time > 55);
goto pause if (time - $time > $ttl);
}
done:

View file

@ -83,12 +83,13 @@ sub execute {
my $now = WebGUI::DateTime->new($session, $start);
my $outdated = DateTime::Duration->new(seconds => $self->get("timeout"));
my $pending = WebGUI::Friends->getAllPendingAddRequests($session);
my $ttl = $self->getTTL;
while (my $invite = $pending->hashRef) {
my $sentOn = WebGUI::DateTime->new($session, $invite->{dateSent});
if (DateTime::Duration->compare($now - $sentOn, $outdated) == 1) {
WebGUI::Friends->new($session, WebGUI::User->new($session, $invite->{friendId}))->rejectAddRequest($invite->{inviteId});
}
if (time() - $start > 55) {
if (time() - $start > $ttl) {
$pending->finish;
return $self->WAITING;
}

View file

@ -81,13 +81,14 @@ sub execute {
my $start = time();
my $log = $self->session->errorHandler;
$log->info('Searching for EMS items that have been in the cart too long.');
my $ttl = $self->getTTL;
my $items = $self->session->db->read("select itemId, cartId, assetId from cartItem where
assetId in (select assetId from asset where className like 'WebGUI::Asset::Sku::EMS%')
and DATE_ADD(dateAdded, interval ".($self->get("expireAfter") + 0)." second) < now()");
while (my ($itemId, $cartId, $assetId) = $items->array) {
$log->info('Removing item '.$itemId.' (asset '.$assetId.') from cart '.$cartId);
WebGUI::Shop::Cart->new($self->session, $cartId)->getItem($itemId)->remove;
if (time() - $start > 55) {
if (time() - $start > $ttl) {
$items->finish;
$log->('Ran out of time. Will have to expire the rest later.');
return $self->WAITING;

View file

@ -167,6 +167,7 @@ sub execute {
my $i18n = WebGUI::International->new($self->session, "Asset_Collaboration");
my $postGroup = $cs->get("postGroupId"); #group that's allowed to post to the CS
my $ttl = $self->getTTL;
while (my $message = $mail->getNextMessage) {
next unless (scalar(@{$message->{parts}})); # no content, skip it
my $from = $message->{from};
@ -227,7 +228,7 @@ sub execute {
$send->send;
}
# just in case there are a lot of messages, we should release after a minutes worth of retrieving
last if (time() > $start + 60);
last if (time() > $start + $ttl);
}
$mail->disconnect;
return $self->COMPLETE;

View file

@ -79,6 +79,7 @@ sub execute {
# start time to check for timeouts
my $time = time();
my $ttl = $self->getTTL;
my @syndicatedUrls = @{$self->getSyndicatedUrls($instance)};
while (my $url = shift(@syndicatedUrls)) {
@ -91,7 +92,7 @@ sub execute {
}
# Check for timeout
last
if (time() - $time > 55);
if (time() - $time > $ttl);
}
# if there are urls left, we need to process again

View file

@ -90,6 +90,7 @@ sub execute {
my $sth = $session->db->read("select assetData.assetId,asset.className,assetData.revisionDate from asset
left join assetData on asset.assetId=assetData.assetId where assetData.revisionDate<?
order by assetData.revisionDate asc", [$suspectDate]);
my $ttl = $self->getTTL;
while (my ($id, $class, $version) = $sth->array) {
# we never want to purge the current version
@ -110,7 +111,7 @@ sub execute {
}
# give up if we're taking too long
if (time() - $start > 55) {
if (time() - $start > $ttl) {
$log->info("Ran out of time, will pick up with revision $version when we start again.");
$instance->setScratch("purgeOldAssetsLastRevisionDate", $version);
$sth->finish;

View file

@ -70,6 +70,7 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute {
my $self = shift;
my $start = time();
my $ttl = $self->getTTL;
foreach my $id (@{WebGUI::Mail::Send->getMessageIdsInQueue($self->session)}) {
my $message = WebGUI::Mail::Send->retrieve($self->session, $id);
if (defined $message) {
@ -79,7 +80,7 @@ sub execute {
}
}
# just in case there are a lot of messages, we should release after a minutes worth of sending
last if (time() > $start + 60);
last if (time() > $start + $ttl);
}
return $self->COMPLETE;
}

View file

@ -133,6 +133,7 @@ sub execute {
my ($currentLinkId, $link, $ldapUrl, $ldap);
my $skippingLink = 0;
my $ttl = $self->getTTL;
while (my ($userId, $rowLinkId) = $sth->array) {
if ($rowLinkId ne $currentLinkId) {
$link->unbind if defined $link;
@ -178,7 +179,7 @@ sub execute {
} continue {
$index++;
if (time - $startTime >= 55) {
if (time - $startTime >= $ttl) {
# $self->session->errorHandler->warn("DEBUG: SyncProfilesToLdap: next round");
$link->unbind if defined $link;
$instance->setScratch('ldapSelectIndex', $index);