test file_size with send to different shard
[cloudstore.git] / gearman / send_file.pl
index 9fbd698..4c5820f 100755 (executable)
@@ -2,10 +2,18 @@
 use warnings;
 use strict;
 
+=head1 NAME
+
+Filesystem Gearman Worker
+
+=cut
+
+
 use Data::Dump qw(dump);
 
 use lib '/srv/cloudstore/lib';
 use CloudStore::API;
+use WarnColor;
 
 my $api = CloudStore::API->new('s1');
 
@@ -13,8 +21,9 @@ use Gearman::Worker;
 my $worker = Gearman::Worker->new;
 $worker->job_servers('127.0.0.1:4730');
 
-open(my $log, '>>', '/rsync1/s1/log/send_file.log');
-select($log); $|++;
+=head2 send_file ~u2001/from.txt#~u2003/dir/new to.txt
+
+=cut
 
 $worker->register_function( send_file => sub {
        my ($job) = @_;
@@ -33,6 +42,10 @@ $worker->register_function( send_file => sub {
        $api->send_file( $f_uid => $from, $t_uid => $to );
 });
 
+=head2 rename_file ~u2001/old.txt#new.txt
+
+=cut
+
 $worker->register_function( rename_file => sub {
        my ($job) = @_;
 
@@ -45,6 +58,10 @@ $worker->register_function( rename_file => sub {
        $api->rename_file( $login, $from, $to );
 });
 
+=head2 delete ~u2001/file_or_dir
+
+=cut
+
 $worker->register_function( delete => sub {
        my ($job) = @_;
        my $work = $job->arg;
@@ -56,6 +73,24 @@ $worker->register_function( delete => sub {
 
 });
 
+=head2 file_size ~u2001/foo.txt
+
+=cut
+
+$worker->register_function( file_size => sub {
+       my ($job) = @_;
+       my $work = $job->arg;
+       chomp $work;
+       warn "# file_size [$work]\n";
+
+       my $login = $1 if $work =~ s{~(\w+)}{};
+       $api->file_size( $login, $work );
+});
+
+=head2 user_usage u2001
+
+=cut
+
 $worker->register_function( user_usage => sub {
        my ($job) = @_;
        my $work = $job->arg;
@@ -67,11 +102,5 @@ $worker->register_function( user_usage => sub {
 
 warn "$0 pid $$ waitng for jobs\n";
 
-if ( $ENV{SLICE} ) {
-       chroot $ENV{SLICE} || die "can't chroot $ENV{SLICE}: $!";
-} else {
-       warn "WARNING: not running under chroot SLICE=/hostname/sx\n";
-}
-
 $worker->work while 1;