@@ -109,7 +109,10 @@ var (
109109
110110func init () {
111111 batchFetchCmd .Flags ().StringVarP (& inputFile , "input-file" , "i" , "" , "urls list file" )
112- batchFetchCmd .Flags ().IntVarP (& worker , "worker" , "c" , 5 , "worker count" )
112+ batchFetchCmd .Flags ().IntVarP (& worker , "worker" , "c" , 1 , "worker count" )
113+ batchFetchCmd .Flags ().StringVarP (& bsuccessFname , "success-list" , "s" , "" , "file to save batch fetch success list" )
114+ batchFetchCmd .Flags ().StringVarP (& bfailureFname , "failure-list" , "e" , "" , "file to save batch fetch failure list" )
115+
113116 batchStatCmd .Flags ().StringVarP (& inputFile , "input-file" , "i" , "" , "input file" )
114117 batchCopyCmd .Flags ().StringVarP (& inputFile , "input-file" , "i" , "" , "input file" )
115118 batchMoveCmd .Flags ().StringVarP (& inputFile , "input-file" , "i" , "" , "input file" )
@@ -195,11 +198,16 @@ func BatchFetch(cmd *cobra.Command, params []string) {
195198 )
196199 defer close (fItemChan )
197200
198- go batchFetch (fItemChan )
201+ fileExporter , fErr := iqshell .NewFileExporter (bsuccessFname , bfailureFname , "" )
202+ if fErr != nil {
203+ fmt .Fprintf (os .Stderr , "create file exporter: %v\n " , fErr )
204+ os .Exit (1 )
205+ }
206+ go batchFetch (fItemChan , fileExporter )
199207
200208 for scanner .Scan () {
201209 line := scanner .Text ()
202- items := strings .Fields (line )
210+ items := strings .Split (line , " \t " )
203211 if len (items ) <= 0 {
204212 continue
205213 }
@@ -225,13 +233,24 @@ func BatchFetch(cmd *cobra.Command, params []string) {
225233 }
226234}
227235
228- func batchFetch (fItemChan chan * iqshell.FetchItem ) {
236+ func batchFetch (fItemChan chan * iqshell.FetchItem , fileExporter * iqshell. FileExporter ) {
229237 for i := 0 ; i < worker ; i ++ {
230238 go func () {
231239 bm := iqshell .GetBucketManager ()
232240 for fetchItem := range fItemChan {
233- fetchResult , fErr := bm .Fetch (fetchItem .RemoteUrl , fetchItem .Bucket , fetchItem .Key )
234- fmt .Println (fetchResult , fErr )
241+ _ , fErr := bm .Fetch (fetchItem .RemoteUrl , fetchItem .Bucket , fetchItem .Key )
242+ if fErr != nil {
243+ fmt .Fprintf (os .Stderr , "fetch %s => %s:%s failed\n " , fetchItem .RemoteUrl , fetchItem .Bucket , fetchItem .Key )
244+ if fileExporter != nil {
245+ fileExporter .WriteToFailedWriter (fmt .Sprintf ("%s\t %s\t %v\n " , fetchItem .RemoteUrl , fetchItem .Key , fErr ))
246+ }
247+ } else {
248+ fmt .Printf ("fetch %s => %s:%s success\n " , fetchItem .RemoteUrl , fetchItem .Bucket , fetchItem .Key )
249+ if fileExporter != nil {
250+ fileExporter .WriteToSuccessWriter (fmt .Sprintf ("%s\t %s\n " , fetchItem .RemoteUrl , fetchItem .Key ))
251+ }
252+
253+ }
235254 }
236255 }()
237256 }
0 commit comments