-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingest_staging_uploader.go
53 lines (47 loc) · 1.85 KB
/
ingest_staging_uploader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package workers
import (
"fmt"
"time"
"github.com/APTrust/preservation-services/constants"
"github.com/APTrust/preservation-services/ingest"
"github.com/APTrust/preservation-services/models/common"
"github.com/APTrust/preservation-services/models/service"
)
type StagingUploader struct {
*IngestBase
}
// NewStagingUploader creates a new StagingUploader worker.
func NewStagingUploader(bufSize, numWorkers, maxAttempts int) *StagingUploader {
_context := common.NewContext()
bufSize, numWorkers, maxAttempts = _context.Config.GetWorkerSettings(constants.IngestStaging, bufSize, numWorkers, maxAttempts)
settings := &Settings{
ChannelBufferSize: bufSize,
DeleteFromReceivingAfterFatalError: false,
DeleteFromReceivingAfterMaxFailedAttempts: false,
MaxAttempts: maxAttempts,
NSQChannel: constants.IngestStaging + "_worker_chan",
NSQTopic: constants.IngestStaging,
NextQueueTopic: constants.IngestFormatIdentification,
NextWorkItemStage: constants.StageFormatIdentification,
NumberOfWorkers: numWorkers,
PushToCleanupAfterMaxFailedAttempts: false,
PushToCleanupOnFatalError: false,
RequeueTimeout: (1 * time.Minute),
WorkItemSuccessNote: "Finished copying files to staging area",
}
worker := &StagingUploader{
IngestBase: NewIngestBase(
_context,
createStagingUploader,
settings,
),
}
err := worker.IngestBase.RegisterAsNsqConsumer()
if err != nil {
panic(fmt.Sprintf("Cannot register NSQ consumer: %v", err))
}
return worker
}
func createStagingUploader(context *common.Context, workItemID int64, ingestObject *service.IngestObject) ingest.Runnable {
return ingest.NewStagingUploader(context, workItemID, ingestObject)
}