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