github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/verification/fetcher/chunkconsumer/job.go (about) 1 package chunkconsumer 2 3 import ( 4 "fmt" 5 6 "github.com/onflow/flow-go/model/chunks" 7 "github.com/onflow/flow-go/model/flow" 8 "github.com/onflow/flow-go/module" 9 ) 10 11 // ChunkJob converts a chunk locator into a Job to be used by job queue. 12 type ChunkJob struct { 13 ChunkLocator *chunks.Locator 14 } 15 16 // ID converts chunk locator identifier into job id, which guarantees uniqueness. 17 func (j ChunkJob) ID() module.JobID { 18 return locatorIDToJobID(j.ChunkLocator.ID()) 19 } 20 21 func locatorIDToJobID(locatorID flow.Identifier) module.JobID { 22 return module.JobID(fmt.Sprintf("%v", locatorID)) 23 } 24 25 func ChunkLocatorToJob(locator *chunks.Locator) *ChunkJob { 26 return &ChunkJob{ChunkLocator: locator} 27 } 28 29 func JobToChunkLocator(job module.Job) (*chunks.Locator, error) { 30 chunkjob, ok := job.(*ChunkJob) 31 if !ok { 32 return nil, fmt.Errorf("could not assert job to chunk locator, job id: %x", job.ID()) 33 } 34 return chunkjob.ChunkLocator, nil 35 }