diff --git a/ulocollect/core/collector.go b/ulocollect/core/collector.go index 19bd6c1d827755ba852eb52e9112b703bbd3636c..71841690afdc5d06e4b39fb721e0c5ecf1656bce 100644 --- a/ulocollect/core/collector.go +++ b/ulocollect/core/collector.go @@ -5,6 +5,9 @@ import ( ) // A Collector schedules the execution of various Jobs. +// +// It also keeps track of all previously submitted jobs. This is +// useful for keeping logs and the like. type Collector struct { // The Importer we forward the ULO/RDF bytes to. Destination Importer @@ -22,19 +25,16 @@ func (c *Collector) Submit(j *Job) error { return fmt.Errorf("Id=%v already submitted", id) } - j.mu.Lock() - defer j.mu.Unlock() - go c.execute(j) return nil } func (c *Collector) execute(j *Job) { - // Aquire lock as we need to set the status initially. + // (1) Aquire lock as we need to set the status initially. j.mu.Lock() - // Set state to submitted. Later we'll want to do some kind + // (2) Set state to submitted. Later we'll want to do some kind // of scheduling at which point a job can spend a lot of time // in this state. But in the current version we don't do any // clever scheduling and as such the job enters the Active @@ -42,19 +42,19 @@ func (c *Collector) execute(j *Job) { j.state = Submitted - // Yep, we are starting already! + // (3) There is no scheduling. Start right away. j.state = Active - // Now we give up the lock as we run the actual payload. + // (4) Now we give up the lock as we run the actual payload. j.mu.Unlock() - // Run the actual payload. + // (5) Run the actual payload. err := j.Collect(c) - // Set completion state. + // (6) Set completion state. j.mu.Lock() @@ -67,7 +67,7 @@ func (c *Collector) execute(j *Job) { j.wr.Release() - // We are done mutating the Job. + // (7) We are done mutating the Job. j.mu.Unlock() }