github.com/koko1123/flow-go-1@v0.29.6/engine/verification/fetcher/chunkconsumer/worker.go (about) 1 package chunkconsumer 2 3 import ( 4 "github.com/koko1123/flow-go-1/engine/verification/fetcher" 5 "github.com/koko1123/flow-go-1/model/flow" 6 "github.com/koko1123/flow-go-1/module" 7 ) 8 9 // Worker receives job from job consumer and converts it back to Chunk 10 // for engine to process 11 type Worker struct { 12 engine fetcher.AssignedChunkProcessor 13 consumer *ChunkConsumer 14 } 15 16 func NewWorker(engine fetcher.AssignedChunkProcessor) *Worker { 17 return &Worker{ 18 engine: engine, 19 } 20 } 21 22 // Run converts the job to Chunk, it's guaranteed to work, because 23 // ChunkJobs converted chunk into job symmetrically 24 func (w *Worker) Run(job module.Job) error { 25 chunk, err := JobToChunkLocator(job) 26 if err != nil { 27 return err 28 } 29 w.engine.ProcessAssignedChunk(chunk) 30 31 return nil 32 } 33 34 func (w *Worker) Notify(chunkLocatorID flow.Identifier) { 35 jobID := locatorIDToJobID(chunkLocatorID) 36 w.consumer.NotifyJobIsDone(jobID) 37 }