Skip to content

Commit

Permalink
Publish the s3 objects to omegaup-submissions too (#96)
Browse files Browse the repository at this point in the history
This is a migration commit that helps publish objects to both the
`omegaup-backup` and the `omegaup-submissions` buckets.
  • Loading branch information
lhchavez authored Nov 8, 2022
1 parent a12cc04 commit 07b9e75
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions grader/artifacts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grader

import (
"bytes"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -260,18 +261,37 @@ func (a *SubmissionsArtifacts) GetSource(ctx *common.Context, guid string) (stri

// PutSource writes the source of the submission to the filesystem (and maybe to S3).
func (a *SubmissionsArtifacts) PutSource(ctx *common.Context, guid string, r io.Reader) error {
submissionKey := path.Join(
var buf bytes.Buffer
_, err := io.Copy(&buf, r)
if err != nil {
return fmt.Errorf("read: %w", err)
}

backupSubmissionKey := path.Join(
"submissions",
guid[:2],
guid[2:],
)
return putArtifact(
err = putArtifact(
ctx,
a.s3c,
"omegaup-backup",
path.Join("omegaup", submissionKey),
path.Join(ctx.Config.Grader.V1.RuntimePath, submissionKey),
r,
path.Join("omegaup", backupSubmissionKey),
path.Join(ctx.Config.Grader.V1.RuntimePath, backupSubmissionKey),
bytes.NewReader(buf.Bytes()),
)
if err != nil {
return fmt.Errorf("put omegaup-backup: %w", err)
}

// TODO: leave just this version once the migration is done.
return putArtifact(
ctx,
a.s3c,
"omegaup-submissions",
guid,
path.Join(ctx.Config.Grader.V1.RuntimePath, backupSubmissionKey),
bytes.NewReader(buf.Bytes()),
)
}

Expand Down

0 comments on commit 07b9e75

Please sign in to comment.