AC-MrGamoo
view release on metacpan or search on metacpan
lib/AC/MrGamoo/Job/TaskInfo.pm view on Meta::CPAN
# -*- perl -*-
# Copyright (c) 2010 AdCopy
# Author: Jeff Weisberg
# Created: 2010-Apr-22 10:50 (EDT)
# Function: info about tasks
#
# $Id: TaskInfo.pm,v 1.1 2010/11/01 18:41:57 jaw Exp $
package AC::MrGamoo::Job::TaskInfo;
use AC::MrGamoo::Debug 'job_taskinfo';
use AC::MrGamoo::PeerList;
use AC::Misc;
use strict;
our @ISA = 'AC::MrGamoo::Job::Info';
my $MAXRETRY = 2;
sub new {
my $class = shift;
my $job = shift;
return bless { @_ }, $class;
}
sub pend {
my $me = shift;
my $job = shift;
return if $me->{replaced};
return if $me->{finished};
# create instance, put on pending queue
my $t = AC::MrGamoo::Job::Task->new($job, $me, $me->{server});
return unless $t;
$me->{instance}{ $t->{id} } = $t;
return;
}
sub finished {
my $me = shift;
my $t = shift;
my $job = shift;
delete $me->{instance}{ $t->{id} };
$me->{finished} = 1;
my $outfiles = $me->{outfile};
my $server = $t->{server};
debug("task finished $me->{id} on $server");
# copy files
for my $fi (@$outfiles){
# add to file_info - file is now on one server
debug(" outfile $fi->{filename}");
$job->{file_info}{ $fi->{filename} } = {
filename => $fi->{filename},
location => [ $server ],
};
$job->{server_info}{$server}{has_files}{$fi->{filename}} = 1;
# QQQ - optionally leave final files?
push @{$job->{tmp_file}}, { filename => $fi->{filename}, server => $server };
# add to copy_pending
foreach my $s ( @{$fi->{dst}} ){
next if $job->{server_info}{$s}{has_files}{$fi->{filename}};
my $c = AC::MrGamoo::Job::XferInfo->new( $job,
id => unique(),
filename => $fi->{filename},
dst => $s,
);
next unless $c;
$c->pend($job);
debug(" => pending copy for $s");
}
}
}
sub failed {
my $me = shift;
my $t = shift;
my $job = shift;
( run in 0.566 second using v1.01-cache-2.11-cpan-99c4e6809bf )