diff options
author | KatolaZ <katolaz@freaknet.org> | 2017-07-12 08:53:12 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2017-07-12 08:53:12 +0100 |
commit | b3ca09586c23831d9f089ab8a023580c403f8e55 (patch) | |
tree | 60bd13a7efe3a2ea210890fb9b486d6d68a90409 /scorsh.go | |
parent | 32b09256150d139e77d04533f28d0c26a32b12bd (diff) |
reorganised types and modules
Diffstat (limited to 'scorsh.go')
-rw-r--r-- | scorsh.go | 70 |
1 files changed, 46 insertions, 24 deletions
@@ -2,30 +2,14 @@ package main import ( "errors" - "log" "flag" -) - -const ( - SCORSH_ERR_NO_FILE = -(1 << iota) - SCORSH_ERR_KEYRING - SCORSH_ERR_NO_REPO - SCORSH_ERR_NO_COMMIT - SCORSH_ERR_SIGNATURE + "log" ) -type SCORSHmsg struct { - repo string - branch string - old_rev string - new_rev string -} var conf_file = flag.String("c", "./scorsh.cfg", "Configuration file for SCORSH") - - func SCORSHErr(err int) error { var err_str string @@ -50,17 +34,55 @@ func SCORSHErr(err int) error { } +func FindMatchingWorkers(master *SCORSHmaster, msg *SCORSHmsg) []*SCORSHworker { + + var ret []*SCORSHworker + + for _,w := range master.Workers { + if w.Matches(msg.repo, msg.branch) { + ret = append(ret, &w) + } + } + return ret +} + + +func Master(master *SCORSHmaster) { + + // master main loop: + + var matching_workers []*SCORSHworker + var push_msg SCORSHmsg + + matching_workers = make([]*SCORSHworker, len(master.Workers)) + + for { + select { + // - receive stuff from the spooler + case push_msg = <- master.Spooler: + // - lookup the repos map for matching workers + matching_workers = FindMatchingWorkers(master, &push_msg) + // - dispatch the message to all the matching workers + for _, w := range matching_workers { + w.Chan <- push_msg + } + } + } +} func main() { flag.Parse() - cfg := ReadGlobalConfig(*conf_file) + master := ReadGlobalConfig(*conf_file) - msg, status := StartWorkers(cfg) - - - - log.Printf("%s\n", cfg) - + err_workers := StartWorkers(master) + if err_workers != nil { + log.Fatal("Error starting workers: ", err_workers) + } + err_spooler := StartSpooler(master) + if err_spooler != nil { + log.Fatal("Error starting spooler: ", err_spooler) + } + go Master(master) } |