Armadito-Agent

 view release on metacpan or  search on metacpan

lib/Armadito/Agent/Scheduler/Win32Native.pm  view on Meta::CPAN

	my $output = capture( EXIT_ANY, $cmdline );
	$self->{logger}->info($output);
	$self->{logger}->info( "Program exited with " . $EXITVAL . "\n" );
}

sub _createAllTasks {
	my ($self) = @_;

	foreach ( @{ $self->{config}->{tasks} } ) {
		$self->_createScheduledTask($_);
	}
}

sub _getExistingTasks {
	my ($self) = @_;

	my $cmdline = "schtasks /Query /FO CSV";
	my $output = capture( EXIT_ANY, $cmdline );
	$self->{logger}->info( "Program exited with " . $EXITVAL . "\n" );

	my $parser  = Armadito::Agent::Patterns::Matcher->new( logger => $self->{logger} );
	my $labels  = ['name'];
	my $pattern = '^"(\\\\ArmaditoAgentTask.*?)"';
	$parser->addPattern( 'tasks', $pattern, $labels );
	$parser->run( $output, '\n' );
	$parser->addHookForLabel( 'name', \&trimSlashes );

	return $parser->getResults();
}

sub trimSlashes {
	my ($match) = @_;
	$match =~ s/^\\+//ms;
	return $match;
}

sub _deleteExistingTask {
	my ( $self, $task ) = @_;

	my $cmdline = "schtasks /Delete /F /TN \"" . $task->{name} . "\"";
	$self->{logger}->info($cmdline);

	my $output = capture( EXIT_ANY, $cmdline );
	$self->{logger}->info($output);
	$self->{logger}->info( "Program exited with " . $EXITVAL . "\n" );
}

sub _deleteExistingTasks {
	my ($self) = @_;

	my $existing_tasks = $self->_getExistingTasks();

	foreach ( @{ $existing_tasks->{tasks} } ) {
		$self->_deleteExistingTask($_);
	}
}

sub run {
	my ( $self, %params ) = @_;

	$self = $self->SUPER::run(%params);
	$self->_loadConf();
	$self->_deleteExistingTasks();
	$self->_createAllTasks();

	return $self;
}

1;

__END__

=head1 NAME

Armadito::Agent::Scheduler::Win32Native - class for managing native Win32 Scheduler.

=head1 DESCRIPTION

This task inherits from L<Armadito::Agent::Task::Scheduler>. It allows remote management of agent's crontab configuration.

=head1 FUNCTIONS

=head2 run ( $self, %params )

Run the task.



( run in 0.812 second using v1.01-cache-2.11-cpan-5a3173703d6 )