Commit 7bf2aa9a authored by Leigh Stoller's avatar Leigh Stoller

Various changes to support better web interface backend communication.

parent 8057c833
......@@ -126,13 +126,17 @@ sub Create($$;$)
{
my ($class, $object_uuid, $task_id) = @_;
# Kill existing.
my $existing = WebTask->LookupByObject($object_uuid);
$existing->Delete()
if (defined($existing));
if (defined($object_uuid)) {
DBQueryWarn("delete from web_tasks ".
"where object_uuid='$object_uuid'")
or return undef;
}
$task_id = TBGenSecretKey()
if (!defined($task_id));
# XXX
$object_uuid = $task_id
if (!defined($object_uuid));
DBQueryWarn("insert into web_tasks set task_id='$task_id', ".
" created=now(), object_uuid='$object_uuid'")
......@@ -152,6 +156,30 @@ sub Delete($)
return 0;
}
sub DeleteByObject($$)
{
my ($class, $uuid) = @_;
DBQueryWarn("delete from web_tasks where object_uuid='$uuid'")
or return -1;
return 0;
}
#
# Utility function to lookup and create if it does not exists.
#
sub LookupOrCreate($$$)
{
my ($class, $object_uuid, $webtask_id) = @_;
my $webtask = WebTask->Lookup($webtask_id);
if (!defined($webtask)) {
$webtask = WebTask->Create($object_uuid, $webtask_id);
}
return $webtask;
}
#
# Lookup by object id. We can get into a problem here if there
# is more then one.
......@@ -269,6 +297,7 @@ sub Exited($$)
my ($self, $exitcode) = @_;
my $task_id = $self->task_id();
$self->Store();
DBQueryWarn("update web_tasks set process_id=0, ".
" exited=now(), exitcode='$exitcode' ".
"where task_id='$task_id'")
......@@ -287,21 +316,5 @@ sub HasExited($)
return (defined($self->exited()) ? 1 : 0);
}
#
# Delete webtask associated with an object. Class method.
#
sub DeleteByObject($$)
{
my ($class, $object) = @_;
my $uuid = (ref($object) ? $object->uuid() : $object);
my $webtask = WebTask->LookupByObject($uuid);
return 0
if (!defined($webtask));
$webtask->Delete();
return 0;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment