github.com/onflow/flow-go@v0.33.17/module/jobqueue.go (about) 1 package module 2 3 import ( 4 "github.com/onflow/flow-go/model/flow" 5 ) 6 7 const ( 8 ConsumeProgressVerificationBlockHeight = "ConsumeProgressVerificationBlockHeight" 9 ConsumeProgressVerificationChunkIndex = "ConsumeProgressVerificationChunkIndex" 10 11 ConsumeProgressExecutionDataRequesterBlockHeight = "ConsumeProgressExecutionDataRequesterBlockHeight" 12 ConsumeProgressExecutionDataRequesterNotification = "ConsumeProgressExecutionDataRequesterNotification" 13 14 ConsumeProgressExecutionDataIndexerBlockHeight = "ConsumeProgressExecutionDataIndexerBlockHeight" 15 ) 16 17 // JobID is a unique ID of the job. 18 type JobID string 19 20 type NewJobListener interface { 21 // Check let the producer notify the consumer that a new job has been added, so that the consumer 22 // can check if there is worker available to process that job. 23 Check() 24 } 25 26 // JobConsumer consumes jobs from a job queue, and it remembers which job it has processed, and is able 27 // to resume processing from the next. 28 type JobConsumer interface { 29 NewJobListener 30 31 // Start starts processing jobs from a job queue. 32 Start() error 33 34 // Stop gracefully stops the consumer from reading new jobs from the job queue. It does not stop 35 // the existing worker finishing their jobs 36 // It blocks until the existing worker finish processing the job 37 Stop() 38 39 // LastProcessedIndex returns the last processed job index 40 LastProcessedIndex() uint64 41 42 // NotifyJobIsDone let the consumer know a job has been finished, so that consumer will take 43 // the next job from the job queue if there are workers available. It returns the last processed job index. 44 NotifyJobIsDone(JobID) uint64 45 46 // Size returns the number of processing jobs in consumer. 47 Size() uint 48 } 49 50 type Job interface { 51 // each job has a unique ID for deduplication 52 ID() JobID 53 } 54 55 // Jobs is the reader for an ordered job queue. Job can be fetched by the index, 56 // which start from 0 57 type Jobs interface { 58 // AtIndex returns the job at the given index. 59 // Error returns: 60 // * storage.ErrNotFound if a job at the provided index is not available 61 AtIndex(index uint64) (Job, error) 62 63 // Head returns the index of the last job 64 Head() (uint64, error) 65 } 66 67 type JobQueue interface { 68 // Add a job to the job queue 69 Add(job Job) error 70 } 71 72 // ProcessingNotifier is for the worker's underneath engine to report an entity 73 // has been processed without knowing the job queue. 74 // It is a callback so that the worker can convert the entity id into a job 75 // id, and notify the consumer about a finished job. 76 // 77 // At the current version, entities used in this interface are chunks and blocks ids. 78 type ProcessingNotifier interface { 79 Notify(entityID flow.Identifier) 80 }