Skip to content

Commit

Permalink
add metadata to uploaded files and use unique path; run render in gor…
Browse files Browse the repository at this point in the history
…outine
  • Loading branch information
andrewmarklloyd committed Jun 20, 2023
1 parent 97d5109 commit 5048e05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 5 additions & 4 deletions internal/pkg/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ func NewClient() (Client, error) {
}, nil
}

func (c *Client) UploadFile(ctx context.Context, localVideoPath, key string) error {
func (c *Client) UploadFile(ctx context.Context, localVideoPath, key string, metadata map[string]string) error {
file, err := os.Open(localVideoPath)
if err != nil {
return fmt.Errorf("opening local video file: %s", err)
}

uploader := manager.NewUploader(c.s3)
_, err = uploader.Upload(ctx, &s3.PutObjectInput{
Bucket: aws.String("math-visual-proofs"),
Key: aws.String(fmt.Sprintf("renderings/%s", key)),
Body: file,
Bucket: aws.String("math-visual-proofs"),
Key: aws.String(fmt.Sprintf("renderings/%s", key)),
Body: file,
Metadata: metadata,
})
if err != nil {
return fmt.Errorf("uploading video file to s3: %s", err)
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ func subscribeHandler(renderMessage mqtt.RenderMessage) error {

name := strings.Trim(f, ".py")
path := fmt.Sprintf("%s/media/videos/%s/720p30/%s.mp4", clonePath, name, name)
err = awsClient.UploadFile(context.Background(), path, fmt.Sprintf("%s.mp4", name))
// TODO: get org and repo as args
tmpOrgRepoPath := strings.Replace(renderMessage.RepoURL, "https://github.com/", "", -1)
orgRepoPath := strings.Replace(tmpOrgRepoPath, ".git", "", -1)
key := fmt.Sprintf("%s/%s.mp4", orgRepoPath, name)
err = awsClient.UploadFile(context.Background(), path, key, map[string]string{
"x-amz-meta-sha": renderMessage.GithubSHA,
"x-amz-meta-repourl": renderMessage.RepoURL,
})
if err != nil {
return fmt.Errorf("error uploading to s3: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c MqttClient) Subscribe(topic string, logger *zap.SugaredLogger, subscribe
logger.Errorf("error publishing to renderErrTopic: %s", err)
}
// wait group here?
subscribeHandler(renderMessage)
go subscribeHandler(renderMessage)
}); token.Wait() && token.Error() != nil {
return token.Error()
}
Expand Down

0 comments on commit 5048e05

Please sign in to comment.