github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/state_synchronization/requester/jobs/jobs.go (about)

     1  package jobs
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/onflow/flow-go/module"
     7  	"github.com/onflow/flow-go/module/jobqueue"
     8  )
     9  
    10  // BlockEntryJob implements the Job interface. It converts a BlockEntry into a Job to be used by job queue.
    11  //
    12  // In current architecture, BlockEntryJob represents a ExecutionData notification enqueued to be
    13  // processed by the NotificationConsumer that implements the JobQueue interface.
    14  type BlockEntryJob struct {
    15  	Entry *BlockEntry
    16  }
    17  
    18  // ID converts block id into job id, which guarantees uniqueness.
    19  func (j BlockEntryJob) ID() module.JobID {
    20  	return jobqueue.JobID(j.Entry.BlockID)
    21  }
    22  
    23  // JobToBlockEntry converts a block entry job into its corresponding BlockEntry.
    24  func JobToBlockEntry(job module.Job) (*BlockEntry, error) {
    25  	blockJob, ok := job.(*BlockEntryJob)
    26  	if !ok {
    27  		return nil, fmt.Errorf("could not convert job to block entry, job id: %x", job.ID())
    28  	}
    29  	return blockJob.Entry, nil
    30  }
    31  
    32  // BlockEntryToJob converts the BlockEntry to a BlockEntryJob.
    33  func BlockEntryToJob(entry *BlockEntry) *BlockEntryJob {
    34  	return &BlockEntryJob{Entry: entry}
    35  }