@@ -106,47 +106,28 @@ func (yt *VideoService) putAllCurrentVideoMetadata(ctx context.Context) error {
106
106
logger ().Errorf ("error fetching videos: %v" , err )
107
107
return err
108
108
}
109
- const maxWorkers = 10
110
- sem := make (chan struct {}, maxWorkers )
111
-
112
- var wg sync.WaitGroup
113
109
for _ , video := range videos {
114
- wg .Add (1 )
115
- sem <- struct {}{}
116
- go func (video models.Video ) {
117
- defer wg .Done ()
118
- defer func () { <- sem }()
119
- vidCtx , cancel := context .WithTimeout (ctx , 5 * time .Minute )
120
- defer cancel ()
121
- select {
122
- case <- vidCtx .Done ():
123
- logger ().Infof ("context cancelled for video %d, stopping upload" , video .ID )
124
- return
125
- default :
126
- videoBytes , err := json .Marshal (video )
127
- if err != nil {
128
- logger ().Errorf ("error marshalling video %d: %v" , video .ID , err )
129
- return
130
- }
131
- input := & s3.PutObjectInput {
132
- Bucket : aws .String (yt .bucketName ),
133
- Body : bytes .NewReader (videoBytes ),
134
- Key : aws .String (video .GetS3KeyJson ()),
135
- }
136
- resp , err := yt .s3Svc .PutObject (vidCtx , input )
137
- if err != nil {
138
- logger ().Errorf ("error putting object for video %d: %v" , video .ID , err )
139
- return
140
- }
141
- if resp .ETag == nil {
142
- logger ().Errorf ("etag is nil for video %d" , video .ID )
143
- return
144
- }
145
- logger ().Infof ("successfully put object for video %d with etag: %s" , video .ID , * resp .ETag )
146
- }
147
- }(video )
110
+ videoBytes , err := json .Marshal (video )
111
+ if err != nil {
112
+ logger ().Errorf ("error marshalling video %d: %v" , video .ID , err )
113
+ return err
114
+ }
115
+ input := & s3.PutObjectInput {
116
+ Bucket : aws .String (yt .bucketName ),
117
+ Body : bytes .NewReader (videoBytes ),
118
+ Key : aws .String (video .GetS3KeyJson ()),
119
+ }
120
+ resp , err := yt .s3Svc .PutObject (ctx , input )
121
+ if err != nil {
122
+ logger ().Errorf ("error putting object for video %d: %v" , video .ID , err )
123
+ return err
124
+ }
125
+ if resp .ETag == nil {
126
+ logger ().Errorf ("etag is nil for video %d" , video .ID )
127
+ return nil
128
+ }
129
+ logger ().Infof ("successfully put object for video %d with etag: %s" , video .ID , * resp .ETag )
148
130
}
149
- wg .Wait ()
150
131
return nil
151
132
}
152
133
0 commit comments