X-Git-Url: http://git.rot13.org/?p=angular-mojolicious.git;a=blobdiff_plain;f=couchdb-trigger.pl;h=1724b6703c024e2b36a7982d27014132cde44d3b;hp=873beeece38e6e3f13fb60665f4391c50a0c97f4;hb=ae014afaa20d0fdc2032fbe9f0befc1c4598cc80;hpb=7a00de959d5462d5a52ab35fcd49b71f2ef83936 diff --git a/couchdb-trigger.pl b/couchdb-trigger.pl index 873beee..1724b67 100755 --- a/couchdb-trigger.pl +++ b/couchdb-trigger.pl @@ -25,6 +25,8 @@ my ( $url, $trigger_path ) = @ARGV; $url ||= 'http://localhost:5984/monitor'; $trigger_path ||= 'trigger/shell.pm' ; +our $database = $1 if $url =~ m{/(\w+)/?$}; + sub commit { warn "# commit ignored\n"; } require $trigger_path if -e $trigger_path; @@ -46,12 +48,9 @@ while( ! $error ) { $tx->res->body(sub{ my ( $content, $body ) = @_; - debug 'BODY' => $body; + return if length($body) == 0; # empty chunk, heartbeat? - if ( length($body) == 0 ) { - warn "# empty chunk, heartbeat?\n"; - return; - } + debug 'BODY' => $body; foreach ( split(/\r?\n/, $body) ) { # we can get multiple documents in one chunk @@ -84,7 +83,7 @@ while( ! $error ) { if ( $tx->res->code == 409 ) { info "TRIGGER ABORTED started on another worker? ", $tx->error; } else { - info "ERROR ", $tx->error; + info "ERROR $url/$id ", $tx->error; } } else { my $res = $tx->res->json; @@ -98,7 +97,7 @@ while( ! $error ) { $client->put( "$url/$id" => $json->encode( $change->{doc} ) => sub { my ($client,$tx) = @_; if ($tx->error) { - info "ERROR", $tx->error; + info "ERROR $url/$id", $tx->error; } else { my $res = $tx->res->json; $change->{doc}->{_rev} = $res->{rev};