diff options
author | KatolaZ <katolaz@freaknet.org> | 2017-07-15 01:35:36 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2017-07-15 01:35:36 +0100 |
commit | 74f8a74ecf8284fd4182cabab797f17bb18e7032 (patch) | |
tree | fccf6ded5d4a894b5863039b99ce977023bd0f79 /scorsh.go | |
parent | 726b399e4747032a3d052339cd62c57ae5b6767c (diff) |
Added Makefile -- gofmt
Diffstat (limited to 'scorsh.go')
-rw-r--r-- | scorsh.go | 40 |
1 files changed, 17 insertions, 23 deletions
@@ -6,14 +6,13 @@ import ( "log" ) -// manage debugging messages +// manage debugging messages const debug debugging = true type debugging bool - -func (d debugging) log(format string, args ...interface{}){ +func (d debugging) log(format string, args ...interface{}) { if d { log.Printf(format, args...) } @@ -45,12 +44,11 @@ func SCORSHerr(err int) error { } - func FindMatchingWorkers(master *SCORSHmaster, msg *SCORSHmsg) []*SCORSHworker { - + var ret []*SCORSHworker - - for idx,w := range master.Workers { + + for idx, w := range master.Workers { if w.Matches(msg.Repo, msg.Branch) { debug.log("--- Worker: %s matches %s:%s\n", w.Name, msg.Repo, msg.Branch) ret = append(ret, &(master.Workers[idx])) @@ -59,34 +57,33 @@ func FindMatchingWorkers(master *SCORSHmaster, msg *SCORSHmsg) []*SCORSHworker { return ret } - func Master(master *SCORSHmaster) { // master main loop: var matching_workers []*SCORSHworker var push_msg SCORSHmsg - + matching_workers = make([]*SCORSHworker, len(master.Workers)) log.Println("[master] Master started ") - + for { select { // - receive stuff from the spooler - case push_msg = <- master.Spooler: + case push_msg = <-master.Spooler: debug.log("[master] received message: %s\n", push_msg) - + // - lookup the repos map for matching workers matching_workers = FindMatchingWorkers(master, &push_msg) debug.log("[master] matching workers: %s\n", matching_workers) - + // add the message to PendingMsg //... // - dispatch the message to all the matching workers for _, w := range matching_workers { - // increase the counter associated to the message + // increase the counter associated to the message w.MsgChan <- push_msg } } @@ -97,14 +94,12 @@ func InitMaster() *SCORSHmaster { master := ReadGlobalConfig(*conf_file) - master.Repos = make(map[string][]*SCORSHworker) master.WorkingMsg = make(map[string]int) // This is the mutex-channel on which we receive acks from workers master.StatusChan = make(chan SCORSHmsg, 1) master.Spooler = make(chan SCORSHmsg, 1) - err_workers := StartWorkers(master) if err_workers != nil { log.Fatal("Error starting workers: ", err_workers) @@ -114,20 +109,19 @@ func InitMaster() *SCORSHmaster { err_spooler := StartSpooler(master) if err_spooler != nil { log.Fatal("Error starting spooler: ", err_spooler) - } + } return master - -} +} func main() { flag.Parse() - + master := InitMaster() - + go Master(master) - <- master.StatusChan - + <-master.StatusChan + } |