re-try put if newer version allready exists, unbless cloned data
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 13 Aug 2009 12:00:38 +0000 (12:00 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 13 Aug 2009 12:00:38 +0000 (12:00 +0000)
lib/PXElator/CouchDB.pm

index 7e012f2..8eae090 100644 (file)
@@ -80,11 +80,19 @@ sub put {
                $rev->{$url} = $json->{_rev} = $old if defined $old;
        }
 
-       $json = unbless dclone $json if blessed $json;
+       my $data = dclone $json;
+       $data = unbless $data if blessed $data;
 
-       $json = JSON->new->utf8->encode( $json ) if $json;
+       warn dump( $data );
 
-       $self->request(PUT => $url, $json);
+       $json = JSON->new->utf8->encode( $data );
+
+       warn $json;
+
+       do {
+               eval { $self->request(PUT => $url, $json) };
+               $rev->{$url} = $self->get( $url )->{_rev} if $@;
+       } until ! $@;
 }
 
 sub post {
@@ -103,7 +111,7 @@ sub audit {
        $url =~ s/\W+/-/g;
 
        my ( $package, $file, $line, $sub ) = caller(1);
-       ( $package, undef, $line ) = caller(0) if $package eq 'main';
+#      ( $package, undef, $line ) = caller(0) if $package eq 'main';
 
        my $time = time();
 
@@ -113,6 +121,7 @@ sub audit {
 
        $time = int($time); # reduce granularity
        $audit->put( "pxelator/$time.$package.$url", $data );
+
 }
 
 1;