Changeset 333 for server/trunk/web/bin
- Timestamp:
- 01/23/11 23:34:43 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/trunk/web/bin/sophie_scan
r332 r333 6 6 use POSIX ":sys_wait_h"; 7 7 use Getopt::Long; 8 use Sophie::Scan; 8 9 9 10 $ENV{LC_ALL} = 'C'; 10 require Sophie::Base; 11 require Sophie::Base::RpmsPath; 11 require Sophie::Scan::RpmsPath; 12 12 13 13 GetOptions( … … 28 28 } 29 29 30 my $update = 1; 30 31 alarm($updated_inotify); 31 32 while (1) { 32 33 local $SIG{ALRM} = sub { 33 34 alarm($updated_inotify); 35 $update = 1; 34 36 }; 35 if (update_base(keys %modified_paths)) { 36 %modified_paths = (); 37 if ($update) { 38 if (update_base(keys %modified_paths)) { 39 %modified_paths = (); 40 $update = 0; 41 } 37 42 } 38 43 warn "$$ Inotify"; 39 44 $inotify = inotify_path(); 40 $inotify->poll; 45 if ($inotify) { 46 $inotify->poll and $update = 1; 47 } else { 48 sleep(300); 49 } 41 50 } 42 51 … … 44 53 45 54 my $i = Linux::Inotify2->new; 46 my $sophie = Sophie::Base->connect;47 55 48 foreach ($sophie->resultset('Paths')->get_column('path')->all) { 56 my @paths = Sophie::Scan->new->list_paths; 57 if (!@paths) { 58 return; 59 } 60 foreach (@paths) { 61 -d $_ or next; 49 62 $i->watch( 50 63 $_, … … 72 85 if (my $pid = fork()) { 73 86 } else { 74 75 87 alarm 0; 88 my $scan = Sophie::Scan->new; 89 $scan->update_meta_paths; 76 90 my @pkey; 77 91 { 78 my $sophie = Sophie::Base->connect or do { 79 die "cannot read config file\n"; 80 }; 81 @pkey = $sophie->resultset('Paths')->search( 82 path => [ @path ], 83 )->get_column('d_path_key')->all; 84 push(@pkey, $sophie->resultset('Paths')->search({ 85 updated => [ undef, 86 \[ " < now() - '24 hours'::interval"], 87 ], 88 })->get_column('d_path_key')->all); 89 my %uniq = map { $_ => 1 } @pkey; 90 @pkey = keys %uniq; 92 @pkey = $scan->paths_to_keys(@path); 93 94 push(@pkey, $scan->list_unscanned_paths); 91 95 } 92 96 93 97 exit(0) if (!@pkey); 94 98 99 foreach my $pathkey (@pkey) { 100 my $time = time; 101 my @delta = Sophie::Scan::RpmsPath 102 ->new($pathkey, Sophie::Scan->new) 103 ->find_delta; 104 while (my @d = splice(@delta, 0, 25)) { 105 my $scan = Sophie::Scan->new; 106 my $path = Sophie::Scan::RpmsPath->new($pathkey, $scan); 107 $path->update_content(@d); 108 last if (time > $time + 15 * 60); 109 } 95 110 96 97 my $NB_PAR = 1; 98 my @split; 99 my $div = @pkey / $NB_PAR; 100 101 for (my $i = 0; $i < $NB_PAR - 1; $i++) { 102 $split[$i] = [ splice(@pkey, 0, $div) ]; 111 Sophie::Scan::RpmsPath->new($pathkey, Sophie::Scan->new)->set_updated 112 if (!@delta); # update only if we finished 103 113 } 104 $split[$NB_PAR -1] = [ @pkey ];105 foreach my $job (@split) {106 @{$job || []} or next;107 108 if (fork()) {109 } else {110 111 foreach my $pathkey (@{ $job }) {112 my $time = time;113 my @delta = Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect)114 ->find_delta;115 while (my @d = splice(@delta, 0, 25)) {116 my $path = Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect);117 $path->update_content(@d);118 #$path->db->disconnect;119 # If it take too long time, next path120 last if (time > $time + 15 * 60);121 }122 Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect)->set_updated123 if (!@delta); # update only if we finished124 }125 exit(0);126 }127 }128 1 while(waitpid(-1, 0) <= 0);129 114 exit(0); 130 115 }
Note: See TracChangeset
for help on using the changeset viewer.