@@ -12,7 +12,6 @@ import (
1212 "net/http"
1313 "os"
1414 "path/filepath"
15- "strconv"
1615 "time"
1716
1817 "github.com/cdnjs/tools/audit"
@@ -39,19 +38,12 @@ var (
3938 // be 50/50 for gz and br. Unknown for woff2.
4039 // Example: FILE_EXTENSION=gz
4140 FILE_EXTENSION = os .Getenv ("FILE_EXTENSION" )
42-
43- UPLOAD_CONCURENCY = os .Getenv ("UPLOAD_CONCURENCY" )
4441)
4542
4643func Invoke (ctx context.Context , e gcp.GCSEvent ) error {
4744 sentry .Init ()
4845 defer sentry .PanicHandler ()
4946
50- uploadConcurency , err := strconv .Atoi (UPLOAD_CONCURENCY )
51- if err != nil {
52- return fmt .Errorf ("could not read UPLOAD_CONCURENCY: %v" , err )
53- }
54-
5547 pkgName := e .Metadata ["package" ].(string )
5648 version := e .Metadata ["version" ].(string )
5749 log .Printf ("Invoke %s %s\n " , pkgName , version )
@@ -83,12 +75,8 @@ func Invoke(ctx context.Context, e gcp.GCSEvent) error {
8375 }
8476
8577 s3Client := s3 .NewFromConfig (cfg )
86- keys := make ([]string , 0 )
87- uploadQueue := make (chan s3.PutObjectInput )
8878
89- for w := 1 ; w <= uploadConcurency ; w ++ {
90- go uploadWorker (ctx , s3Client , uploadQueue )
91- }
79+ keys := make ([]string , 0 )
9280
9381 onFile := func (name string , r io.Reader ) error {
9482 ext := filepath .Ext (name )
@@ -112,14 +100,15 @@ func Invoke(ctx context.Context, e gcp.GCSEvent) error {
112100 Key : aws .String (key ),
113101 Metadata : meta ,
114102 }
115- uploadQueue <- s3Object
103+ if err := uploadFile (ctx , s3Client , & s3Object ); err != nil {
104+ return errors .Wrap (err , "failed to upload file" )
105+ }
116106 }
117107 return nil
118108 }
119109 if err := gcp .Inflate (bytes .NewReader (archive ), onFile ); err != nil {
120110 return fmt .Errorf ("could not inflate archive: %s" , err )
121111 }
122- close (uploadQueue )
123112
124113 if len (keys ) == 0 {
125114 log .Printf ("%s: no files to publish\n " , pkgName )
@@ -162,11 +151,3 @@ func uploadFile(ctx context.Context, s3Client *s3.Client, obj *s3.PutObjectInput
162151
163152 return nil
164153}
165-
166- func uploadWorker (ctx context.Context , s3Client * s3.Client , queue <- chan s3.PutObjectInput ) {
167- for item := range queue {
168- if err := uploadFile (ctx , s3Client , & item ); err != nil {
169- panic (errors .Wrap (err , "failed to upload file" ))
170- }
171- }
172- }
0 commit comments