Permalink
Browse files

remove Coro temporalily because it have not worked before

  • Loading branch information...
1 parent 01c76fa commit 786ae142ad019bc37aa615c0b86fc59933abdf28 @shibayu36 shibayu36 committed Jun 3, 2012
Showing with 8 additions and 42 deletions.
  1. +0 −1 Build.PL
  2. +0 −16 lib/Cinnamon/Config.pm
  3. +8 −25 lib/Cinnamon/Runner.pm
View
@@ -20,7 +20,6 @@ my $build = Module::Build->new(
'Net::OpenSSH' => 0,
'Log::Dispatch' => 0,
'Class::Load' => 0,
- 'Coro' => 0,
'Term::ReadKey' => 0,
'Getopt::Long::Parser' => 0,
},
View
@@ -2,31 +2,23 @@ package Cinnamon::Config;
use strict;
use warnings;
-use Coro;
-use Coro::RWLock;
use Cinnamon::Config::Loader;
use Cinnamon::Logger;
my %CONFIG;
my %ROLES;
my %TASKS;
-my $lock = new Coro::RWLock;
-
sub set ($$) {
my ($key, $value) = @_;
- $lock->wrlock;
$CONFIG{$key} = $value;
- $lock->unlock;
}
sub get ($@) {
my ($key, @args) = @_;
- $lock->rdlock;
my $value = $CONFIG{$key};
- $lock->unlock;
$value = $value->(@args) if ref $value eq 'CODE';
$value;
@@ -35,19 +27,15 @@ sub get ($@) {
sub set_role ($$$) {
my ($role, $hosts, $params) = @_;
- $lock->wrlock;
$ROLES{$role} = [$hosts, $params];
- $lock->unlock;
}
sub get_role (@) {
my $role = ($_[0] || get('role'));
my $role_def = $ROLES{$role} or return undef;
- $lock->rdlock;
my ($hosts, $params) = @$role_def;
- $lock->unlock;
for my $key (keys %$params) {
set $key => $params->{$key};
@@ -62,9 +50,7 @@ sub get_role (@) {
sub set_task ($$) {
my ($task, $task_def) = @_;
- $lock->wrlock;
$TASKS{$task} = $task_def;
- $lock->unlock;
}
sub get_task (@) {
@@ -73,12 +59,10 @@ sub get_task (@) {
$task ||= get('task');
my @task_path = split(':', $task);
- $lock->rdlock;
my $value = \%TASKS;
for (@task_path) {
$value = $value->{$_};
}
- $lock->unlock;
$value;
}
View
@@ -2,42 +2,25 @@ package Cinnamon::Runner;
use strict;
use warnings;
-use Coro;
-
use Cinnamon::Logger;
use Cinnamon::Config;
sub start {
my ($class, $hosts, $task, @args) = @_;
- my $concurrency = Cinnamon::Config::get('concurrency') || 1;
my %result;
- my @workers;
- for my $job (@{$hosts || []}) {
- my $i = scalar(@$hosts) % $concurrency;
-
- $workers[$i] ||= [];
- push @{$workers[$i]}, $job;
+ for my $host (@$hosts) {
+ $result{$host} = +{ error => 0 };
- $result{$job} = +{ error => 0 };
- }
+ eval { $task->($host, @args) };
- my @coros;
- for my $jobs (@workers) {
- push @coros, async {
- for my $job (@$jobs) {
- eval { $task->($job, @args) };
-
- if ($@) {
- chomp $@;
- log error => sprintf '[%s] %s', $job, $@;
- $result{$job}->{error}++ ;
- }
- }
- };
+ if ($@) {
+ chomp $@;
+ log error => sprintf '[%s] %s', $host, $@;
+ $result{$host}->{error}++ ;
+ }
}
- $_->join for @coros;
\%result;
}

0 comments on commit 786ae14

Please sign in to comment.