-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingest_format_identifier.go
53 lines (47 loc) · 1.88 KB
/
ingest_format_identifier.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 FormatIdentifier struct {
*IngestBase
}
// NewFormatIdentifier creates a new FormatIdentifier worker.
func NewIngestFormatIdentifier(bufSize, numWorkers, maxAttempts int) *FormatIdentifier {
_context := common.NewContext()
bufSize, numWorkers, maxAttempts = _context.Config.GetWorkerSettings(constants.IngestFormatIdentification, bufSize, numWorkers, maxAttempts)
settings := &Settings{
ChannelBufferSize: bufSize,
DeleteFromReceivingAfterFatalError: false,
DeleteFromReceivingAfterMaxFailedAttempts: false,
MaxAttempts: maxAttempts,
NSQChannel: constants.IngestFormatIdentification + "_worker_chan",
NSQTopic: constants.IngestFormatIdentification,
NextQueueTopic: constants.IngestStorage,
NextWorkItemStage: constants.StageStore,
NumberOfWorkers: numWorkers,
PushToCleanupAfterMaxFailedAttempts: false,
PushToCleanupOnFatalError: false,
RequeueTimeout: (1 * time.Minute),
WorkItemSuccessNote: "Finished file format identification",
}
worker := &FormatIdentifier{
IngestBase: NewIngestBase(
_context,
createFormatIdentifier,
settings,
),
}
err := worker.IngestBase.RegisterAsNsqConsumer()
if err != nil {
panic(fmt.Sprintf("Cannot register NSQ consumer: %v", err))
}
return worker
}
func createFormatIdentifier(context *common.Context, workItemID int64, ingestObject *service.IngestObject) ingest.Runnable {
return ingest.NewFormatIdentifier(context, workItemID, ingestObject)
}