-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingest_pre_fetch.go
58 lines (52 loc) · 2.12 KB
/
ingest_pre_fetch.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
54
55
56
57
58
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 IngestPreFetch struct {
*IngestBase
}
// NewIngestPreFetch creates a new IngestPreFetch worker. The worker starts
// handling NSQ messages as soon as it's instantiated.
func NewIngestPreFetch(bufSize, numWorkers, maxAttempts int) *IngestPreFetch {
_context := common.NewContext()
bufSize, numWorkers, maxAttempts = _context.Config.GetWorkerSettings(constants.IngestPreFetch, bufSize, numWorkers, maxAttempts)
settings := &Settings{
ChannelBufferSize: bufSize,
DeleteFromReceivingAfterFatalError: false,
DeleteFromReceivingAfterMaxFailedAttempts: false,
MaxAttempts: maxAttempts,
NSQChannel: constants.IngestPreFetch + "_worker_chan",
NSQTopic: constants.IngestPreFetch,
NextQueueTopic: constants.IngestValidation,
NextWorkItemStage: constants.StageValidate,
NumberOfWorkers: numWorkers,
PushToCleanupAfterMaxFailedAttempts: false,
PushToCleanupOnFatalError: false,
RequeueTimeout: (1 * time.Minute),
WorkItemSuccessNote: "Finished pre-fetch metadata gathering",
}
worker := &IngestPreFetch{
IngestBase: NewIngestBase(
_context,
createMetadataGatherer,
settings,
),
}
// The underlying IngestBase worker will start handling messages
// as soon as you call this. IngestBase pushes items into the
// ProcessChannel, and from there to SuccessChannel, ErrorChannel,
// or FatalErrorChannel.
err := worker.IngestBase.RegisterAsNsqConsumer()
if err != nil {
panic(fmt.Sprintf("Cannot register NSQ consumer: %v", err))
}
return worker
}
func createMetadataGatherer(context *common.Context, workItemID int64, ingestObject *service.IngestObject) ingest.Runnable {
return ingest.NewMetadataGatherer(context, workItemID, ingestObject)
}