diff options
author | KatolaZ <katolaz@freaknet.org> | 2017-07-15 01:26:39 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2017-07-15 01:26:39 +0100 |
commit | 726b399e4747032a3d052339cd62c57ae5b6767c (patch) | |
tree | aac8350e83bb13e9628dd287ca3aae97ecafcb32 | |
parent | ed637037b75cb5dfe1b49e776956fa6ab3632b68 (diff) |
pipeline from spool to worker is done -- added examples
-rw-r--r-- | commits.go | 6 | ||||
-rw-r--r-- | config.go | 41 | ||||
-rwxr-xr-x | examples/create_spool_message.sh | 30 | ||||
-rw-r--r-- | examples/scorsh_example.cfg | 29 | ||||
-rw-r--r-- | examples/worker1/allowed_users.asc | 62 | ||||
-rw-r--r-- | examples/worker1/allowed_users.pgp | bin | 0 -> 3073 bytes | |||
-rw-r--r-- | examples/worker1/worker1.cfg | 24 | ||||
-rw-r--r-- | examples/worker2/allowed_users.asc | 62 | ||||
-rw-r--r-- | examples/worker2/allowed_users.pgp | bin | 0 -> 3073 bytes | |||
-rw-r--r-- | examples/worker2/worker2.cfg | 14 | ||||
-rw-r--r-- | sandpit/test_parse_message.go | 44 | ||||
-rw-r--r-- | sandpit/test_regexp.go | 26 | ||||
-rw-r--r-- | sandpit/test_worker_cfg.go | 63 | ||||
-rw-r--r-- | scorsh.cfg | 48 | ||||
-rw-r--r-- | scorsh.go | 39 | ||||
-rw-r--r-- | spooler.go | 42 | ||||
-rw-r--r-- | types.go | 86 | ||||
-rw-r--r-- | workers.go | 46 |
18 files changed, 537 insertions, 125 deletions
@@ -53,9 +53,9 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error { fmt.Printf("Inside parse_commits\n") - reponame := msg.repo - old_rev := msg.old_rev - new_rev := msg.new_rev + reponame := msg.Repo + old_rev := msg.Old_rev + new_rev := msg.New_rev repo, err := git.OpenRepository(reponame) if err != nil { @@ -1,7 +1,6 @@ package main import ( - "bytes" "fmt" "github.com/go-yaml/yaml" "io" @@ -41,7 +40,7 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { } if cfg.LogPrefix != "" { - log.SetPrefix(cfg.LogPrefix) + log.SetPrefix(cfg.LogPrefix+ " ") } // If the user has not set a spooldir, crash loudly @@ -54,46 +53,10 @@ func ReadGlobalConfig(fname string) *SCORSHmaster { // Check if the user wants to redirect the logs to a file // If we got so far, then there is some sort of config in cfg + log.Printf("----- Starting SCORSH -----\n") log.Printf("Successfully read config from %s\n", fname) return cfg } -func (cfg *SCORSHmaster) String() string { - - var buff bytes.Buffer - - buff.WriteString("spooldir: ") - buff.WriteString(cfg.Spooldir) - buff.WriteString("\nlogfile: ") - buff.WriteString(cfg.Logfile) - buff.WriteString("\nlogprefix: ") - buff.WriteString(cfg.LogPrefix) - buff.WriteString("\nWorkers: \n") - - for _, w := range cfg.Workers { - buff.WriteString("---\n name: ") - buff.WriteString(w.Name) - buff.WriteString("\n repos: ") - for _, r := range w.Repos { - buff.WriteString("\n ") - buff.WriteString(r) - } - buff.WriteString("\n folder: ") - buff.WriteString(w.Folder) - buff.WriteString("\n logfile: ") - buff.WriteString(w.Logfile) - buff.WriteString("\n tagfile: ") - buff.WriteString(w.Tagfile) - buff.WriteString("\n keyrings: ") - for _, k := range w.Keyrings { - buff.WriteString("\n ") - buff.WriteString(k) - } - buff.WriteString("\n...\n") - - } - - return buff.String() -} diff --git a/examples/create_spool_message.sh b/examples/create_spool_message.sh new file mode 100755 index 0000000..22c5839 --- /dev/null +++ b/examples/create_spool_message.sh @@ -0,0 +1,30 @@ +#!/bin/sh + + + +##function +write_message(){ + + orev=${3:-"a1b2c3d4e5f6"} + nrev=${4:-"9a8b7c6d5e4f"} + + + cat <<EOF +--- +m_id: 123456 +m_repo: $1 +m_branch: $2 +m_oldrev: $orev +m_newrev: $nrev +... +EOF + +} + + +if [ $# -le 1 ]; then + echo "Usage: $0 <repo> <branch> [<oldrev> [<newrev]]" + exit 1 +fi + +write_message $@ diff --git a/examples/scorsh_example.cfg b/examples/scorsh_example.cfg new file mode 100644 index 0000000..91bd413 --- /dev/null +++ b/examples/scorsh_example.cfg @@ -0,0 +1,29 @@ +--- +s_spooldir: "./spool" +s_logfile: "./scorsh.log" +s_logprefix: "[scorsh]" + +s_workers: + [ + { + w_name: worker1, + w_repos: [".*:.*"], # All branches in all repos + w_folder: ./worker1, + w_logfile: ./worker1/worker1.log, + w_tagfile: "./worker1/worker1.cfg", + w_keyrings: [ + "./worker1/allowed_users.asc" + ] + }, + { + w_name: worker2, + w_repos: [".*:master"], # Branch master in all repos + w_folder: ./worker2, + w_logfile: ./worker2/worker2.log, + w_tagfile: "./worker2/worker2.cfg", + w_keyrings: [ + "./worker2/allowed_users.asc" + ] + } +] +... diff --git a/examples/worker1/allowed_users.asc b/examples/worker1/allowed_users.asc new file mode 100644 index 0000000..38bee5a --- /dev/null +++ b/examples/worker1/allowed_users.asc @@ -0,0 +1,62 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQGiBEFi1/MRBADTOYQBLugy99OG588zPBaOhDPaCfeeB/XiMbMLdO6RzCCZtuU7 +e1G3I+8yIOLNUhfkmIT5Q7aU7FQA6OEexMvA3hijma7uLWs0GPGBC6U2XWEGVCcM +NNCVgZXv8JAEGdyWZmYBO+StYzp7tPhoujUMbY3ChPFes2IB1tlpJeYkuwCglKi6 +ENT7n1pp0ZL02HyW7sUeFIED/3X1G6hKpcO12KXhdl70bI1ELBEoXW8S6E5+zN9v +bj/3SDVMMc99k7vmxd8MVhQviCuwHdX9115fiuUcb6atSdtbXMvCR729rlH+QfCA +aEdJ5O784zcpaTaplRlSVhqbkqU0O0qs2Uwpzyq2YOmqOWaUoxWjaAEZ3MTinJ05 +FOIrA/4xN/kC0xJmqtAYg+IXnEM91pJaHVn1tlG0Us/ZUcV3qOBVzlxbELiYJY/P +f0RdSdJpsCglMeHMvKXYWDYeUwCxVnrX9QdY5U+o7jajW3CY+QXyiUOyB6Oxp1ZB +R9/Kzch8ZDG1efvhPS6Yl6c4VzrOEfmYfq0zA8dD81Q7fKoW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/examples/worker1/allowed_users.pgp Binary files differnew file mode 100644 index 0000000..c083709 --- /dev/null +++ b/examples/worker1/allowed_users.pgp diff --git a/examples/worker1/worker1.cfg b/examples/worker1/worker1.cfg new file mode 100644 index 0000000..233afdd --- /dev/null +++ b/examples/worker1/worker1.cfg @@ -0,0 +1,24 @@ +# +# This is the typical worker configuration file. The file should be +# called "worker_config.cfg", and will be placed inside the worker +# directory. It defines the tags understood by the worker, with the +# corresponding list of commands +# +# + + +--- +w_tags: + [ + { + t_name: "LOG", + t_keyrings: ["allowed_users.asc"], + t_commands: [ + { + c_url: "file:///home/katolaz/bin/scorsh_script.sh" +## c_hash: "12da324fb76s924acbce" + } + ] + } + ] +...
\ No newline at end of file diff --git a/examples/worker2/allowed_users.asc b/examples/worker2/allowed_users.asc new file mode 100644 index 0000000..38bee5a --- /dev/null +++ b/examples/worker2/allowed_users.asc @@ -0,0 +1,62 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQGiBEFi1/MRBADTOYQBLugy99OG588zPBaOhDPaCfeeB/XiMbMLdO6RzCCZtuU7 +e1G3I+8yIOLNUhfkmIT5Q7aU7FQA6OEexMvA3hijma7uLWs0GPGBC6U2XWEGVCcM +NNCVgZXv8JAEGdyWZmYBO+StYzp7tPhoujUMbY3ChPFes2IB1tlpJeYkuwCglKi6 +ENT7n1pp0ZL02HyW7sUeFIED/3X1G6hKpcO12KXhdl70bI1ELBEoXW8S6E5+zN9v +bj/3SDVMMc99k7vmxd8MVhQviCuwHdX9115fiuUcb6atSdtbXMvCR729rlH+QfCA +aEdJ5O784zcpaTaplRlSVhqbkqU0O0qs2Uwpzyq2YOmqOWaUoxWjaAEZ3MTinJ05 +FOIrA/4xN/kC0xJmqtAYg+IXnEM91pJaHVn1tlG0Us/ZUcV3qOBVzlxbELiYJY/P +f0RdSdJpsCglMeHMvKXYWDYeUwCxVnrX9QdY5U+o7jajW3CY+QXyiUOyB6Oxp1ZB +R9/Kzch8ZDG1efvhPS6Yl6c4V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diff --git a/examples/worker2/allowed_users.pgp b/examples/worker2/allowed_users.pgp Binary files differnew file mode 100644 index 0000000..c083709 --- /dev/null +++ b/examples/worker2/allowed_users.pgp diff --git a/examples/worker2/worker2.cfg b/examples/worker2/worker2.cfg new file mode 100644 index 0000000..5624cb0 --- /dev/null +++ b/examples/worker2/worker2.cfg @@ -0,0 +1,14 @@ +--- +w_tags: + [ + { + t_name: "DEPLOY", + t_keyrings: ["allowed_users.asc"], + t_commands: [ + { + c_url: "file:///home/katolaz/bin/deploy.sh" + } + ] + } + ] +...
\ No newline at end of file diff --git a/sandpit/test_parse_message.go b/sandpit/test_parse_message.go new file mode 100644 index 0000000..f60f03c --- /dev/null +++ b/sandpit/test_parse_message.go @@ -0,0 +1,44 @@ +package main + +import( + "fmt" + "github.com/go-yaml/yaml" + "io/ioutil" + "log" + "os" +) + + +var orig_msg= ` +--- +m_id: 123456 +m_repo: master +m_branch: test_branch +m_oldrev: a1b2c3d4e5f6 +m_newrev: 9a8b7c6d5e4f +... + +` + + +func main(){ + + var msg *SCORSHmsg + msg = new(SCORSHmsg) + + + fname := "spool/test_2" + + data, err := ioutil.ReadFile(fname) + if err != nil { + log.Printf("Unable to open file: %s\n", fname) + os.Exit(1) + } + err = yaml.Unmarshal([]byte(data), msg) + if err != nil{ + log.Printf("Error parsing message: %s", err) + } + + fmt.Printf("%s\n", msg) + +} diff --git a/sandpit/test_regexp.go b/sandpit/test_regexp.go new file mode 100644 index 0000000..5ae1d88 --- /dev/null +++ b/sandpit/test_regexp.go @@ -0,0 +1,26 @@ +package main + +import( + "regexp" + "log" +) + + +func main (){ + + pattern := ".*" + str := "my_string" + + matched, err := regexp.MatchString(pattern, str) + + if err != nil { + log.Fatal("Error matching string: ", err) + } + + if matched { + log.Printf("Yes! '%s' matched '%s'\n", str, pattern) + } else { + log.Printf("Bad luck!\n") + } + +} diff --git a/sandpit/test_worker_cfg.go b/sandpit/test_worker_cfg.go new file mode 100644 index 0000000..b8bc891 --- /dev/null +++ b/sandpit/test_worker_cfg.go @@ -0,0 +1,63 @@ +package main + +import( + "fmt" + "github.com/go-yaml/yaml" + "log" + "strings" +) + + +var worker_cfg = ` +--- +w_tags: + [ + { + t_name: "BUILD", + t_keyrings: ["build_keyring.asc", "general_keyring.asc"], + t_commands: [ + { + c_url: "file:///home/user/bin/script.sh $1 $2", + c_hash: "12da324fb76s924acbce" + }, + { + c_url: "http://my.server.net/call.pl?branch=$1" + } + ] + }, + { + t_name: "PUBLISH", + t_keyrings: ["web_developers.asc"], + t_commands: [ + { + c_url: "file:///usr/local/bin/publish.py $repo $branch", + c_hash: "3234567898765432345678" + } + ] + } + ] +... + +` + + +func main(){ + + var w *SCORSHworker + w = new(SCORSHworker) + + + sep := "\n---\n" + + idx := strings.Index(worker_cfg, sep) + + err := yaml.Unmarshal([]byte(worker_cfg[idx:]), w) + + + if err != nil{ + log.Printf("Error parsing message: %s", err) + } + + fmt.Printf("%s\n", w) + +} @@ -6,42 +6,24 @@ s_logprefix: "[scorsh]" s_workers: [ { - w_name: catchall, - w_repos: ["*:*"], # All branches in all repos - w_folder: ./catchall, - w_logfile: ./catchall/catchall.log, - w_tagfile: "./catchall/tags.cfg", + w_name: worker1, + w_repos: [".*:.*"], # All branches in all repos + w_folder: ./worker1, + w_logfile: ./worker1/worker1.log, + w_tagfile: "./worker1/worker1.cfg", w_keyrings: [ - "./catchall/catchall_keyring.asc" + "./worker1/allowed_users.asc" ] }, - { - w_name: ascii, - w_repos: ["*:suites/ascii", # branch "suites/ascii" in all the repos - "*:suites/ascii-updates", - "*:suites/ascii-security" - ], - w_folder: ./ascii, - w_logfile: ./worker_ascii.log, - w_tagfile: "./ascii/tags.cfg", - w_keyrings: [ - "./ascii/ascii_keyring.asc" - ] - }, { - w_name: ascii-side-branches , - w_repos: [ - "*:suites/ascii-proposed", - "*:suites/ascii-proposed-updates" - ], - w_folder: ./ascii-side-branches, - w_logfile: ./worker_ascii_side_branches.log, - w_tagfile: "./ascii-side-branches/tags.cfg", + w_name: worker2, + w_repos: [".*:master"], # Branch master in all repos + w_folder: ./worker2, + w_logfile: ./worker2/worker2.log, + w_tagfile: "./worker2/worker2.cfg", w_keyrings: [ - "./ascii/ascii_keyring.asc", - "./ascii/ascii_proposed_keyring.asc", - "./ascii/ascii_proposed_updates_keyring.asc" - ], - } - ] + "./worker2/allowed_users.asc" + ] + } +] ... @@ -6,7 +6,20 @@ import ( "log" ) +// manage debugging messages +const debug debugging = true + +type debugging bool + + +func (d debugging) log(format string, args ...interface{}){ + if d { + log.Printf(format, args...) + } +} + +/////////// var conf_file = flag.String("c", "./scorsh.cfg", "Configuration file for SCORSH") @@ -37,9 +50,10 @@ 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) + 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])) } } return ret @@ -55,12 +69,19 @@ func Master(master *SCORSHmaster) { matching_workers = make([]*SCORSHworker, len(master.Workers)) + log.Println("[master] Master started ") + for { select { // - receive stuff from the 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 @@ -75,11 +96,14 @@ func Master(master *SCORSHmaster) { 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 { @@ -90,9 +114,7 @@ func InitMaster() *SCORSHmaster { err_spooler := StartSpooler(master) if err_spooler != nil { log.Fatal("Error starting spooler: ", err_spooler) - } else { - log.Println("Spooler started correctly") - } + } return master } @@ -101,8 +123,11 @@ func InitMaster() *SCORSHmaster { func main() { flag.Parse() - + master := InitMaster() go Master(master) + + <- master.StatusChan + } @@ -1,40 +1,59 @@ package main import ( + "fmt" "github.com/fsnotify/fsnotify" + "github.com/go-yaml/yaml" + "io/ioutil" "log" - "os" - "fmt" +// "time" ) // parse a request file and return a SCORSHmessage -func parse_request(fname string) (SCORSHmsg, error) { +func parse_request(fname string, msg *SCORSHmsg) error { - var ret SCORSHmsg - _, err := os.Open(fname) + + debug.log("[parse_request] message at start: %s\n", msg) + + data, err := ioutil.ReadFile(fname) if err != nil { log.Printf("Unable to open file: %s\n", fname) - return ret, SCORSHerr(SCORSH_ERR_NO_FILE) + return SCORSHerr(SCORSH_ERR_NO_FILE) } - // FIXME: Fill in the ret structure + debug.log("[parse_request] file contains: \n%s\n", data) + + debug.log("[parse_request] reading message from file: %s\n", fname) - return ret, nil + err = yaml.Unmarshal([]byte(data), msg) + if err != nil { + return fmt.Errorf("Error parsing message: %s", err) + } + debug.log("[parse_request] got message: %s\n", msg) + return nil } func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) { + + log.Println("Spooler started correctly") + + var msg *SCORSHmsg + msg = new(SCORSHmsg) for { select { case event := <-watcher.Events: - if event.Op == fsnotify.Create { - msg, err := parse_request(event.Name) + if event.Op == fsnotify.Write { + //time.Sleep(1000 * time.Millisecond) + debug.log("[spooler] new file %s detected\n", event.Name) + err := parse_request(event.Name, msg) if err != nil { log.Printf("Invalid packet received. [%s]\n", err) } - worker <- msg + debug.log("[spooler] read message: %s\n", msg) + worker <- *msg } case err := <-watcher.Errors: log.Println("error:", err) @@ -59,5 +78,4 @@ func StartSpooler(master *SCORSHmaster) error { go spooler(watcher, master.Spooler) return nil - } @@ -1,6 +1,7 @@ package main import ( + "bytes" "golang.org/x/crypto/openpgp" ) @@ -15,11 +16,11 @@ const ( // the SCORSHmsg type represents messages received from the spool and // sent to workers type SCORSHmsg struct { - name string - repo string - branch string - old_rev string - new_rev string + Name string `yaml:"m_id"` + Repo string `yaml:"m_repo"` + Branch string `yaml:"m_branch"` + Old_rev string `yaml:"m_oldrev"` + New_rev string `yaml:"m_newrev"` } type SCORSHcmd struct { @@ -35,17 +36,17 @@ type SCORSHtag struct { // Configuration of a worker type SCORSHworker_cfg struct { - Name string `yaml:"w_name"` - Repos []string `yaml:"w_repos"` - Folder string `yaml:"w_folder"` - Logfile string `yaml:"w_logfile"` - Tagfile string `yaml:"w_tagfile"` - Keyrings []string `yaml:"w_keyrings"` + Name string `yaml:"w_name"` + Repos []string `yaml:"w_repos"` + Folder string `yaml:"w_folder"` + Logfile string `yaml:"w_logfile"` + Tagfile string `yaml:"w_tagfile"` + Keyrings []string `yaml:"w_keyrings"` + Tags []SCORSHtag `yaml:"w_tags"` } // State of a worker type SCORSHworker_state struct { - Tags []SCORSHtag `yaml:"w_tags"` Keys map[string]openpgp.KeyRing MsgChan chan SCORSHmsg StatusChan chan SCORSHmsg @@ -55,7 +56,7 @@ type SCORSHworker_state struct { // worker type SCORSHworker struct { SCORSHworker_cfg `yaml:",inline"` - SCORSHworker_state `yaml:",inline"` + SCORSHworker_state } // Configuration of the master @@ -80,3 +81,62 @@ type SCORSHmaster struct { SCORSHmaster_cfg `yaml:",inline"` SCORSHmaster_state } + + + +func (cfg *SCORSHmaster) String() string { + + var buff bytes.Buffer + + buff.WriteString("spooldir: ") + buff.WriteString(cfg.Spooldir) + buff.WriteString("\nlogfile: ") + buff.WriteString(cfg.Logfile) + buff.WriteString("\nlogprefix: ") + buff.WriteString(cfg.LogPrefix) + buff.WriteString("\nWorkers: \n") + + for _, w := range cfg.Workers { + buff.WriteString("---\n name: ") + buff.WriteString(w.Name) + buff.WriteString("\n repos: ") + for _, r := range w.Repos { + buff.WriteString("\n ") + buff.WriteString(r) + } + buff.WriteString("\n folder: ") + buff.WriteString(w.Folder) + buff.WriteString("\n logfile: ") + buff.WriteString(w.Logfile) + buff.WriteString("\n tagfile: ") + buff.WriteString(w.Tagfile) + buff.WriteString("\n keyrings: ") + for _, k := range w.Keyrings { + buff.WriteString("\n ") + buff.WriteString(k) + } + buff.WriteString("\n...\n") + + } + + return buff.String() +} + + +func (msg *SCORSHmsg) String() string { + + var buff bytes.Buffer + buff.WriteString("\nName: ") + buff.WriteString(msg.Name) + buff.WriteString("\nRepo: ") + buff.WriteString(msg.Repo) + buff.WriteString("\nBranch: ") + buff.WriteString(msg.Branch) + buff.WriteString("\nOld_rev: ") + buff.WriteString(msg.Old_rev) + buff.WriteString("\nNew_rev: ") + buff.WriteString(msg.New_rev) + return buff.String() + +} + @@ -19,6 +19,8 @@ func (worker *SCORSHworker) Matches(repo, branch string) bool { branch_pattern := parts[1] repo_match, _ := regexp.MatchString(repo_pattern, repo) branch_match, _ := regexp.MatchString(branch_pattern, branch) + debug.log("[worker.Matches] repo_match: %s\n", repo_match) + debug.log("[worker.Matches] branch_match: %s\n", branch_match) if repo_match && branch_match { return true } @@ -59,34 +61,40 @@ func (w *SCORSHworker) LoadTags() error { w_tags, err := ioutil.ReadFile(w.Tagfile) if err != nil{ - log.Printf("[worker:%s] Cannot read worker config: ", w.Name, err) - return err + return fmt.Errorf("Cannot read worker config: %s", err) } + - err = yaml.Unmarshal(w_tags, w.Tags) + err = yaml.Unmarshal(w_tags, w) + //err = yaml.Unmarshal(w_tags, tags) if err != nil { - log.Printf("[worker:%s] Error while reading tags: ", w.Name, err) - return err + return fmt.Errorf("Error while reading tags: %s", err) } - return nil } -// FIXME--- STILL UNDER HEAVY WORK... -func SCORSHWorker(w *SCORSHworker) { +// FIXME--- still needs some work... +func Worker(w *SCORSHworker) { + var msg SCORSHmsg + + log.Printf("[worker: %s] Started\n", w.Name) + w.StatusChan <- msg + // This is the main worker loop for { select { - case msg := <-w.MsgChan: + case msg = <-w.MsgChan: + debug.log("[worker: %s] received message %s\n", w.Name, msg.Name) // process message - err := walk_commits(msg, w) - if err != nil { - log.Printf("[worker: %s] error in walk_commits: %s", err) - } + // err := walk_commits(msg, w) + // if err != nil { + // log.Printf("[worker: %s] error in walk_commits: %s", err) + // } + log.Printf("[worker: %s] Received message: ", w.Name, msg) } } } @@ -99,7 +107,9 @@ func StartWorkers(master *SCORSHmaster) error { // We should now start each worker - for w:=1; w<num_workers; w++ { + log.Printf("num_workers: %d\n", num_workers) + + for w:=0; w<num_workers; w++ { worker := & (master.Workers[w]) // Set the Status and Msg channels @@ -108,21 +118,21 @@ func StartWorkers(master *SCORSHmaster) error { // Load worker keyrings err := worker.LoadKeyrings() if err != nil { - log.Printf("[worker: %s] Unable to load keyrings (Exiting): %s\n", worker.Name, err) close(worker.MsgChan) - return err + return fmt.Errorf("[Starting worker: %s] Unable to load keyrings: %s\n", worker.Name, err) } // Load worker tags from worker.Tagfile err = worker.LoadTags() if err != nil { - log.Printf("[worker: %s] Unable to load tags (Exiting): %s\n", worker.Name, err) close(worker.MsgChan) - return err + return fmt.Errorf("[Starting worker: %s] Unable to load tags: %s\n", worker.Name, err) } // Add the repos definitions to the map master.Repos for _, repo_name := range worker.Repos { master.Repos[repo_name] = append(master.Repos[repo_name], worker) } + go Worker(worker) + <- master.StatusChan } return nil } |