-
Notifications
You must be signed in to change notification settings - Fork 175
/
worker.go
37 lines (31 loc) · 886 Bytes
/
worker.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
package chunkconsumer
import (
"github.com/onflow/flow-go/engine/verification/fetcher"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
)
// Worker receives job from job consumer and converts it back to Chunk
// for engine to process
type Worker struct {
engine fetcher.AssignedChunkProcessor
consumer *ChunkConsumer
}
func NewWorker(engine fetcher.AssignedChunkProcessor) *Worker {
return &Worker{
engine: engine,
}
}
// Run converts the job to Chunk, it's guaranteed to work, because
// ChunkJobs converted chunk into job symmetrically
func (w *Worker) Run(job module.Job) error {
chunk, err := JobToChunkLocator(job)
if err != nil {
return err
}
w.engine.ProcessAssignedChunk(chunk)
return nil
}
func (w *Worker) Notify(chunkLocatorID flow.Identifier) {
jobID := locatorIDToJobID(chunkLocatorID)
w.consumer.NotifyJobIsDone(jobID)
}