-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add failed transfers/SIPs buckets
- Loading branch information
Showing
8 changed files
with
283 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package activities | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"gocloud.dev/blob" | ||
) | ||
|
||
const ( | ||
SendToFailedBucketName = "send-to-failed-bucket" | ||
FailureSIP = "sip" | ||
FailureTransfer = "transfer" | ||
) | ||
|
||
type SendToFailedBucketActivity struct { | ||
failedTransferBucket *blob.Bucket | ||
failedSipBucket *blob.Bucket | ||
} | ||
|
||
func NewSendToFailedBuckeActivity(transfer, sip *blob.Bucket) *SendToFailedBucketActivity { | ||
return &SendToFailedBucketActivity{ | ||
failedTransferBucket: transfer, | ||
failedSipBucket: sip, | ||
} | ||
} | ||
|
||
type SendToFailedBucketParams struct { | ||
Type string | ||
Path string | ||
Key string | ||
} | ||
|
||
type SendToFailedBucketResult struct { | ||
FailedKey string | ||
} | ||
|
||
func (sf *SendToFailedBucketActivity) Execute( | ||
ctx context.Context, | ||
params *SendToFailedBucketParams, | ||
) (*SendToFailedBucketResult, error) { | ||
res := &SendToFailedBucketResult{} | ||
|
||
f, err := os.Open(params.Path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
|
||
res.FailedKey = "Failed_" + params.Key | ||
writerOptions := &blob.WriterOptions{ | ||
ContentType: "application/octet-stream", | ||
BufferSize: 100_000_000, | ||
} | ||
|
||
switch params.Type { | ||
case FailureTransfer: | ||
err = sf.failedTransferBucket.Upload(ctx, res.FailedKey, f, writerOptions) | ||
case FailureSIP: | ||
err = sf.failedSipBucket.Upload(ctx, res.FailedKey, f, writerOptions) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
Oops, something went wrong.