Changeset 404


Ignore:
Timestamp:
11/15/11 09:16:16 (12 years ago)
Author:
nanardon
Message:
  • split rpm parsing and directory notify
Location:
server/trunk/web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/bin/sophie_scan

    r337 r404  
    33use strict; 
    44use warnings; 
    5 use Linux::Inotify2; 
    6 use POSIX ":sys_wait_h"; 
    75use Getopt::Long; 
    86use Sophie::Scan; 
     
    119require Sophie::Scan::RpmsPath; 
    1210 
    13 GetOptions( 
    14     'bdelay=i' =>  \my $updated_inotify, 
    15     'd|daemon'  => \my $daemon, 
    16 ) or die "Wrong options"; 
     11my $scan = Sophie::Scan->new; 
     12$scan->update_meta_paths; 
    1713 
    18 $SIG{CHLD} = sub { wait }; 
     14my @pkey = $scan->list_unscanned_paths; 
    1915 
    20 my %modified_paths; 
    21 my $inotify = undef; 
    22 $updated_inotify ||= 500; 
     16foreach my $pathkey (@pkey) { 
     17    my $time = time; 
     18    my @delta = Sophie::Scan::RpmsPath 
     19    ->new($pathkey, Sophie::Scan->new) 
     20    ->find_delta; 
     21    while (my @d = splice(@delta, 0, 25)) { 
     22        my $scan = Sophie::Scan->new; 
     23        my $path = Sophie::Scan::RpmsPath->new($pathkey, $scan); 
     24        $path->update_content(@d); 
     25        last if (time > $time + 15 * 60); 
     26    } 
    2327 
    24 if ($daemon) { 
    25     if (fork()) { 
    26         exit(0); 
    27     } 
     28    Sophie::Scan::RpmsPath->new($pathkey, Sophie::Scan->new)->set_updated 
     29    if (!@delta); # update only if we finished 
    2830} 
    2931 
    30 my $update = 1; 
    31 alarm($updated_inotify); 
    32 while (1) { 
    33     local $SIG{ALRM} = sub { 
    34         alarm($updated_inotify); 
    35         $update = 1; 
    36     }; 
    37     if ($update) { 
    38         if (update_base(keys %modified_paths)) { 
    39             %modified_paths = (); 
    40             $update = 0; 
    41         } 
    42     } 
    43     warn "$$ Inotify"; 
    44     $inotify = inotify_path(); 
    45     if ($inotify) { 
    46         $inotify->poll and $update = 1; 
    47     } else { 
    48         sleep(300); 
    49     } 
    50 } 
    51  
    52 sub inotify_path { 
    53  
    54     my $i = Linux::Inotify2->new; 
    55      
    56     my @paths = Sophie::Scan->new->list_paths; 
    57     if (!@paths) { 
    58         return; 
    59     } 
    60     foreach (@paths) { 
    61         -d $_ or next; 
    62         $i->watch( 
    63             $_, 
    64             IN_DELETE | IN_MODIFY | IN_CREATE, 
    65             sub { 
    66                 my $e = shift; 
    67                 warn $e->w->name; 
    68                 $modified_paths{$e->w->name} = 1; 
    69                 1; 
    70             } 
    71         ) 
    72     } 
    73  
    74     $i; 
    75 } 
    76  
    77 sub update_base { 
    78     my @path = @_; 
    79  
    80     if (waitpid(-1, &WNOHANG) != -1) { 
    81         warn "child still running"; 
    82         return; 
    83     } 
    84     warn "$$ updating base"; 
    85     if (my $pid = fork()) { 
    86     } else { 
    87         alarm 0; 
    88         my $scan = Sophie::Scan->new; 
    89         $scan->update_meta_paths; 
    90  
    91         my @pkey; 
    92         { 
    93             @pkey = $scan->paths_to_keys(@path); 
    94              
    95             push(@pkey, $scan->list_unscanned_paths); 
    96         } 
    97  
    98         exit(0) if (!@pkey); 
    99  
    100         foreach my $pathkey (@pkey) { 
    101             my $time = time; 
    102             my @delta = Sophie::Scan::RpmsPath 
    103                 ->new($pathkey, Sophie::Scan->new) 
    104                 ->find_delta; 
    105             while (my @d = splice(@delta, 0, 25)) { 
    106                 my $scan = Sophie::Scan->new; 
    107                 my $path = Sophie::Scan::RpmsPath->new($pathkey, $scan); 
    108                 $path->update_content(@d); 
    109                 last if (time > $time + 15 * 60); 
    110             } 
    111  
    112             Sophie::Scan::RpmsPath->new($pathkey, Sophie::Scan->new)->set_updated 
    113                 if (!@delta); # update only if we finished 
    114         } 
    115         exit(0); 
    116     } 
    117     return 1; 
    118 } 
    119  
  • server/trunk/web/lib/Sophie/Scan.pm

    r362 r404  
    2525 
    2626    return $self->base->resultset('Paths')->search({ 
    27             updated => [ undef, 
    28             \[ " < now() - '24 hours'::interval"], 
     27            -or => [ 
     28                updated => [  
     29                    undef, 
     30                    \[ " < now() - '24 hours'::interval"], 
     31                ], 
     32                { needupdate => 'true', }, 
    2933            ], 
    3034    })->get_column('d_path_key')->all 
Note: See TracChangeset for help on using the changeset viewer.